-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move OCI/Docker-registry-related cmds from
remote
to their own cmd (#…
…1908) * improved doc strings * fixed stray unrenamed method * updated e2e test names * added visual indicator of system endpoint in keyserver list * re-added `login` capability for keyservers * move registry-related cmds from `remote` to their own cmd * improved visuals for insecure registries * corrected error msgs in registry login/logout flows * refactor: create ObtainLoginArgs() and use it from keyserver & registry CLI code
- Loading branch information
preminger
authored
Jul 21, 2023
1 parent
9cf1bbe
commit 925071a
Showing
16 changed files
with
768 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2019-2023, Sylabs Inc. All rights reserved. | ||
// Copyright (c) 2020, Control Command Inc. All rights reserved. | ||
// This software is licensed under a 3-clause BSD license. Please consult the | ||
// LICENSE.md file distributed with the sources of this project regarding your | ||
// rights to use or distribute this software. | ||
|
||
package cli | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"strings" | ||
|
||
"github.com/sylabs/singularity/internal/app/singularity" | ||
"github.com/sylabs/singularity/pkg/sylog" | ||
) | ||
|
||
func ObtainLoginArgs(name string) *singularity.LoginArgs { | ||
var loginArgs singularity.LoginArgs | ||
|
||
loginArgs.Name = name | ||
|
||
loginArgs.Username = loginUsername | ||
loginArgs.Password = loginPassword | ||
loginArgs.Tokenfile = loginTokenFile | ||
loginArgs.Insecure = loginInsecure | ||
|
||
if loginPasswordStdin { | ||
p, err := io.ReadAll(os.Stdin) | ||
if err != nil { | ||
sylog.Fatalf("Failed to read password from stdin: %s", err) | ||
} | ||
loginArgs.Password = strings.TrimSuffix(string(p), "\n") | ||
loginArgs.Password = strings.TrimSuffix(loginArgs.Password, "\r") | ||
} | ||
|
||
return &loginArgs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright (c) 2019-2023, Sylabs Inc. All rights reserved. | ||
// Copyright (c) 2020, Control Command Inc. All rights reserved. | ||
// This software is licensed under a 3-clause BSD license. Please consult the | ||
// LICENSE.md file distributed with the sources of this project regarding your | ||
// rights to use or distribute this software. | ||
|
||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/sylabs/singularity/docs" | ||
"github.com/sylabs/singularity/internal/app/singularity" | ||
"github.com/sylabs/singularity/pkg/cmdline" | ||
"github.com/sylabs/singularity/pkg/sylog" | ||
) | ||
|
||
// -c|--config | ||
var registryConfigFlag = cmdline.Flag{ | ||
ID: "registryConfigFlag", | ||
Value: &remoteConfig, | ||
DefaultValue: remoteConfigUser, | ||
Name: "config", | ||
ShortHand: "c", | ||
Usage: "path to the file holding remote endpoint configurations", | ||
} | ||
|
||
// -u|--username | ||
var registryLoginUsernameFlag = cmdline.Flag{ | ||
ID: "registryLoginUsernameFlag", | ||
Value: &loginUsername, | ||
DefaultValue: "", | ||
Name: "username", | ||
ShortHand: "u", | ||
Usage: "username to authenticate with (required for Docker/OCI registry login)", | ||
EnvKeys: []string{"LOGIN_USERNAME"}, | ||
} | ||
|
||
// -p|--password | ||
var registryLoginPasswordFlag = cmdline.Flag{ | ||
ID: "registryLoginPasswordFlag", | ||
Value: &loginPassword, | ||
DefaultValue: "", | ||
Name: "password", | ||
ShortHand: "p", | ||
Usage: "password / token to authenticate with", | ||
EnvKeys: []string{"LOGIN_PASSWORD"}, | ||
} | ||
|
||
// --password-stdin | ||
var registryLoginPasswordStdinFlag = cmdline.Flag{ | ||
ID: "registryLoginPasswordStdinFlag", | ||
Value: &loginPasswordStdin, | ||
DefaultValue: false, | ||
Name: "password-stdin", | ||
Usage: "take password from standard input", | ||
} | ||
|
||
func init() { | ||
addCmdInit(func(cmdManager *cmdline.CommandManager) { | ||
cmdManager.RegisterCmd(RegistryCmd) | ||
cmdManager.RegisterSubCmd(RegistryCmd, RegistryLoginCmd) | ||
cmdManager.RegisterSubCmd(RegistryCmd, RegistryLogoutCmd) | ||
cmdManager.RegisterSubCmd(RegistryCmd, RegistryListCmd) | ||
|
||
// default location of the remote.yaml file is the user directory | ||
cmdManager.RegisterFlagForCmd(®istryConfigFlag, RegistryCmd) | ||
|
||
cmdManager.RegisterFlagForCmd(®istryLoginUsernameFlag, RegistryLoginCmd) | ||
cmdManager.RegisterFlagForCmd(®istryLoginPasswordFlag, RegistryLoginCmd) | ||
cmdManager.RegisterFlagForCmd(®istryLoginPasswordStdinFlag, RegistryLoginCmd) | ||
}) | ||
} | ||
|
||
// RegistryCmd singularity registry [...] | ||
var RegistryCmd = &cobra.Command{ | ||
Run: nil, | ||
|
||
Use: docs.RegistryUse, | ||
Short: docs.RegistryShort, | ||
Long: docs.RegistryLong, | ||
Example: docs.RegistryExample, | ||
|
||
DisableFlagsInUseLine: true, | ||
} | ||
|
||
// RegistryLoginCmd singularity registry login [option] <registry_url> | ||
var RegistryLoginCmd = &cobra.Command{ | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := singularity.RegistryLogin(remoteConfig, ObtainLoginArgs(args[0])); err != nil { | ||
sylog.Fatalf("%s", err) | ||
} | ||
}, | ||
|
||
Use: docs.RegistryLoginUse, | ||
Short: docs.RegistryLoginShort, | ||
Long: docs.RegistryLoginLong, | ||
Example: docs.RegistryLoginExample, | ||
|
||
DisableFlagsInUseLine: true, | ||
} | ||
|
||
// RegistryLogoutCmd singularity remote logout [remoteName|serviceURI] | ||
var RegistryLogoutCmd = &cobra.Command{ | ||
Args: cobra.RangeArgs(0, 1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// default to empty string to signal to registryLogin to use default remote | ||
name := "" | ||
if len(args) > 0 { | ||
name = args[0] | ||
} | ||
|
||
if err := singularity.RegistryLogout(remoteConfig, name); err != nil { | ||
sylog.Fatalf("%s", err) | ||
} | ||
sylog.Infof("Logout succeeded") | ||
}, | ||
|
||
Use: docs.RegistryLogoutUse, | ||
Short: docs.RegistryLogoutShort, | ||
Long: docs.RegistryLogoutLong, | ||
Example: docs.RegistryLogoutExample, | ||
|
||
DisableFlagsInUseLine: true, | ||
} | ||
|
||
// RegistryListCmd singularity remote list | ||
var RegistryListCmd = &cobra.Command{ | ||
Args: cobra.ExactArgs(0), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if err := singularity.RegistryList(remoteConfig); err != nil { | ||
sylog.Fatalf("%s", err) | ||
} | ||
}, | ||
|
||
Use: docs.RegistryListUse, | ||
Short: docs.RegistryListShort, | ||
Long: docs.RegistryListLong, | ||
Example: docs.RegistryListExample, | ||
|
||
DisableFlagsInUseLine: true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) 2019-2023, Sylabs Inc. All rights reserved. | ||
// Copyright (c) 2020, Control Command Inc. All rights reserved. | ||
// This software is licensed under a 3-clause BSD license. Please consult the | ||
// LICENSE.md file distributed with the sources of this project regarding your | ||
// rights to use or distribute this software. | ||
|
||
package docs | ||
|
||
// Global content for help and man pages | ||
const ( | ||
|
||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// registry command | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
RegistryUse string = `registry [subcommand options...]` | ||
RegistryShort string = `Manage authentication to OCI/Docker registries` | ||
RegistryLong string = ` | ||
The 'registry' command allows you to manage authentication to standalone OCI/Docker | ||
registries, such as 'docker://'' or 'oras://'.` | ||
RegistryExample string = ` | ||
All group commands have their own help output: | ||
$ singularity help registry login | ||
$ singularity registry login` | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// registry login command | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
RegistryLoginUse string = `login [login options...] <registry_uri>` | ||
RegistryLoginShort string = `Login to an OCI/Docker registry` | ||
RegistryLoginLong string = ` | ||
The 'registry login' command allows you to login to a specific OCI/Docker | ||
registry.` | ||
RegistryLoginExample string = ` | ||
To login in to a docker/OCI registry: | ||
$ singularity registry login --username foo docker://docker.io | ||
$ singularity registry login --username foo oras://myregistry.example.com | ||
Note that many cloud OCI registries use token-based authentication. The token | ||
should be specified as the password for login. A username is still required. | ||
E.g. when using a standard Azure identity and token to login to an ACR | ||
registry, the username '00000000-0000-0000-0000-000000000000' is required. | ||
Consult your provider's documentation for details concerning their specific | ||
login requirements.` | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// registry logout command | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
RegistryLogoutUse string = `logout <registry_uri>` | ||
RegistryLogoutShort string = `Logout from an OCI/Docker registry` | ||
RegistryLogoutLong string = ` | ||
The 'registry logout' command allows you to log out from an OCI/Docker | ||
registry.` | ||
RegistryLogoutExample string = ` | ||
To log out from an OCI/Docker registry | ||
$ singularity registry logout docker://docker.io` | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// registry list command | ||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
RegistryListUse string = `list` | ||
RegistryListShort string = `List all OCI credentials that are configured` | ||
RegistryListLong string = ` | ||
The 'registry list' command lists all credentials for OCI/Docker registries | ||
that are configured for use.` | ||
RegistryListExample string = ` | ||
$ singularity registry list` | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.