MCPcopy Create free account
hub / github.com/algolia/cli / EnsureAPIKey

Function EnsureAPIKey

pkg/cmd/shared/apputil/create.go:134–152  ·  view source on GitHub ↗

EnsureAPIKey generates a write API key for the application. Callers should skip this if the local profile already has a key.

(
	io *iostreams.IOStreams,
	client *dashboard.Client,
	accessToken string,
	app *dashboard.Application,
)

Source from the content-addressed store, hash-verified

132// EnsureAPIKey generates a write API key for the application.
133// Callers should skip this if the local profile already has a key.
134func EnsureAPIKey(
135 io *iostreams.IOStreams,
136 client *dashboard.Client,
137 accessToken string,
138 app *dashboard.Application,
139) error {
140 cs := io.ColorScheme()
141 io.StartProgressIndicatorWithLabel("Generating API key")
142 apiKey, err := client.CreateAPIKey(accessToken, app.ID, dashboard.WriteACL, "Algolia CLI")
143 io.StopProgressIndicator()
144 if err != nil {
145 return fmt.Errorf("failed to generate API key: %w", err)
146 }
147
148 app.APIKey = apiKey
149 fmt.Fprintf(io.Out, "%s API key generated for application %s\n",
150 cs.SuccessIcon(), cs.Bold(app.ID))
151 return nil
152}
153
154// ConfigureProfile creates a CLI profile from application details and
155// optionally sets it as the default.

Callers 4

runOAuthFlowStepsFunction · 0.92
runListCmdFunction · 0.92
runSelectCmdFunction · 0.92

Calls 7

ColorSchemeMethod · 0.80
CreateAPIKeyMethod · 0.80
StopProgressIndicatorMethod · 0.80
SuccessIconMethod · 0.80
BoldMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected