Skip to content
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

feat: implement login/logout UX #413

Merged
merged 4 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cmd/notation/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func loginCommand(opts *loginOpts) *cobra.Command {
opts = &loginOpts{}
}
command := &cobra.Command{
Use: "login [options] [server]",
Short: "Provides credentials for authenticated registry operations",
Long: `notation login [options] [server]
Use: "login [flags] <server>",
Short: "Login to registry",
Long: `Log in to an OCI registry

Example - Login with provided username and password:
notation login -u <user> -p <password> registry.example.com
Expand All @@ -50,7 +50,7 @@ Example - Login using $NOTATION_USERNAME $NOTATION_PASSWORD variables:
return runLogin(cmd, opts)
},
}
command.Flags().BoolVar(&opts.passwordStdin, "password-stdin", false, "Take the password from stdin")
command.Flags().BoolVar(&opts.passwordStdin, "password-stdin", false, "take the password from stdin")
opts.ApplyFlags(command.Flags())
return command
}
Expand All @@ -67,6 +67,7 @@ func runLogin(cmd *cobra.Command, opts *loginOpts) error {
if err != nil {
return fmt.Errorf("could not get the credentials store: %v", err)
}

// init creds
creds := newCredentialFromInput(
opts.Username,
Expand All @@ -75,6 +76,8 @@ func runLogin(cmd *cobra.Command, opts *loginOpts) error {
if err = nativeStore.Store(serverAddress, creds); err != nil {
return fmt.Errorf("failed to store credentials: %v", err)
}

fmt.Println("Login Succeeded")
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/notation/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func logoutCommand(opts *logoutOpts) *cobra.Command {
opts = &logoutOpts{}
}
return &cobra.Command{
Use: "logout [server]",
Short: "Log out the specified registry hostname",
Use: "logout [flags] <server>",
Short: "Log out from the logged in registries",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("no hostname specified")
Expand Down
1 change: 0 additions & 1 deletion cmd/notation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func main() {
pluginCommand(),
loginCommand(nil),
logoutCommand(nil))

if err := cmd.Execute(); err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 2 additions & 4 deletions specs/commandline/logout.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ Use `notation logout` to log out from an OCI registry.
## Outline

```text
Log out from an OCI registry
Log out from the logged in registries

Usage:
notation logout [flags] [server]
notation logout [flags] <server>

Flags:
--all log out from all logged in registries
-h, --help help for logout
--plain-http registry access via plain HTTP
```

## Usage
Expand Down