MCPcopy Index your code
hub / github.com/coder/coder / login

Method login

cli/login.go:142–488  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

140}
141
142func (r *RootCmd) login() *serpent.Command {
143 const firstUserTrialEnv = "CODER_FIRST_USER_TRIAL"
144
145 var (
146 email string
147 username string
148 name string
149 password string
150 trial bool
151 useTokenForSession bool
152 )
153 cmd := &serpent.Command{
154 Use: "login [<url>]",
155 Short: "Authenticate with Coder deployment",
156 Long: "By default, the session token is stored in the operating system keyring on " +
157 "macOS and Windows and a plain text file on Linux. Use the --use-keyring flag " +
158 "or CODER_USE_KEYRING environment variable to change the storage mechanism.",
159 Middleware: serpent.RequireRangeArgs(0, 1),
160 Handler: func(inv *serpent.Invocation) error {
161 ctx := inv.Context()
162
163 rawURL := ""
164 var urlSource string
165
166 if len(inv.Args) == 0 {
167 rawURL = r.clientURL.String()
168 urlSource = "flag"
169 if rawURL != "" && rawURL == inv.Environ.Get(envURL) {
170 urlSource = "environment"
171 }
172 } else {
173 rawURL = inv.Args[0]
174 urlSource = "argument"
175 }
176
177 if url, err := r.createConfig().URL().Read(); rawURL == "" && err == nil {
178 urlSource = "config"
179 rawURL = url
180 }
181
182 if rawURL == "" {
183 return xerrors.Errorf("no url argument provided")
184 }
185
186 if !strings.HasPrefix(rawURL, "http://") && !strings.HasPrefix(rawURL, "https://") {
187 scheme := "https"
188 if strings.HasPrefix(rawURL, "localhost") {
189 scheme = "http"
190 }
191 rawURL = fmt.Sprintf("%s://%s", scheme, rawURL)
192 }
193 serverURL, err := url.Parse(rawURL)
194 if err != nil {
195 return xerrors.Errorf("parse raw url %q: %w", rawURL, err)
196 }
197 // Default to HTTPs. Enables simple URLs like: master.cdr.dev
198 if serverURL.Scheme == "" {
199 serverURL.Scheme = "https"

Callers 3

CoreSubcommandsMethod · 0.95
api.test.tsFile · 0.80
loginFnFunction · 0.80

Calls 15

createConfigMethod · 0.95
ensureTokenBackendMethod · 0.95
loginWithPasswordMethod · 0.95
loginTokenMethod · 0.95
PromptFunction · 0.92
isTTYInFunction · 0.85
promptFirstUsernameFunction · 0.85
promptFirstNameFunction · 0.85
promptFirstPasswordFunction · 0.85
promptTrialInfoFunction · 0.85
promptCountryFunction · 0.85

Tested by

no test coverage detected