MCPcopy Create free account
hub / github.com/nhost/nhost / ValidateRemote

Function ValidateRemote

cli/cmd/config/validate.go:150–200  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
150func 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}

Callers 3

cloudFunction · 0.92
commandApplyFunction · 0.85
commandValidateFunction · 0.85

Calls 11

UnmarshalFileFunction · 0.92
PathExistsFunction · 0.92
ApplyJSONPatchesFunction · 0.85
NhostTomlMethod · 0.80
ErrorfMethod · 0.80
OverlayMethod · 0.80
InfolnMethod · 0.80
GetNhostClientMethod · 0.80
GetSecretsMethod · 0.80
GetAppSecretsMethod · 0.80
respToSecretsFunction · 0.70

Tested by

no test coverage detected