MCPcopy Create free account
hub / github.com/devspace-sh/devspace / getActivatedProfiles

Function getActivatedProfiles

pkg/devspace/config/versions/versions.go:262–301  ·  view source on GitHub ↗
(ctx context.Context, data map[string]interface{}, resolver variable.Resolver, log log.Logger)

Source from the content-addressed store, hash-verified

260}
261
262func 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
303func matchEnvironment(env map[string]string) (bool, error) {
304 for k, v := range env {

Callers 1

ParseProfileFunction · 0.85

Calls 5

GetFunction · 0.85
matchEnvironmentFunction · 0.85
matchVarsFunction · 0.85
ParseFunction · 0.70
DebugfMethod · 0.45

Tested by

no test coverage detected