예제 #1
0
func postAuditLog(request *restful.Request, response *restful.Response) {
	auditLog := &utilityaudit.AuditLog{}
	err := request.ReadEntity(&auditLog)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Read body failure"
		jsonMap["ErrorMessage"] = err.Error()
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(400, string(errorMessageByteSlice))
		return
	}

	err = audit.SaveAudit(auditLog, false)
	if err != nil {
		jsonMap := make(map[string]interface{})
		jsonMap["Error"] = "Create service failure"
		jsonMap["ErrorMessage"] = err.Error()
		jsonMap["auditLog"] = auditLog
		errorMessageByteSlice, _ := json.Marshal(jsonMap)
		log.Error(jsonMap)
		response.WriteErrorString(422, string(errorMessageByteSlice))
		return
	}
}
예제 #2
0
func sendAuditLog(token string, requestURI string, method string, path string, requestBody string, queryParameterMap map[string][]string, pathParameterMap map[string]string, remoteAddress string) {
	// Get cache. If not exsiting, retrieving from authorization server.
	user, err := getCache(token)
	userName := ""
	if err != nil {
		log.Error(err)
		userName = "******"
	}
	if user != nil {
		userName = user.Name
	}

	// Header is not used since the header has no useful information for now
	auditLog := utilityaudit.CreateAuditLog(componentName, path, userName, remoteAddress, queryParameterMap, pathParameterMap, method, requestURI, requestBody, nil)

	err = audit.SaveAudit(auditLog, false)
	if err != nil {
		log.Error("Fail to send audit log with error %s", err)
	}
}