github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/avs/external_eval_assistant.go (about) 1 package avs 2 3 import ( 4 "time" 5 6 "github.com/kyma-project/kyma-environment-broker/internal" 7 ) 8 9 const externalEvalCheckType = "HTTPSGET" 10 11 type ExternalEvalAssistant struct { 12 avsConfig Config 13 retryConfig *RetryConfig 14 } 15 16 func NewExternalEvalAssistant(avsConfig Config) *ExternalEvalAssistant { 17 return &ExternalEvalAssistant{ 18 avsConfig: avsConfig, 19 retryConfig: &RetryConfig{maxTime: 20 * time.Minute, retryInterval: 30 * time.Second}, 20 } 21 } 22 23 func (eea *ExternalEvalAssistant) CreateBasicEvaluationRequest(operations internal.Operation, url string) (*BasicEvaluationCreateRequest, error) { 24 return newBasicEvaluationCreateRequest(operations, eea, url) 25 } 26 27 func (eea *ExternalEvalAssistant) IsAlreadyCreated(lifecycleData internal.AvsLifecycleData) bool { 28 return lifecycleData.AVSEvaluationExternalId != 0 29 } 30 31 func (eea *ExternalEvalAssistant) IsValid(lifecycleData internal.AvsLifecycleData) bool { 32 return eea.IsAlreadyCreated(lifecycleData) && !eea.IsAlreadyDeletedOrEmpty(lifecycleData) 33 } 34 35 func (eea *ExternalEvalAssistant) ProvideSuffix() string { 36 return "ext" 37 } 38 39 func (eea *ExternalEvalAssistant) ProvideTesterAccessId(_ internal.ProvisioningParameters) int64 { 40 return eea.avsConfig.ExternalTesterAccessId 41 } 42 43 func (eea *ExternalEvalAssistant) ProvideGroupId(_ internal.ProvisioningParameters) int64 { 44 return eea.avsConfig.GroupId 45 } 46 47 func (eea *ExternalEvalAssistant) ProvideParentId(_ internal.ProvisioningParameters) int64 { 48 return eea.avsConfig.ParentId 49 } 50 51 func (eea *ExternalEvalAssistant) ProvideTags(operation internal.Operation) []*Tag { 52 53 tags := []*Tag{ 54 { 55 Content: operation.InstanceID, 56 TagClassId: eea.avsConfig.InstanceIdTagClassId, 57 }, 58 { 59 Content: operation.ProvisioningParameters.ErsContext.GlobalAccountID, 60 TagClassId: eea.avsConfig.GlobalAccountIdTagClassId, 61 }, 62 { 63 Content: operation.ProvisioningParameters.ErsContext.SubAccountID, 64 TagClassId: eea.avsConfig.SubAccountIdTagClassId, 65 }, 66 { 67 Content: operation.ProvisioningParameters.PlatformRegion, 68 TagClassId: eea.avsConfig.LandscapeTagClassId, 69 }, 70 { 71 Content: convertAZR(providerCodeByPlan(operation.ProvisioningParameters.PlanID)), 72 TagClassId: eea.avsConfig.ProviderTagClassId, 73 }, 74 { 75 Content: operation.ShootName, 76 TagClassId: eea.avsConfig.ShootNameTagClassId, 77 }, 78 } 79 80 region := "" 81 if operation.ProvisioningParameters.Parameters.Region != nil { 82 region = *operation.ProvisioningParameters.Parameters.Region 83 } else if operation.LastRuntimeState.ClusterSetup != nil { 84 region = operation.LastRuntimeState.ClusterSetup.Metadata.Region 85 } else if operation.LastRuntimeState.ClusterConfig.Region != "" { 86 region = operation.LastRuntimeState.ClusterConfig.Region 87 } else if operation.Region != "" { 88 region = operation.Region 89 } 90 91 tags = append(tags, &Tag{ 92 Content: region, 93 TagClassId: eea.avsConfig.RegionTagClassId, 94 }) 95 96 return tags 97 } 98 99 func (eea *ExternalEvalAssistant) ProvideNewOrDefaultServiceName(defaultServiceName string) string { 100 if eea.avsConfig.ExternalTesterService == "" { 101 return defaultServiceName 102 } 103 return eea.avsConfig.ExternalTesterService 104 } 105 106 func (eea *ExternalEvalAssistant) SetEvalId(lifecycleData *internal.AvsLifecycleData, evalId int64) { 107 lifecycleData.AVSEvaluationExternalId = evalId 108 } 109 110 func (eea *ExternalEvalAssistant) SetEvalStatus(lifecycleData *internal.AvsLifecycleData, status string) { 111 current := lifecycleData.AvsExternalEvaluationStatus.Current 112 if ValidStatus(current) { 113 lifecycleData.AvsExternalEvaluationStatus.Original = current 114 } 115 lifecycleData.AvsExternalEvaluationStatus.Current = status 116 } 117 118 func (eea *ExternalEvalAssistant) GetEvalStatus(lifecycleData internal.AvsLifecycleData) string { 119 return lifecycleData.AvsExternalEvaluationStatus.Current 120 } 121 122 func (eea *ExternalEvalAssistant) GetOriginalEvalStatus(lifecycleData internal.AvsLifecycleData) string { 123 return lifecycleData.AvsExternalEvaluationStatus.Original 124 } 125 126 func (eea *ExternalEvalAssistant) IsInMaintenance(lifecycleData internal.AvsLifecycleData) bool { 127 return lifecycleData.AvsExternalEvaluationStatus.Current == StatusMaintenance 128 } 129 130 func (eea *ExternalEvalAssistant) ProvideCheckType() string { 131 return externalEvalCheckType 132 } 133 134 func (eea *ExternalEvalAssistant) IsAlreadyDeletedOrEmpty(lifecycleData internal.AvsLifecycleData) bool { 135 return lifecycleData.AVSExternalEvaluationDeleted || lifecycleData.AVSEvaluationExternalId == 0 136 } 137 138 func (eea *ExternalEvalAssistant) GetEvaluationId(lifecycleData internal.AvsLifecycleData) int64 { 139 return lifecycleData.AVSEvaluationExternalId 140 } 141 142 func (eea *ExternalEvalAssistant) SetDeleted(lifecycleData *internal.AvsLifecycleData, deleted bool) { 143 lifecycleData.AVSExternalEvaluationDeleted = deleted 144 } 145 146 func (eea *ExternalEvalAssistant) provideRetryConfig() *RetryConfig { 147 return eea.retryConfig 148 }