github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/avs/model.go (about) 1 package avs 2 3 import ( 4 "fmt" 5 6 "github.com/kyma-project/kyma-environment-broker/internal" 7 "github.com/kyma-project/kyma-environment-broker/internal/broker" 8 ) 9 10 const ( 11 DefinitionType = "BASIC" 12 interval = 60 13 timeout = 30000 14 contentCheck = "error" 15 contentCheckType = "NOT_CONTAINS" 16 threshold = "30000" 17 visibility = "PUBLIC" 18 ) 19 20 const ( 21 StatusActive = "ACTIVE" 22 StatusMaintenance = "MAINTENANCE" 23 StatusInactive = "INACTIVE" 24 StatusRetired = "RETIRED" 25 StatusDeleted = "DELETED" 26 ) 27 28 func ValidStatus(status string) bool { 29 switch status { 30 case StatusActive, StatusMaintenance, StatusInactive, StatusRetired, StatusDeleted: 31 return true 32 } 33 34 return false 35 } 36 37 type Tag struct { 38 Content string `json:"content"` 39 TagClassId int `json:"tag_class_id"` 40 TagClassName string `json:"tag_class_name"` 41 } 42 43 type BasicEvaluationCreateRequest struct { 44 DefinitionType string `json:"definition_type"` 45 Name string `json:"name"` 46 Description string `json:"description"` 47 Service string `json:"service"` 48 URL string `json:"url"` 49 CheckType string `json:"check_type"` 50 Interval int32 `json:"interval"` 51 TesterAccessId int64 `json:"tester_access_id"` 52 Timeout int `json:"timeout"` 53 ReadOnly bool `json:"read_only"` 54 ContentCheck string `json:"content_check"` 55 ContentCheckType string `json:"content_check_type"` 56 Threshold string `json:"threshold"` 57 GroupId int64 `json:"group_id"` 58 Visibility string `json:"visibility"` 59 ParentId int64 `json:"parent_id"` 60 Tags []*Tag `json:"tags"` 61 } 62 63 type BasicEvaluationCreateResponse struct { 64 DefinitionType string `json:"definition_type"` 65 Name string `json:"name"` 66 Description string `json:"description"` 67 Service string `json:"service"` 68 URL string `json:"url"` 69 CheckType string `json:"check_type"` 70 Interval int32 `json:"interval"` 71 TesterAccessId int64 `json:"tester_access_id"` 72 Timeout int `json:"timeout"` 73 ReadOnly bool `json:"read_only"` 74 ContentCheck string `json:"content_check"` 75 ContentCheckType string `json:"content_check_type"` 76 Threshold int64 `json:"threshold"` 77 GroupId int64 `json:"group_id"` 78 Visibility string `json:"visibility"` 79 80 DateCreated int64 `json:"dateCreated"` 81 DateChanged int64 `json:"dateChanged"` 82 Owner string `json:"owner"` 83 Status string `json:"status"` 84 Alerts []int `json:"alerts"` 85 Tags []*Tag `json:"tags"` 86 Id int64 `json:"id"` 87 LegacyCheckId int64 `json:"legacy_check_id"` 88 InternalInterval int64 `json:"internal_interval"` 89 AuthType string `json:"auth_type"` 90 IndividualOutageEventsOnly bool `json:"individual_outage_events_only"` 91 IdOnTester string `json:"id_on_tester"` 92 } 93 94 func newBasicEvaluationCreateRequest(operation internal.Operation, evalTypeSpecificConfig ModelConfigurator, url string) (*BasicEvaluationCreateRequest, error) { 95 96 beName, beDescription := generateNameAndDescription(operation, evalTypeSpecificConfig.ProvideSuffix()) 97 98 return &BasicEvaluationCreateRequest{ 99 DefinitionType: DefinitionType, 100 Name: beName, 101 Description: beDescription, 102 Service: evalTypeSpecificConfig.ProvideNewOrDefaultServiceName(beName), 103 URL: url, 104 CheckType: evalTypeSpecificConfig.ProvideCheckType(), 105 Interval: interval, 106 TesterAccessId: evalTypeSpecificConfig.ProvideTesterAccessId(operation.ProvisioningParameters), 107 Tags: evalTypeSpecificConfig.ProvideTags(operation), 108 Timeout: timeout, 109 ReadOnly: false, 110 ContentCheck: contentCheck, 111 ContentCheckType: contentCheckType, 112 Threshold: threshold, 113 GroupId: evalTypeSpecificConfig.ProvideGroupId(operation.ProvisioningParameters), 114 Visibility: visibility, 115 ParentId: evalTypeSpecificConfig.ProvideParentId(operation.ProvisioningParameters), 116 }, nil 117 } 118 119 func generateNameAndDescription(operation internal.Operation, beType string) (string, string) { 120 globalAccountID := operation.ProvisioningParameters.ErsContext.GlobalAccountID 121 subAccountID := operation.ProvisioningParameters.ErsContext.SubAccountID 122 instanceID := operation.InstanceID 123 name := operation.ProvisioningParameters.Parameters.Name 124 shootName := operation.InstanceDetails.ShootName 125 beName := fmt.Sprintf("K8S-%s-Kyma-%s-%s-%s", providerCodeByPlan(operation.ProvisioningParameters.PlanID), beType, instanceID, name) 126 beDescription := fmt.Sprintf("{\"instanceName\": \"%s\", \"globalAccountID\": \"%s\", \"subAccountID\": \"%s\", \"instanceID\": \"%s\", \"shootName\": \"%s\"}", 127 name, globalAccountID, subAccountID, instanceID, shootName) 128 129 return truncateString(beName, 80), truncateString(beDescription, 255) 130 } 131 132 func providerCodeByPlan(planID string) string { 133 switch planID { 134 case broker.AWSPlanID: 135 return "AWS" 136 case broker.GCPPlanID: 137 return "GCP" 138 case broker.AzurePlanID, broker.AzureLitePlanID: 139 return "AZR" 140 case broker.TrialPlanID, broker.FreemiumPlanID: 141 return "AZR" 142 case broker.OpenStackPlanID: 143 return "CC" 144 default: 145 return "AZR" 146 } 147 } 148 149 func convertAZR(code string) string { 150 if code == "AZR" { 151 return "Azure" 152 } 153 return code 154 } 155 156 func truncateString(input string, num int) string { 157 output := input 158 if len(input) > num { 159 output = input[0:num] 160 } 161 return output 162 }