mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-22 05:40:50 +02:00
refactor: extract code from the container package
This commit is contained in:
parent
4130b110c6
commit
d1abce889a
15 changed files with 253 additions and 185 deletions
33
pkg/registry/registry.go
Normal file
33
pkg/registry/registry.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package registry
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/api/types"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// GetPullOptions creates a struct with all options needed for pulling images from a registry
|
||||
func GetPullOptions(imageName string) (types.ImagePullOptions, error) {
|
||||
auth, err := EncodedAuth(imageName)
|
||||
log.Debugf("Got image name: %s", imageName)
|
||||
if err != nil {
|
||||
return types.ImagePullOptions{}, err
|
||||
}
|
||||
|
||||
log.Debugf("Got auth value: %s", auth)
|
||||
if auth == "" {
|
||||
return types.ImagePullOptions{}, nil
|
||||
}
|
||||
|
||||
return types.ImagePullOptions{
|
||||
RegistryAuth: auth,
|
||||
PrivilegeFunc: DefaultAuthHandler,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DefaultAuthHandler will be invoked if an AuthConfig is rejected
|
||||
// It could be used to return a new value for the "X-Registry-Auth" authentication header,
|
||||
// but there's no point trying again with the same value as used in AuthConfig
|
||||
func DefaultAuthHandler() (string, error) {
|
||||
log.Debug("Authentication request was rejected. Trying again without authentication")
|
||||
return "", nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue