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

Function createApplication

pkg/cmd/application/create/create.go:184–331  ·  view source on GitHub ↗
(
	ctx context.Context,
	opts *CreateOptions,
	tracker *telemetry.FlowTracker,
)

Source from the content-addressed store, hash-verified

182}
183
184func createApplication(
185 ctx context.Context,
186 opts *CreateOptions,
187 tracker *telemetry.FlowTracker,
188) (createResult, error) {
189 var result createResult
190 cs := opts.IO.ColorScheme()
191
192 tracker.SetStep(telemetry.StepName)
193 name, err := resolveName(opts)
194 if err != nil {
195 return result, err
196 }
197
198 client := opts.NewDashboardClient(auth.OAuthClientID())
199
200 tracker.SetStep(telemetry.StepAuth)
201 token, err := auth.EnsureAuthenticated(opts.IO, client)
202 if err != nil {
203 return result, err
204 }
205
206 tracker.SetStep(telemetry.StepPlan)
207 var plans []dashboard.Plan
208 if err := callWithReauth(opts.IO, client, &token, "Fetching plans", func(t string) error {
209 var e error
210 plans, e = client.GetSelfServePlans(t)
211 return e
212 }); err != nil {
213 return result, err
214 }
215 if len(plans) == 0 {
216 return result, fmt.Errorf("no self-serve plans are available")
217 }
218
219 // Best-effort: continue without billing status if /1/user fails.
220 var user *dashboard.DashboardUser
221 if err := callWithReauth(opts.IO, client, &token, "Checking account", func(t string) error {
222 var e error
223 user, e = client.GetUser(t)
224 return e
225 }); err != nil {
226 user = nil
227 }
228
229 target, err := selectPlan(opts, plans, user)
230 if err != nil {
231 return result, err
232 }
233 result.plan = apputil.PlanTelemetryID(*target)
234
235 if !target.IsFree() {
236 billingMissing := !apputil.PlanAvailable(plans, target.ID) ||
237 (user != nil && !user.HasPaymentMethod)
238 if billingMissing {
239 result.abortReason = telemetry.AbortReasonBillingRequired
240 return result, offerBilling(opts, client, *target)
241 }

Callers 1

runCreateCmdFunction · 0.85

Calls 15

OAuthClientIDFunction · 0.92
EnsureAuthenticatedFunction · 0.92
PlanTelemetryIDFunction · 0.92
PlanAvailableFunction · 0.92
TrackEventFunction · 0.92
ConfigureProfileFunction · 0.92
resolveNameFunction · 0.85
selectPlanFunction · 0.85
offerBillingFunction · 0.85

Tested by

no test coverage detected