github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/pkg/webhook/application_tenant_mapping.go (about) 1 package webhook 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "net/http" 7 8 "github.com/kyma-incubator/compass/components/director/internal/model" 9 ) 10 11 // ApplicationTenantMappingInput struct contains the input for an app-to-app formation notification 12 type ApplicationTenantMappingInput struct { 13 Operation model.FormationOperation 14 FormationID string 15 SourceApplicationTemplate *ApplicationTemplateWithLabels 16 // SourceApplication is the application that the notification is about 17 SourceApplication *ApplicationWithLabels 18 TargetApplicationTemplate *ApplicationTemplateWithLabels 19 // TargetApplication is the application that the notification is for (the one with the webhook / the one receiving the notification) 20 TargetApplication *ApplicationWithLabels 21 CustomerTenantContext *CustomerTenantContext 22 Assignment *FormationAssignment 23 ReverseAssignment *FormationAssignment 24 } 25 26 // ParseURLTemplate missing godoc 27 func (rd *ApplicationTenantMappingInput) ParseURLTemplate(tmpl *string) (*URL, error) { 28 var url URL 29 return &url, parseTemplate(tmpl, *rd, &url) 30 } 31 32 // ParseInputTemplate missing godoc 33 func (rd *ApplicationTenantMappingInput) ParseInputTemplate(tmpl *string) ([]byte, error) { 34 res := json.RawMessage{} 35 if err := parseTemplate(tmpl, *rd, &res); err != nil { 36 return nil, err 37 } 38 res = bytes.ReplaceAll(res, []byte("<nil>"), nil) 39 return res, nil 40 } 41 42 // ParseHeadersTemplate missing godoc 43 func (rd *ApplicationTenantMappingInput) ParseHeadersTemplate(tmpl *string) (http.Header, error) { 44 var headers http.Header 45 return headers, parseTemplate(tmpl, *rd, &headers) 46 } 47 48 // GetParticipantsIDs returns the list of IDs part of the FormationConfigurationChangeInput 49 func (rd *ApplicationTenantMappingInput) GetParticipantsIDs() []string { 50 return []string{rd.SourceApplication.ID, rd.TargetApplication.ID} 51 } 52 53 // SetAssignment sets the assignment for the ApplicationTenantMappingInput to the provided one 54 func (rd *ApplicationTenantMappingInput) SetAssignment(assignment *model.FormationAssignment) { 55 config := string(assignment.Value) 56 if config == "" || assignment.State == string(model.CreateErrorAssignmentState) || assignment.State == string(model.DeleteErrorAssignmentState) { 57 config = "\"\"" 58 } 59 rd.Assignment = &FormationAssignment{ 60 ID: assignment.ID, 61 FormationID: assignment.FormationID, 62 TenantID: assignment.TenantID, 63 Source: assignment.Source, 64 SourceType: assignment.SourceType, 65 Target: assignment.Target, 66 TargetType: assignment.TargetType, 67 State: assignment.State, 68 Value: config, 69 } 70 } 71 72 // SetReverseAssignment sets the reverseAssignment for the ApplicationTenantMappingInput to the provided one 73 func (rd *ApplicationTenantMappingInput) SetReverseAssignment(reverseAssignment *model.FormationAssignment) { 74 config := string(reverseAssignment.Value) 75 if config == "" || reverseAssignment.State == string(model.CreateErrorAssignmentState) || reverseAssignment.State == string(model.DeleteErrorAssignmentState) { 76 config = "\"\"" 77 } 78 rd.ReverseAssignment = &FormationAssignment{ 79 ID: reverseAssignment.ID, 80 FormationID: reverseAssignment.FormationID, 81 TenantID: reverseAssignment.TenantID, 82 Source: reverseAssignment.Source, 83 SourceType: reverseAssignment.SourceType, 84 Target: reverseAssignment.Target, 85 TargetType: reverseAssignment.TargetType, 86 State: reverseAssignment.State, 87 Value: config, 88 } 89 } 90 91 // Clone return a copy of the ApplicationTenantMappingInput 92 func (rd *ApplicationTenantMappingInput) Clone() FormationAssignmentTemplateInput { 93 return &ApplicationTenantMappingInput{ 94 Operation: rd.Operation, 95 FormationID: rd.FormationID, 96 SourceApplicationTemplate: rd.SourceApplicationTemplate, 97 SourceApplication: rd.SourceApplication, 98 TargetApplicationTemplate: rd.TargetApplicationTemplate, 99 TargetApplication: rd.TargetApplication, 100 CustomerTenantContext: rd.CustomerTenantContext, 101 Assignment: rd.Assignment, 102 ReverseAssignment: rd.ReverseAssignment, 103 } 104 }