-
Notifications
You must be signed in to change notification settings - Fork 2
/
compliance.go
39 lines (31 loc) · 1.03 KB
/
compliance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package actions
import (
"encoding/json"
"io"
"net/http"
"github.com/ottogroup/penelope/pkg/builder"
"github.com/ottogroup/penelope/pkg/requestobjects"
"go.opencensus.io/trace"
)
type ComplianceBackupHandler struct {
processorBuilder *builder.ProcessorBuilder
}
func NewComplianceBackupHandler(processorBuilder *builder.ProcessorBuilder) *ComplianceBackupHandler {
return &ComplianceBackupHandler{processorBuilder: processorBuilder}
}
// ServeHTTP will handle Calculating operation
func (dl *ComplianceBackupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx, span := trace.StartSpan(r.Context(), "ComplianceBackupHandler.ServeHTTP")
defer span.End()
bodyBytes, err := io.ReadAll(r.Body)
if !checkRequestBodyIsValid(w, err) {
return
}
var request requestobjects.ComplianceRequest
err = json.Unmarshal(bodyBytes, &request)
body := string(bodyBytes)
if !checkParsingBodyIsValid(w, err, body) {
return
}
handleRequestByProcessor(ctx, w, r, request, http.StatusOK, dl.processorBuilder.ProcessorForCompliance)
}