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, )
| 132 | // EnsureAPIKey generates a write API key for the application. |
| 133 | // Callers should skip this if the local profile already has a key. |
| 134 | func 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. |
no test coverage detected