8000 Replace "GitHub Enterprise Server" option with "other" in gh auth login prompting by jtmcg · Pull Request #9642 · cli/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace "GitHub Enterprise Server" option with "other" in gh auth login prompting #9642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 23, 2024

Conversation

jtmcg
Copy link
Contributor
@jtmcg jtmcg commented Sep 19, 2024

Closes #9641

Changes

  • gh auth login prompting now provides an "other" option in place of "GitHub Enterprise Server"
  • Tests were added/updated to cover this change
  • Docs were updated for the gh auth login command to clarify how to use hostnames

To test

  1. Pull down the branch and build using make
  2. Run bin/gh auth login
  3. Notice the change in prompt
Screenshot 2024-09-20 at 2 16 30 PM
  1. Complete the flow to see that it is successful
Screenshot 2024-09-20 at 2 20 42 PM

@jtmcg jtmcg requested a review from a team as a code owner September 19, 2024 22:23
@jtmcg jtmcg requested a review from BagToad September 19, 2024 22:23
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Sep 19, 2024
…ompt

This change is meant to better support the login flow for other customers
besides GitHub Enterprise Server customers that use the same login flow
as GHES.
@jtmcg jtmcg added 8000 gh-auth relating to the gh auth command and removed external pull request originating outside of the CLI core team gh-auth relating to the gh auth command labels Sep 19, 2024
Copy link
Member
@mxie mxie left a comment

Choose a reason for hiding this comment

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

Left some thoughts on the docs!

Copy link
Member
@williammartin williammartin left a comment

Choose a reason for hiding this comment

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

I think this is missing both prompt changes from the A/C:

➜  gh auth login
? Where do you use GitHub? [Use arrows to move, type to filter]
  github.com
> other

? Hostname:
? What account do you want to log into?  [Use arrows to move, type to filter]
? Where do you use GitHub? [Use arrows to move, type to filter]
? GHE Hostname:
? Hostname:

@jtmcg
Copy link
Contributor Author
jtmcg commented Sep 20, 2024

I think this is missing both prompt changes from the A/C:

➜  gh auth login
? Where do you use GitHub? [Use arrows to move, type to filter]
  github.com
> other

? Hostname:
? What account do you want to log into?  [Use arrows to move, type to filter]
? Where do you use GitHub? [Use arrows to move, type to filter]
? GHE Hostname:
? Hostname:

Totally missed that detail! Thanks for calling them out.

The default authentication mode is a web-based browser flow. After completion, an
authentication token will be stored securely in the system credential store.
If a credential store is not found or there is an issue using it gh will fallback
to writing the token to a plain text file. See `gh auth status` for its
stored location.

Alternatively, use `--with-token` to pass in a token on standard input.
The minimum required scopes for the token are: `repo`, `read:org`, and `gist`.

Alternatively, gh will use the authentication token found in environment variables.
This method is most suitable for "headless" use of gh such as in automation. See
`gh help environment` for more info.

To use gh in GitHub Actions, add `GH_TOKEN: ${{ github.token }}` to `env`.

The git protocol to use for git operations on this host can be set with `--git-protocol`,
or during the interactive prompting. Although login is for a single account on a host, setting
the git protocol will take effect for all users on the host.

Specifying `ssh` for the git protocol will detect existing SSH keys to upload,
prompting to create and upload a new key if one is not found. This can be skipped with
`--skip-ssh-key` flag.

USAGE
  gh auth login [flags]

FLAGS
  -p, --git-protocol string   The protocol to use for git operations on this host: {ssh|https}
  -h, --hostname string       The hostname of the GitHub instance to authenticate with
      --insecure-storage      Save authentication credentials in plain text instead of credential store
  -s, --scopes strings        Additional authentication scopes to request
      --skip-ssh-key          Skip generate/upload SSH key prompt
  -w, --web                   Open a browser to authenticate
      --with-token            Read token from standard input

INHERITED FLAGS
  --help   Show help for command

EXAMPLES
  # Start interactive setup
  $ gh auth login

  # Authenticate against github.com by reading the token from a file
  $ gh auth login --with-token < mytoken.txt

  # Authenticate with specific host
  $ gh auth login --hostname enterprise.internal

LEARN MORE
  Use `gh <command> <subcommand> --help` for more information about a command.
  Read the manual at https://cli.github.com/manual
  Learn about exit codes using `gh help exit-codes` around Tylers-GitHub-MacBook.local
@jtmcg jtmcg requested a review from williammartin September 20, 2024 22:52
@williammartin
Copy link
Member

Given I am in an interactive terminal environment
When I run gh auth login
Then I am presented with:

➜  gh auth login
? Where do you use GitHub? [Use arrows to move, type to filter]
  github.com
> other

? Hostname:

➜ ./bin/gh auth login
? Where do you use GitHub?  [Use arrows to move, type to filter]
  GitHub.com
> Other
➜ ./bin/gh auth login
? Where do you use GitHub? Other
? Hostname:

Copy link
Member
@williammartin williammartin left a comment

Choose a reason for hiding this comment

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

Deeply annoying that you can't comment on unmodified lines but I think we should adjust this block

isEnterprise := hostType == 1
hostname := ghinstance.Default()
if isEnterprise {
hostname, err = opts.Prompter.InputHostname()
}
return hostname, err

Firstly, isEnterprise doesn't capture the intent which is now "other". Secondly, there's no good reason to go lookup the hostname if we're not using it. Thirdly, it's idiomatic to early return in Go. Fourthly, return thing, err in the case where you know err is nil forces the developer to parse any previous conditionals in order to understand that there is no error.

I'd suggest changing this to:

	isGitHubDotCom := hostType == 0
	if isGitHubDotCom {
		return ghinstance.Default(), nil
	}

	return opts.Prompter.InputHostname()

I'm not sure why we bother calling for the default hostname when we know the user chose github.com in the select but it also doesn't really matter.

@@ -803,3 +804,50 @@ func Test_loginRun_Survey(t *testing.T) {
})
}
}

func Test_promptForHostname(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Interesting test!

…anges

The old isEnterprise check no longer makes sense, given the prompter is
providing 'other', not 'GitHub Enterprise Server' as its non-GitHub.com
option. Additionally, there was an opportunity for cleaning up the code
via early returns and the removal of the default hostname lookup if we
don't need it.
@jtmcg jtmcg requested a review from williammartin September 23, 2024 16:37
@jtmcg
Copy link
Contributor Author
jtmcg commented Sep 23, 2024

Given I am in an interactive terminal environment When I run gh auth login Then I am presented with:

➜  gh auth login
? Where do you use GitHub? [Use arrows to move, type to filter]
  github.com
> other

? Hostname:
➜ ./bin/gh auth login
? Where do you use GitHub?  [Use arrows to move, type to filter]
  GitHub.com
> Other
➜ ./bin/gh auth login
? Where do you use GitHub? Other
? Hostname:

Is there a change requested by this comment, @williammartin?

@williammartin
Copy link
Member

Is there a change requested by this comment, @williammartin?

No, sorry, it was me doing the A/C and then was following up with the review but I didn't comment it as such.

Copy link
Member
@williammartin williammartin left a comment

Choose a reason for hiding this comment

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

LGTM!

@jtmcg jtmcg merged commit 9f3f91f into trunk Sep 23, 2024
16 checks passed
@jtmcg jtmcg deleted the jtmcg/503 branch September 23, 2024 17:50
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Oct 16, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.57.0` -> `v2.58.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.58.0`](https://github.com/cli/cli/releases/tag/v2.58.0): GitHub CLI 2.58.0

[Compare Source](cli/cli@v2.57.0...v2.58.0)

#### What's Changed

-   Better messaging for `attestation verify` custom issuer mismatch error by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#9616
-   Enhance gh repo create docs, fix random cmd link by [@&#8203;andyfeller](https://github.com/andyfeller) in cli/cli#9630
-   Add HasActiveToken method to AuthConfig to refactor auth check for `attestation trusted-root` command by [@&#8203;BagToad](https://github.com/BagToad) in cli/cli#9635
-   Improve the suggested command for creating an issue when an extension doesn't have a binary for your platform by [@&#8203;timrogers](https://github.com/timrogers) in cli/cli#9608
-   Disable auth check for `attestation trusted-root` command by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#9610
-   build(deps): bump github.com/henvic/httpretty from 0.1.3 to 0.1.4 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#9645
-   Fix tenant-awareness for `trusted-root` command by [@&#8203;bdehamer](https://github.com/bdehamer) in cli/cli#9638
-   Replace "GitHub Enterprise Server" option with "other" in gh auth login prompting by [@&#8203;jtmcg](https://github.com/jtmcg) in cli/cli#9642
-   build(deps): bump github.com/cpuguy83/go-md2man/v2 from 2.0.4 to 2.0.5 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#9634
-   Add `dnf5` instru
6D40
ctions to `docs/install_linux.md` by [@&#8203;its-miroma](https://github.com/its-miroma) in cli/cli#9660
-   build(deps): bump github.com/theupdateframework/go-tuf/v2 from 2.0.0 to 2.0.1 by [@&#8203;dependabot](https://github.com/dependabot) in cli/cli#9688

#### New Contributors

-   [@&#8203;its-miroma](https://github.com/its-miroma) made their first contribution in cli/cli#9660

**Full Changelog**: cli/cli@v2.57.0...v2.58.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace "GitHub Enterprise Server" option with "other" in gh auth login prompting
5 participants
0