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

Function getProfiles

pkg/devspace/config/versions/versions.go:181–260  ·  view source on GitHub ↗

getProfiles loads a certain profile

(ctx context.Context, basePath string, data map[string]interface{}, profile string, profileChain *[]*latest.ProfileConfig, depth int, update bool, log log.Logger)

Source from the content-addressed store, hash-verified

179
180// getProfiles loads a certain profile
181func getProfiles(ctx context.Context, basePath string, data map[string]interface{}, profile string, profileChain *[]*latest.ProfileConfig, depth int, update bool, log log.Logger) error {
182 if depth > 50 {
183 return fmt.Errorf("cannot load config with profile %s: max config loading depth reached. Seems like you have a profile cycle somewhere", profile)
184 }
185
186 // Check if a profile is defined
187 if profile == "" {
188 return nil
189 }
190
191 // get the profiles and parse them
192 profilesData, err := Get(data, "profiles")
193 if err != nil {
194 return err
195 }
196 profiles, err := Parse(profilesData, log)
197 if err != nil {
198 return err
199 }
200
201 // Search for config
202 for _, profileConfig := range profiles.Profiles {
203 if profileConfig.Name == profile {
204 // Add to profile chain
205 *profileChain = append(*profileChain, profileConfig)
206
207 // Get parents profiles
208 if profileConfig.Parent != "" && len(profileConfig.Parents) > 0 {
209 return errors.Errorf("parents and parent cannot be defined at the same time in profile %s. Please choose either one", profile)
210 }
211
212 // single parent
213 if profileConfig.Parent != "" {
214 return getProfiles(ctx, basePath, data, profileConfig.Parent, profileChain, depth+1, update, log)
215 }
216
217 // multiple parents
218 if len(profileConfig.Parents) > 0 {
219 for i := len(profileConfig.Parents) - 1; i >= 0; i-- {
220 if profileConfig.Parents[i].Profile == "" {
221 continue
222 }
223
224 if profileConfig.Parents[i].Source != nil {
225 configPath, err := dependencyutil.DownloadDependency(ctx, basePath, profileConfig.Parents[i].Source, log)
226 if err != nil {
227 return err
228 }
229
230 fileContent, err := os.ReadFile(configPath)
231 if err != nil {
232 return errors.Wrap(err, "read parent config")
233 }
234
235 rawMap := map[string]interface{}{}
236 err = yamlutil.Unmarshal(fileContent, &rawMap)
237 if err != nil {
238 return err

Callers 1

ParseProfileFunction · 0.85

Calls 4

UnmarshalFunction · 0.92
GetFunction · 0.85
ParseFunction · 0.70
ErrorfMethod · 0.45

Tested by

no test coverage detected