forked from containers/skopeo
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements skopeo login&logout commands. Signed-off-by: Qi Wang <qiwan@redhat.com>
- Loading branch information
Showing
173 changed files
with
1,039 additions
and
27,706 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/containers/common/pkg/auth" | ||
"github.com/containers/image/v5/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type loginOptions struct { | ||
global *globalOptions | ||
loginOpts auth.LoginOptions | ||
getLogin optionalBool | ||
tlsVerify optionalBool | ||
} | ||
|
||
func loginCmd(global *globalOptions) *cobra.Command { | ||
opts := loginOptions{ | ||
global: global, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "login", | ||
Short: "Login to a container registry", | ||
Long: "Login to a container registry on a specified server.", | ||
RunE: commandAction(opts.run), | ||
Example: `skopeo login quay.io`, | ||
} | ||
adjustUsage(cmd) | ||
flags := cmd.Flags() | ||
optionalBoolFlag(flags, &opts.tlsVerify, "tls-verify", "require HTTPS and verify certificates when accessing the registry") | ||
flags.AddFlagSet(auth.GetLoginFlags(&opts.loginOpts)) | ||
return cmd | ||
} | ||
|
||
func (opts *loginOptions) run(args []string, stdout io.Writer) error { | ||
ctx, cancel := opts.global.commandTimeoutContext() | ||
defer cancel() | ||
opts.loginOpts.Stdout = stdout | ||
opts.loginOpts.Stdin = os.Stdin | ||
sys := opts.global.newSystemContext() | ||
if opts.tlsVerify.present { | ||
sys.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!opts.tlsVerify.value) | ||
} | ||
return auth.Login(ctx, sys, &opts.loginOpts, args) | ||
} |
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,35 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/containers/common/pkg/auth" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type logoutOptions struct { | ||
global *globalOptions | ||
logoutOpts auth.LogoutOptions | ||
} | ||
|
||
func logoutCmd(global *globalOptions) *cobra.Command { | ||
opts := logoutOptions{ | ||
global: global, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "logout", | ||
Short: "Logout of a container registry", | ||
Long: "Logout of a container registry on a specified server.", | ||
RunE: commandAction(opts.run), | ||
Example: `skopeo logout quay.io`, | ||
} | ||
adjustUsage(cmd) | ||
cmd.Flags().AddFlagSet(auth.GetLogoutFlags(&opts.logoutOpts)) | ||
return cmd | ||
} | ||
|
||
func (opts *logoutOptions) run(args []string, stdout io.Writer) error { | ||
opts.logoutOpts.Stdout = stdout | ||
sys := opts.global.newSystemContext() | ||
return auth.Logout(sys, &opts.logoutOpts, args) | ||
} |
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
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,101 @@ | ||
% skopeo-login(1) | ||
|
||
## NAME | ||
skopeo\-login - Login to a container registry | ||
|
||
## SYNOPSIS | ||
**skoepo login** [*options*] *registry* | ||
|
||
## DESCRIPTION | ||
**skopeo login** logs into a specified registry server with the correct username | ||
and password. **skopeo login** reads in the username and password from STDIN. | ||
The username and password can also be set using the **username** and **password** flags. | ||
The path of the authentication file can be specified by the user by setting the **authfile** | ||
flag. The default path used is **${XDG\_RUNTIME\_DIR}/containers/auth.json**. | ||
|
||
## OPTIONS | ||
|
||
**--password**, **-p**=*password* | ||
|
||
Password for registry | ||
|
||
**--password-stdin** | ||
|
||
Take the password from stdin | ||
|
||
**--username**, **-u**=*username* | ||
|
||
Username for registry | ||
|
||
**--authfile**=*path* | ||
|
||
Path of the authentication file. Default is ${XDG\_RUNTIME\_DIR}/containers/auth.json | ||
|
||
Note: You can also override the default path of the authentication file by setting the REGISTRY\_AUTH\_FILE | ||
environment variable. `export REGISTRY_AUTH_FILE=path` | ||
|
||
**--get-login** | ||
|
||
Return the logged-in user for the registry. Return error if no login is found. | ||
|
||
**--cert-dir**=*path* | ||
|
||
Use certificates at *path* (\*.crt, \*.cert, \*.key) to connect to the registry. | ||
Default certificates directory is _/etc/containers/certs.d_. | ||
|
||
**--tls-verify**=*true|false* | ||
|
||
Require HTTPS and verify certificates when contacting registries (default: true). If explicitly set to true, | ||
then TLS verification will be used. If set to false, then TLS verification will not be used. If not specified, | ||
TLS verification will be used unless the target registry is listed as an insecure registry in registries.conf. | ||
|
||
**--help**, **-h** | ||
|
||
Print usage statement | ||
|
||
## EXAMPLES | ||
|
||
``` | ||
$ skopeo login docker.io | ||
Username: testuser | ||
Password: | ||
Login Succeeded! | ||
``` | ||
|
||
``` | ||
$ skopeo login -u testuser -p testpassword localhost:5000 | ||
Login Succeeded! | ||
``` | ||
|
||
``` | ||
$ skopeo login --authfile authdir/myauths.json docker.io | ||
Username: testuser | ||
Password: | ||
Login Succeeded! | ||
``` | ||
|
||
``` | ||
$ skopeo login --tls-verify=false -u test -p test localhost:5000 | ||
Login Succeeded! | ||
``` | ||
|
||
``` | ||
$ skopeo login --cert-dir /etc/containers/certs.d/ -u foo -p bar localhost:5000 | ||
Login Succeeded! | ||
``` | ||
|
||
``` | ||
$ skopeo login -u testuser --password-stdin < testpassword.txt docker.io | ||
Login Succeeded! | ||
``` | ||
|
||
``` | ||
$ echo $testpassword | skopeo login -u testuser --password-stdin docker.io | ||
Login Succeeded! | ||
``` | ||
|
||
## SEE ALSO | ||
skopeo(1), skopeo-logout(1) | ||
|
||
## HISTORY | ||
May 2020, Originally compiled by Qi Wang <qiwan@redhat.com> |
Oops, something went wrong.