MCPcopy Create free account
hub / github.com/clouditor/clouditor / LogRequest

Function LogRequest

internal/logging/logging.go:93–139  ·  view source on GitHub ↗

LogRequest creates a logging message with the given parameters - log *logrus.Entry - level the message must have - reqType is the request type - Optional. params for self-created string messages to be appended to the created log message. The elements do not need a space at the beginning of the messa

(log *logrus.Entry, level logrus.Level, reqType RequestType, req api.PayloadRequest, params ...string)

Source from the content-addressed store, hash-verified

91//
92// "*orchestrator.AuditScope created with ID 'AuditScope1234' for Certification Target '00000000-0000-0000-0000-000000000000' and Catalog 'EUCS'."
93func LogRequest(log *logrus.Entry, level logrus.Level, reqType RequestType, req api.PayloadRequest, params ...string) {
94 var (
95 buffer bytes.Buffer
96 )
97
98 // Check if inputs are available
99 if log == nil || util.IsNil(req) {
100 return
101 }
102
103 // Retrieve the payload from the request. The request itself is usually
104 // a wrapper around the sent object.
105 payload := req.GetPayload()
106 if util.IsNil(payload) {
107 return
108 }
109
110 // We can retrieve the name via the proto descriptor. This should be
111 // sufficiently fast and also gives us the non-pointer type in comparison to
112 // the %T printf directive.
113 name := req.GetPayload().ProtoReflect().Descriptor().Name()
114
115 // Check, if our payload has an ID field
116 idreq, ok := payload.(interface{ GetId() string })
117 if ok && idreq.GetId() != "" {
118 buffer.WriteString(fmt.Sprintf("%s with ID '%s' %s", name, idreq.GetId(), reqType.String()))
119 } else {
120 buffer.WriteString(fmt.Sprintf("%s %s", name, reqType.String()))
121 }
122
123 // Check, if it is a certification target request. In this case we can append the
124 // information about the target certification target. However, we only want to do
125 // that, if the payload type is not a certification target itself.
126 ctreq, ok := req.(api.CertificationTargetRequest)
127 if name != "CertificationTarget" && ok {
128 buffer.WriteString(fmt.Sprintf(" for Certification Target '%s'", ctreq.GetCertificationTargetId()))
129 }
130
131 // If params is not empty, the elements are joined and added to the message
132 if len(params) > 0 {
133 buffer.WriteString(" " + strings.Join(params, " "))
134 }
135
136 buffer.WriteString(".")
137
138 log.Log(level, buffer.String())
139}

Callers 15

AssessEvidenceMethod · 0.92
StoreEvidenceMethod · 0.92
CreateCatalogMethod · 0.92
UpdateCatalogMethod · 0.92
RemoveCatalogMethod · 0.92
CreateAuditScopeMethod · 0.92
UpdateAuditScopeMethod · 0.92
RemoveAuditScopeMethod · 0.92
StoreAssessmentResultMethod · 0.92

Calls 8

IsNilFunction · 0.92
GetPayloadMethod · 0.65
NameMethod · 0.65
GetIdMethod · 0.65
DescriptorMethod · 0.45
ProtoReflectMethod · 0.45
StringMethod · 0.45

Tested by 1

TestLogRequestFunction · 0.68