Skip to content

Commit

Permalink
feat: update CMDs to be consistent with specs
Browse files Browse the repository at this point in the history
Signed-off-by: Binbin Li <[email protected]>
  • Loading branch information
binbin-li committed Jul 14, 2022
1 parent 7085fc0 commit 7a2547c
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 16 deletions.
3 changes: 0 additions & 3 deletions cmd/notation/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var (
flagLocal,
flagUsername,
flagPassword,
flagPlainHTTP,
},
ArgsUsage: "[reference|manifest_digest]",
Action: listCachedSignatures,
Expand Down Expand Up @@ -62,7 +61,6 @@ var (
flagLocal,
flagUsername,
flagPassword,
flagPlainHTTP,
},
Action: pruneCachedSignatures,
}
Expand All @@ -76,7 +74,6 @@ var (
flagLocal,
flagUsername,
flagPassword,
flagPlainHTTP,
},
Action: removeCachedSignatures,
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/notation/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ var (
flagUsername = &cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Usage: "username for generic remote access",
Usage: "Username for registry operations",
EnvVars: []string{"NOTATION_USERNAME"},
}
flagPassword = &cli.StringFlag{
Name: "password",
Aliases: []string{"p"},
Usage: "password for generic remote access",
Usage: "Password for registry operations",
EnvVars: []string{"NOTATION_PASSWORD"},
}
flagPlainHTTP = &cli.BoolFlag{
Name: "plain-http",
Usage: "remote access via plain HTTP",
Usage: "Registry access via plain HTTP",
}
flagMediaType = &cli.StringFlag{
Name: "media-type",
Expand Down
1 change: 0 additions & 1 deletion cmd/notation/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var listCommand = &cli.Command{
Flags: []cli.Flag{
flagUsername,
flagPassword,
flagPlainHTTP,
},
Action: runList,
}
Expand Down
43 changes: 39 additions & 4 deletions cmd/notation/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,35 @@ package main
import (
"errors"
"fmt"
"io"
"os"
"strings"

"github.com/notaryproject/notation/pkg/auth"
"github.com/urfave/cli/v2"
orasauth "oras.land/oras-go/v2/registry/remote/auth"
)

var loginCommand = &cli.Command{
Name: "login",
Usage: "Log in the specified registry hostname",
ArgsUsage: "<SERVER>",
Name: "login",
Usage: "Provides credentials for authenticated registry operations",
UsageText: `notation login [options] [server]
Example - Login with provided username and password:
notation login -u <user> -p <password> registry.example.com
Example - Login using $NOTATION_USERNAME $NOTATION_PASSWORD variables:
notation login registry.example.com`,
ArgsUsage: "[server]",
Flags: []cli.Flag{
flagUsername,
flagPassword,
flagPlainHTTP,
&cli.BoolFlag{
Name: "password-stdin",
Usage: "Take the password from stdin",
},
},
Before: readPassword,
Action: runLogin,
}

Expand Down Expand Up @@ -65,3 +79,24 @@ func newCredentialFromInput(username, password string) orasauth.Credential {
}
return c
}

func readPassword(ctx *cli.Context) error {
if ctx.Bool("password-stdin") {
password, err := readLine()
if err != nil {
return err
}
ctx.Set(flagPassword.Name, password)
}
return nil
}

func readLine() (string, error) {
passwordBytes, err := io.ReadAll(os.Stdin)
if err != nil {
return "", err
}
password := strings.TrimSuffix(string(passwordBytes), "\n")
password = strings.TrimSuffix(password, "\r")
return password, nil
}
2 changes: 1 addition & 1 deletion cmd/notation/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var logoutCommand = &cli.Command{
Name: "logout",
Usage: "Log out the specified registry hostname",
ArgsUsage: "<SERVER>",
ArgsUsage: "[server]",
Action: runLogout,
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/notation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func main() {
Name: "CNCF Notary Project",
},
},
Flags: []cli.Flag{
flagPlainHTTP,
},
Commands: []*cli.Command{
signCommand,
verifyCommand,
Expand Down
1 change: 0 additions & 1 deletion cmd/notation/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var pullCommand = &cli.Command{
flagOutput,
flagUsername,
flagPassword,
flagPlainHTTP,
},
Action: runPull,
}
Expand Down
1 change: 0 additions & 1 deletion cmd/notation/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var pushCommand = &cli.Command{
flagSignature,
flagUsername,
flagPassword,
flagPlainHTTP,
},
Action: runPush,
}
Expand Down
1 change: 0 additions & 1 deletion cmd/notation/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var signCommand = &cli.Command{
},
flagUsername,
flagPassword,
flagPlainHTTP,
flagMediaType,
cmd.FlagPluginConfig,
},
Expand Down
1 change: 0 additions & 1 deletion cmd/notation/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var verifyCommand = &cli.Command{
flagLocal,
flagUsername,
flagPassword,
flagPlainHTTP,
flagMediaType,
},
Action: runVerify,
Expand Down

0 comments on commit 7a2547c

Please sign in to comment.