ValidateDependencies validates the dependencies of the addon and returns a list of errors for the missing dependencies.
(features map[FeatureName]Feature)
| 105 | // ValidateDependencies validates the dependencies of the addon |
| 106 | // and returns a list of errors for the missing dependencies. |
| 107 | func (a Addon) ValidateDependencies(features map[FeatureName]Feature) []string { |
| 108 | errors := []string{} |
| 109 | |
| 110 | // Candidate for a switch statement once we have more addons. |
| 111 | if a == AddonAIGovernance { |
| 112 | requiredFeatures := []FeatureName{ |
| 113 | FeatureAIGovernanceUserLimit, |
| 114 | } |
| 115 | |
| 116 | for _, featureName := range requiredFeatures { |
| 117 | feature, ok := features[featureName] |
| 118 | if !ok { |
| 119 | errors = append(errors, |
| 120 | fmt.Sprintf( |
| 121 | "Feature %s must be set when using the %s addon.", |
| 122 | featureName.Humanize(), |
| 123 | a.Humanize(), |
| 124 | ), |
| 125 | ) |
| 126 | continue |
| 127 | } |
| 128 | // For limit features, check if the Limit is set (not nil). |
| 129 | // For usage period features, check if the Limit is set. |
| 130 | if featureName.UsesLimit() || featureName.UsesUsagePeriod() { |
| 131 | if feature.Limit == nil { |
| 132 | errors = append(errors, |
| 133 | fmt.Sprintf( |
| 134 | "Feature %s must be set when using the %s addon.", |
| 135 | featureName.Humanize(), |
| 136 | a.Humanize(), |
| 137 | ), |
| 138 | ) |
| 139 | } |
| 140 | } else if feature.Entitlement == EntitlementNotEntitled { |
| 141 | // For non-limit features, check if the feature is entitled. |
| 142 | errors = append(errors, |
| 143 | fmt.Sprintf( |
| 144 | "Feature %s must be set when using the %s addon.", |
| 145 | featureName.Humanize(), |
| 146 | a.Humanize(), |
| 147 | ), |
| 148 | ) |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | return errors |
| 154 | } |
| 155 | |
| 156 | // Humanize returns the addon name in a human-readable format. |
| 157 | func (a Addon) Humanize() string { |
no test coverage detected