ValidateRemote validates the configuration of a remote project by fetching the secrets and applying them to the configuration. It also applies any JSON patches from the overlay directory if it exists. It returns the original configuration with the applied patches (without being filled and without se
( ctx context.Context, ce *clienv.CliEnv, subdomain string, appID string, )
| 148 | // It returns the original configuration with the applied patches (without being filled |
| 149 | // and without secrets resolved) and another configuration filled and with secrets resolved. |
| 150 | func ValidateRemote( |
| 151 | ctx context.Context, |
| 152 | ce *clienv.CliEnv, |
| 153 | subdomain string, |
| 154 | appID string, |
| 155 | ) (*model.ConfigConfig, *model.ConfigConfig, error) { |
| 156 | cfg := &model.ConfigConfig{} //nolint:exhaustruct |
| 157 | if err := clienv.UnmarshalFile(ce.Path.NhostToml(), cfg, toml.Unmarshal); err != nil { |
| 158 | return nil, nil, fmt.Errorf("failed to parse config: %w", err) |
| 159 | } |
| 160 | |
| 161 | if clienv.PathExists(ce.Path.Overlay(subdomain)) { |
| 162 | var err error |
| 163 | |
| 164 | cfg, err = ApplyJSONPatches(*cfg, ce.Path.Overlay(subdomain)) |
| 165 | if err != nil { |
| 166 | return nil, nil, fmt.Errorf("failed to apply json patches: %w", err) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | schema, err := schema.New() |
| 171 | if err != nil { |
| 172 | return nil, nil, fmt.Errorf("failed to create schema: %w", err) |
| 173 | } |
| 174 | |
| 175 | ce.Infoln("Getting secrets...") |
| 176 | |
| 177 | cl, err := ce.GetNhostClient(ctx) |
| 178 | if err != nil { |
| 179 | return nil, nil, fmt.Errorf("failed to get nhost client: %w", err) |
| 180 | } |
| 181 | |
| 182 | secretsResp, err := cl.GetSecrets( |
| 183 | ctx, |
| 184 | appID, |
| 185 | ) |
| 186 | if err != nil { |
| 187 | return nil, nil, fmt.Errorf("failed to get secrets: %w", err) |
| 188 | } |
| 189 | |
| 190 | secrets := respToSecrets(secretsResp.GetAppSecrets(), false) |
| 191 | |
| 192 | cfgSecrets, err := appconfig.SecretsResolver(cfg, secrets, schema.Fill) |
| 193 | if err != nil { |
| 194 | return nil, nil, fmt.Errorf("failed to validate config: %w", err) |
| 195 | } |
| 196 | |
| 197 | ce.Infoln("Config is valid!") |
| 198 | |
| 199 | return cfg, cfgSecrets, nil |
| 200 | } |
no test coverage detected