Load loads the config from the filesystem
(devSpaceFilePath string)
| 44 | |
| 45 | // Load loads the config from the filesystem |
| 46 | func (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 |
nothing calls this directly
no test coverage detected