(cmd *cobra.Command, f factory.Factory, isPromptEnabled bool, ask question.Asker, flags *LoginFlags)
| 91 | } |
| 92 | |
| 93 | func loginRun(cmd *cobra.Command, f factory.Factory, isPromptEnabled bool, ask question.Asker, flags *LoginFlags) error { |
| 94 | |
| 95 | configProvider, err := f.GetConfigProvider() |
| 96 | |
| 97 | if err != nil { |
| 98 | return err |
| 99 | } |
| 100 | |
| 101 | inputs, err := getInputs(configProvider, flags, isPromptEnabled, ask, cmd) |
| 102 | if err != nil { |
| 103 | return err |
| 104 | } |
| 105 | |
| 106 | if inputs.server == "" { |
| 107 | return errors.New("must supply server") |
| 108 | } |
| 109 | |
| 110 | if inputs.serviceAccountId == "" && inputs.apiKey == "" { |
| 111 | return errors.New("must supply a service account id or api key") |
| 112 | } |
| 113 | |
| 114 | if inputs.serviceAccountId != "" && inputs.apiKey != "" { |
| 115 | return errors.New("can only login with one of service account id or api key") |
| 116 | } |
| 117 | |
| 118 | httpClient, err := f.GetHttpClient() |
| 119 | |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | |
| 124 | // The http client could be nil, in which case we just use the default one from http |
| 125 | if httpClient == nil { |
| 126 | httpClient = &http.Client{} |
| 127 | } |
| 128 | |
| 129 | if inputs.ignoreSslErrors { |
| 130 | if httpClient.Transport == nil { |
| 131 | httpClient.Transport = &http.Transport{} |
| 132 | } |
| 133 | |
| 134 | httpClient.Transport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} |
| 135 | } |
| 136 | |
| 137 | if inputs.apiKey != "" { |
| 138 | err = loginWithApiKey(configProvider, httpClient, inputs.server, inputs.apiKey, cmd) |
| 139 | if err != nil { |
| 140 | return err |
| 141 | } |
| 142 | } else if inputs.serviceAccountId != "" { |
| 143 | if inputs.idToken == "" { |
| 144 | return errors.New("must supply an id token when logging in with OpenID Connect") |
| 145 | } |
| 146 | |
| 147 | err = loginWithOpenIdConnect(configProvider, httpClient, inputs.server, inputs.serviceAccountId, inputs.idToken, cmd) |
| 148 | if err != nil { |
| 149 | return err |
| 150 | } |
no test coverage detected