Skip to content
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
6 changes: 3 additions & 3 deletions docs/content/1_getting_started/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,17 @@ Log into a registry and store credentials

**--help, -h**: show help

**--identity-token**: Log in with identity token interactively
**--identity-token**="": identity token

**--identity-token-stdin**: Log in with identity token from stdin

**--insecure**: Ignore TLS certificate verification issues for registry connections.

**--password, -p**: Log in with password interactively
**--password, -p**="": registry password

**--password-stdin**: Log in with password from stdin

**--username, -u**="": Log in using username and password
**--username, -u**="": registry username

#### help, h

Expand Down
10 changes: 8 additions & 2 deletions docs/content/2_concepts/catalog_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ Only plain `major.minor.patch` is accepted.
If your registry needs authentication, log in once:

```bash
kubara catalog login -u my-github-user --password ghcr.io
kubara catalog login -u my-github-user --password my-password ghcr.io
```

or alternatively

```bash
printf '%s' "$GITHUB_TOKEN" | kubara catalog login -u my-github-user --password-stdin ghcr.io
```

kubara stores registry credentials in:
Expand All @@ -122,7 +128,7 @@ You can use:

- username/password (interactive)
- password from stdin
- identity token (interactive)
- identity token from flag
- identity token from stdin

## Step 4: Push the cached catalog
Expand Down
37 changes: 17 additions & 20 deletions src/cmd/catalog/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
type catalogLoginFlags struct {
insecure bool
username string
password bool
password string
passwordStdin bool
identityToken bool
identityToken string
identityTokenStdin bool
}

Expand All @@ -33,23 +33,23 @@ func NewCatalogLogin() *cli.Command {
&cli.StringFlag{
Name: "username",
Aliases: []string{"u"},
Usage: "Log in using username and password",
Usage: "registry username",
Destination: &flags.username,
},
&cli.BoolFlag{
&cli.StringFlag{
Comment thread
Matthiator marked this conversation as resolved.
Name: "password",
Aliases: []string{"p"},
Usage: "Log in with password interactively",
Usage: "registry password",
Comment thread
Matthiator marked this conversation as resolved.
Destination: &flags.password,
},
&cli.BoolFlag{
Name: "password-stdin",
Usage: "Log in with password from stdin",
Destination: &flags.passwordStdin,
},
&cli.BoolFlag{
&cli.StringFlag{
Name: "identity-token",
Usage: "Log in with identity token interactively",
Usage: "identity token",
Destination: &flags.identityToken,
},
&cli.BoolFlag{
Expand Down Expand Up @@ -94,15 +94,15 @@ func NewCatalogLogin() *cli.Command {
func resolveCatalogLoginOptions(flags *catalogLoginFlags) (internal.LoginOptions, error) {
var err error

if flags.password && flags.passwordStdin {
if (flags.password != "") && flags.passwordStdin {
return internal.LoginOptions{}, fmt.Errorf("password and password-stdin cannot be used together")
}
if flags.identityToken && flags.identityTokenStdin {
if (flags.identityToken != "") && flags.identityTokenStdin {
return internal.LoginOptions{}, fmt.Errorf("identity-token and identity-token-stdin cannot be used together")
}

usesPasswordInputs := flags.username != "" || flags.password || flags.passwordStdin
usesIdentityTokenAuth := flags.identityToken || flags.identityTokenStdin
usesPasswordInputs := flags.username != "" || flags.password != "" || flags.passwordStdin
usesIdentityTokenAuth := flags.identityToken != "" || flags.identityTokenStdin

if usesPasswordInputs && usesIdentityTokenAuth {
return internal.LoginOptions{}, fmt.Errorf("username/password and identity token authentication cannot be combined")
Expand All @@ -111,20 +111,15 @@ func resolveCatalogLoginOptions(flags *catalogLoginFlags) (internal.LoginOptions
if usesIdentityTokenAuth {
var identityToken string

switch {
case flags.identityTokenStdin:
if flags.identityToken != "" {
identityToken = flags.identityToken
}
if flags.identityTokenStdin {
identityToken, err = readLine(io.Discard, "", false)
if err != nil {
return internal.LoginOptions{}, fmt.Errorf("read identity token from stdin: %w", err)
}

default:
identityToken, err = readLine(os.Stdout, "Identity Token: ", true)
if err != nil {
return internal.LoginOptions{}, fmt.Errorf("read identity token: %w", err)
}
}

return internal.LoginOptions{
IdentityToken: identityToken,
Insecure: flags.insecure,
Expand All @@ -141,6 +136,8 @@ func resolveCatalogLoginOptions(flags *catalogLoginFlags) (internal.LoginOptions

var password string
switch {
case flags.password != "":
password = flags.password
case flags.passwordStdin:
password, err = readLine(io.Discard, "", false)
if err != nil {
Expand Down
Loading