ensureClientURL loads the client URL from the config file if it wasn't provided via --url or CODER_URL.
()
| 601 | // ensureClientURL loads the client URL from the config file if it |
| 602 | // wasn't provided via --url or CODER_URL. |
| 603 | func (r *RootCmd) ensureClientURL() error { |
| 604 | if r.clientURL != nil && r.clientURL.String() != "" { |
| 605 | return nil |
| 606 | } |
| 607 | rawURL, err := r.createConfig().URL().Read() |
| 608 | // If the configuration files are absent, the user is logged out. |
| 609 | if os.IsNotExist(err) { |
| 610 | binPath, err := os.Executable() |
| 611 | if err != nil { |
| 612 | binPath = "coder" |
| 613 | } |
| 614 | return xerrors.Errorf(notLoggedInMessage, binPath) |
| 615 | } |
| 616 | if err != nil { |
| 617 | return err |
| 618 | } |
| 619 | r.clientURL, err = url.Parse(strings.TrimSpace(rawURL)) |
| 620 | return err |
| 621 | } |
| 622 | |
| 623 | // ensureTLSConfig loads the TLS configuration from files if specified. |
| 624 | // The resulting config is used for both API requests and DERP connections. |