MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / getInputs

Function getInputs

pkg/cmd/login/login.go:336–394  ·  view source on GitHub ↗
(configProvider config.IConfigProvider, flags *LoginFlags, isPromptEnabled bool, ask question.Asker, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

334}
335
336func getInputs(configProvider config.IConfigProvider, flags *LoginFlags, isPromptEnabled bool, ask question.Asker, cmd *cobra.Command) (*LoginInputs, error) {
337 server := flags.Server.Value
338 apiKey := flags.ApiKey.Value
339 serviceAccountId := flags.ServiceAccountId.Value
340 idToken := flags.IdToken.Value
341 ignoreSslErrors := flags.IgnoreSslErrors.Value
342
343 if isPromptEnabled {
344 if server == "" {
345 currentServer := configProvider.Get(constants.ConfigUrl)
346
347 if err := ask(&survey.Input{
348 Message: "Octopus Server URL",
349 Default: currentServer,
350 }, &server, survey.WithValidator(survey.Required)); err != nil {
351 return nil, err
352 }
353 }
354
355 if apiKey == "" {
356 var createNewApiKey bool
357
358 if err := ask(&survey.Confirm{
359 Message: "Create a new API key",
360 Default: true,
361 }, &createNewApiKey); err != nil {
362 return nil, err
363 }
364
365 if createNewApiKey {
366 createApiKeyUrl := fmt.Sprintf("%s/app#/users/me/apiKeys", server)
367 createApiKeyLink := output.Cyan(createApiKeyUrl)
368 cmd.Printf("A web browser has been opened at %s. Please create an API key and paste it here. If no web browser is available or if the web browser fails to open, please use the --server and --api-key arguments directly e.g. octopus login --server %s --api-key API-MYAPIKEY.", createApiKeyLink, server)
369 cmd.Println()
370
371 err := browser.OpenURL(createApiKeyUrl)
372
373 if err != nil {
374 return nil, err
375 }
376 }
377
378 if err := ask(&survey.Input{
379 Message: "API Key",
380 }, &apiKey, survey.WithValidator(survey.Required)); err != nil {
381 return nil, err
382 }
383 }
384 }
385
386 inputs := &LoginInputs{
387 server: server,
388 apiKey: apiKey,
389 serviceAccountId: serviceAccountId,
390 idToken: idToken,
391 ignoreSslErrors: ignoreSslErrors,
392 }
393 return inputs, nil

Callers 1

loginRunFunction · 0.85

Calls 2

CyanFunction · 0.92
GetMethod · 0.65

Tested by

no test coverage detected