move functions supporting images command to libkpod/image
Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
parent
df7536e3c0
commit
0f44ff1d3b
6 changed files with 281 additions and 235 deletions
|
@ -1,7 +1,9 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
cp "github.com/containers/image/copy"
|
||||
"github.com/containers/image/signature"
|
||||
|
@ -68,3 +70,20 @@ func GetPolicyContext(path string) (*signature.PolicyContext, error) {
|
|||
}
|
||||
return signature.NewPolicyContext(policy)
|
||||
}
|
||||
|
||||
// ParseRegistryCreds takes a credentials string in the form USERNAME:PASSWORD
|
||||
// and returns a DockerAuthConfig
|
||||
func ParseRegistryCreds(creds string) (*types.DockerAuthConfig, error) {
|
||||
if creds == "" {
|
||||
return nil, errors.New("no credentials supplied")
|
||||
}
|
||||
if strings.Index(creds, ":") < 0 {
|
||||
return nil, errors.New("user name supplied, but no password supplied")
|
||||
}
|
||||
v := strings.SplitN(creds, ":", 2)
|
||||
cfg := &types.DockerAuthConfig{
|
||||
Username: v[0],
|
||||
Password: v[1],
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue