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

Function Pull

cli/cmd/config/pull.go:170–218  ·  view source on GitHub ↗
(
	ctx context.Context,
	ce *clienv.CliEnv,
	proj *graphql.AppSummaryFragment,
	writeSecrts bool,
)

Source from the content-addressed store, hash-verified

168}
169
170func Pull(
171 ctx context.Context,
172 ce *clienv.CliEnv,
173 proj *graphql.AppSummaryFragment,
174 writeSecrts bool,
175) (*model.ConfigConfig, error) {
176 ce.Infoln("Pulling config from Nhost...")
177
178 cl, err := ce.GetNhostClient(ctx)
179 if err != nil {
180 return nil, fmt.Errorf("failed to get nhost client: %w", err)
181 }
182
183 cfg, err := cl.GetConfigRawJSON(
184 ctx,
185 proj.ID,
186 )
187 if err != nil {
188 return nil, fmt.Errorf("failed to get config: %w", err)
189 }
190
191 var v model.ConfigConfig
192 if err := json.Unmarshal([]byte(cfg.ConfigRawJSON), &v); err != nil {
193 return nil, fmt.Errorf("failed to unmarshal config: %w", err)
194 }
195
196 if err := os.MkdirAll(ce.Path.NhostFolder(), 0o755); err != nil { //nolint:mnd
197 return nil, fmt.Errorf("failed to create nhost directory: %w", err)
198 }
199
200 if err := clienv.MarshalFile(v, ce.Path.NhostToml(), toml.Marshal); err != nil {
201 return nil, fmt.Errorf("failed to save nhost.toml: %w", err)
202 }
203
204 if writeSecrts {
205 if err := pullSecrets(ctx, ce, proj); err != nil {
206 return nil, err
207 }
208 }
209
210 ce.Infoln("Success!")
211 ce.Warnln(
212 "- Review `nhost/nhost.toml` and make sure there are no secrets before you commit it to git.",
213 )
214 ce.Warnln("- Review `.secrets` file and set your development secrets")
215 ce.Warnln("- Review `.secrets` was added to .gitignore")
216
217 return &v, nil
218}

Callers 2

InitRemoteFunction · 0.92
commandPullFunction · 0.85

Calls 9

MarshalFileFunction · 0.92
pullSecretsFunction · 0.85
InfolnMethod · 0.80
GetNhostClientMethod · 0.80
ErrorfMethod · 0.80
NhostFolderMethod · 0.80
NhostTomlMethod · 0.80
WarnlnMethod · 0.80
GetConfigRawJSONMethod · 0.45

Tested by

no test coverage detected