Skip to content

Commit

Permalink
feat: implement login/logout UX (#413)
Browse files Browse the repository at this point in the history
implemnt login UI based on
https://github.com/notaryproject/notation/blob/main/specs/commandline/login.md
fix:
1. added `Login Succeeded` message when login succeeded
2. added username parameter validation
3. removed --plain-http global flag
4. updated spec: removed logout --plain-http & --all flag

Test:
1. login with -u -p flags
2. login with $NOTATION_USERNAME $NOTATION_PASSWORD
3. login with --password-stdin
5. login without username -> `username was not set.`

Signed-off-by: Junjie Gao <[email protected]>
  • Loading branch information
JeyJeyGao authored Oct 31, 2022
1 parent 469069e commit a41b377
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
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

0 comments on commit a41b377

Please sign in to comment.