Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

login: detect missing protocol in URL #54

Merged
merged 1 commit into from
Jun 19, 2020

Conversation

Russtopia
Copy link

@Russtopia Russtopia commented Jun 19, 2020

Fixes #53

What This Does

Detects a user entering a URL without the protocol field, eg. 'localhost:8080' instead of 'http://localhost:8080' which would result in a malformed login URL, and the stored state using incorrect API paths for all coder-cli operations (eg. sync, sh) which give obscure rsync errors.

Since the cli library dispatches sub-commands to the login.Run() function as non-writable array fl.Arg(), the URL can't be patched up silently to be correct, so instead this patch detects the missing protocol prefix in the URL, and prints out a help usage modified to explain that http[s]:// is required.

Desc: "authenticate this client for future operations",
}
}
func (cmd loginCmd) Run(fl *pflag.FlagSet) {
rawURL := fl.Arg(0)
if rawURL == "" {
if rawURL == "" || !strings.HasPrefix(rawURL, "http") {
exitUsage(fl)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested against http://localhost:8080, http://master.cdr.dev/ and https://master.cdr.dev/ and all seem to work (ie., master.cdr.dev auto-downgrades the login URL to http, which I assume is desired).

@Russtopia Russtopia requested review from ammario and cmoog June 19, 2020 20:30
@ammario ammario removed their request for review June 19, 2020 21:05
Copy link
Contributor

@cmoog cmoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Russtopia Russtopia merged commit c69c791 into master Jun 19, 2020
@Russtopia Russtopia deleted the 53-detect-missing-protocol branch June 19, 2020 23:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

login: Malformed login URL arg breaks login, sh and sync
2 participants