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

Method Save

pkg/devspace/config/localcache/schema.go:188–247  ·  view source on GitHub ↗

Save saves the config to the filesystem

()

Source from the content-addressed store, hash-verified

186
187// Save saves the config to the filesystem
188func (l *LocalCache) Save() error {
189 if l.cachePath == "" {
190 return fmt.Errorf("no path specified where to save the local cache")
191 }
192
193 l.accessMutex.Lock()
194 defer l.accessMutex.Unlock()
195
196 data, err := yaml.Marshal(l)
197 if err != nil {
198 return err
199 }
200
201 copiedConfig := &LocalCache{}
202 err = yaml.Unmarshal(data, copiedConfig)
203 if err != nil {
204 return err
205 }
206
207 // encrypt variables
208 if env.GlobalGetEnv(DevSpaceDisableVarsEncryptionEnv) != "true" && EncryptionKey != "" {
209 for k, v := range copiedConfig.Vars {
210 if len(v) == 0 {
211 continue
212 }
213
214 encrypted, err := encryption.EncryptAES([]byte(EncryptionKey), []byte(v))
215 if err != nil {
216 return err
217 }
218
219 copiedConfig.Vars[k] = base64.StdEncoding.EncodeToString(encrypted)
220 }
221
222 copiedConfig.VarsEncrypted = true
223 }
224
225 // marshal again with the encrypted vars
226 data, err = yaml.Marshal(copiedConfig)
227 if err != nil {
228 return err
229 }
230
231 _, err = os.Stat(l.cachePath)
232 if err != nil {
233 if os.IsNotExist(err) {
234 // check if a save is really necessary
235 if len(l.Data) == 0 && len(l.Vars) == 0 && len(l.Images) == 0 && l.LastContext == nil {
236 return nil
237 }
238 }
239 }
240
241 err = os.MkdirAll(filepath.Dir(l.cachePath), 0755)
242 if err != nil {
243 return err
244 }
245

Callers

nothing calls this directly

Calls 4

EncryptAESFunction · 0.92
LockMethod · 0.80
UnlockMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected