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

Method Load

pkg/devspace/config/localcache/config.go:46–104  ·  view source on GitHub ↗

Load loads the config from the filesystem

(devSpaceFilePath string)

Source from the content-addressed store, hash-verified

44
45// Load loads the config from the filesystem
46func (l *cacheLoader) Load(devSpaceFilePath string) (Cache, error) {
47 var loadedConfig *LocalCache
48
49 absPath, err := filepath.Abs(devSpaceFilePath)
50 if err != nil {
51 return nil, err
52 }
53
54 cachePath := cachePath(absPath)
55 data, readErr := os.ReadFile(cachePath)
56 if readErr != nil {
57 loadedConfig = New(cachePath).(*LocalCache)
58 } else {
59 loadedConfig = &LocalCache{}
60 err := yamlutil.Unmarshal(data, loadedConfig)
61 if err != nil {
62 return nil, err
63 }
64
65 if loadedConfig.Images == nil {
66 loadedConfig.Images = make(map[string]ImageCache)
67 }
68 if loadedConfig.Data == nil {
69 loadedConfig.Data = make(map[string]string)
70 }
71 if loadedConfig.Vars == nil {
72 loadedConfig.Vars = make(map[string]string)
73 }
74 }
75
76 // Decrypt vars if necessary
77 if loadedConfig.VarsEncrypted {
78 for k, v := range loadedConfig.Vars {
79 if len(v) == 0 {
80 continue
81 }
82
83 decoded, err := base64.StdEncoding.DecodeString(v)
84 if err != nil {
85 // seems like not encrypted
86 continue
87 }
88
89 decrypted, err := encryption.DecryptAES([]byte(EncryptionKey), decoded)
90 if err != nil {
91 // we cannot decrypt the variable, so we will ask the user again
92 delete(loadedConfig.Vars, k)
93 continue
94 }
95
96 loadedConfig.Vars[k] = string(decrypted)
97 }
98
99 loadedConfig.VarsEncrypted = false
100 }
101
102 loadedConfig.cachePath = cachePath
103 return loadedConfig, nil

Callers

nothing calls this directly

Calls 4

UnmarshalFunction · 0.92
DecryptAESFunction · 0.92
cachePathFunction · 0.85
NewFunction · 0.70

Tested by

no test coverage detected