(ctx context.Context, data map[string]interface{}, resolver variable.Resolver, log log.Logger)
| 260 | } |
| 261 | |
| 262 | func getActivatedProfiles(ctx context.Context, data map[string]interface{}, resolver variable.Resolver, log log.Logger) ([]string, error) { |
| 263 | activatedProfiles := []string{} |
| 264 | |
| 265 | // Check if there are profiles |
| 266 | if data["profiles"] == nil { |
| 267 | return activatedProfiles, nil |
| 268 | } |
| 269 | |
| 270 | // get the profiles and parse them |
| 271 | profilesData, err := Get(data, "profiles") |
| 272 | if err != nil { |
| 273 | return nil, err |
| 274 | } |
| 275 | profiles, err := Parse(profilesData, log) |
| 276 | if err != nil { |
| 277 | return nil, err |
| 278 | } |
| 279 | |
| 280 | // Select which profiles are activated |
| 281 | for _, profileConfig := range profiles.Profiles { |
| 282 | for _, activation := range profileConfig.Activation { |
| 283 | activatedByEnv, err := matchEnvironment(activation.Environment) |
| 284 | if err != nil { |
| 285 | return activatedProfiles, errors.Wrap(err, "error activating profile with env") |
| 286 | } |
| 287 | |
| 288 | activatedByVars, err := matchVars(ctx, activation.Vars, resolver) |
| 289 | if err != nil { |
| 290 | return activatedProfiles, errors.Wrap(err, "error activating profile with vars") |
| 291 | } |
| 292 | |
| 293 | if activatedByEnv && activatedByVars { |
| 294 | log.Debugf("profile %s was automatically activated", profileConfig.Name) |
| 295 | activatedProfiles = append(activatedProfiles, profileConfig.Name) |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | return activatedProfiles, nil |
| 301 | } |
| 302 | |
| 303 | func matchEnvironment(env map[string]string) (bool, error) { |
| 304 | for k, v := range env { |
no test coverage detected