mirror of
https://github.com/containrrr/watchtower.git
synced 2026-02-16 20:28:07 +01:00
fix linting, formatting. tidy up go mod
This commit is contained in:
parent
b5823cfbf9
commit
3d21ea683c
8 changed files with 22 additions and 42 deletions
|
|
@ -254,6 +254,7 @@ func (c Container) HasImageInfo() bool {
|
|||
return c.imageInfo != nil
|
||||
}
|
||||
|
||||
// ImageInfo fetches the ImageInspect data of the current container
|
||||
func (c Container) ImageInfo() *types.ImageInspect {
|
||||
return c.imageInfo
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,10 +126,10 @@ func GetAuthURL(challenge string, img string) (*url2.URL, error) {
|
|||
}
|
||||
if values["realm"] == "" || values["service"] == "" {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"realm": values["realm"],
|
||||
"realm": values["realm"],
|
||||
"service": values["service"],
|
||||
}).Debug("Checking challenge header content")
|
||||
return nil, fmt.Errorf("challenge header did not include all values needed to construct an auth url", )
|
||||
return nil, fmt.Errorf("challenge header did not include all values needed to construct an auth url")
|
||||
}
|
||||
|
||||
authURL, _ := url2.Parse(fmt.Sprintf("%s", values["realm"]))
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@ package auth
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/containrrr/watchtower/pkg/logger"
|
||||
wtTypes "github.com/containrrr/watchtower/pkg/types"
|
||||
"github.com/docker/docker/api/types"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/containrrr/watchtower/pkg/logger"
|
||||
wtTypes "github.com/containrrr/watchtower/pkg/types"
|
||||
"github.com/docker/docker/api/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
|
|
@ -59,9 +60,9 @@ var _ = Describe("the auth module", func() {
|
|||
It("should create a valid auth url object based on the challenge header supplied", func() {
|
||||
input := `bearer realm="https://ghcr.io/token",service="ghcr.io",scope="repository:user/image:pull"`
|
||||
expected := &url.URL{
|
||||
Host: "ghcr.io",
|
||||
Scheme: "https",
|
||||
Path: "/token",
|
||||
Host: "ghcr.io",
|
||||
Scheme: "https",
|
||||
Path: "/token",
|
||||
RawQuery: "scope=repository%3Acontainrrr%2Fwatchtower%3Apull&service=ghcr.io",
|
||||
}
|
||||
res, err := GetAuthURL(input, "containrrr/watchtower")
|
||||
|
|
@ -69,7 +70,7 @@ var _ = Describe("the auth module", func() {
|
|||
Expect(res).To(Equal(expected))
|
||||
})
|
||||
It("should create a valid auth url object based on the challenge header supplied", func() {
|
||||
input := `bearer realm="https://ghcr.io/token",service="ghcr.io"`
|
||||
input := `bearer realm="https://ghcr.io/token"`
|
||||
res, err := GetAuthURL(input, "containrrr/watchtower")
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(res).To(BeNil())
|
||||
|
|
@ -77,18 +78,17 @@ var _ = Describe("the auth module", func() {
|
|||
})
|
||||
When("getting a challenge url", func() {
|
||||
It("should create a valid challenge url object based on the image ref supplied", func() {
|
||||
expected := url.URL{ Host: "ghcr.io", Scheme: "https", Path: "/v2/"}
|
||||
expected := url.URL{Host: "ghcr.io", Scheme: "https", Path: "/v2/"}
|
||||
Expect(GetChallengeURL("ghcr.io/containrrr/watchtower:latest")).To(Equal(expected))
|
||||
})
|
||||
It("should assume dockerhub if the image ref is not fully qualified", func() {
|
||||
expected := url.URL{ Host: "index.docker.io", Scheme: "https", Path: "/v2/"}
|
||||
expected := url.URL{Host: "index.docker.io", Scheme: "https", Path: "/v2/"}
|
||||
Expect(GetChallengeURL("containrrr/watchtower:latest")).To(Equal(expected))
|
||||
})
|
||||
It("should convert legacy dockerhub hostnames to index.docker.io", func() {
|
||||
expected := url.URL{ Host: "index.docker.io", Scheme: "https", Path: "/v2/"}
|
||||
expected := url.URL{Host: "index.docker.io", Scheme: "https", Path: "/v2/"}
|
||||
Expect(GetChallengeURL("docker.io/containrrr/watchtower:latest")).To(Equal(expected))
|
||||
Expect(GetChallengeURL("registry-1.docker.io/containrrr/watchtower:latest")).To(Equal(expected))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func CompareDigest(ctx context.Context, image apiTypes.ImageInspect, credentials
|
|||
for _, dig := range image.RepoDigests {
|
||||
localDigest := strings.Split(dig, "@")[1]
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"local": localDigest,
|
||||
"local": localDigest,
|
||||
"remote": digest,
|
||||
}).Debug("Comparing")
|
||||
if localDigest == digest {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func TestDigest(t *testing.T) {
|
||||
|
||||
RegisterFailHandler(Fail)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ var _ = Describe("the manifest module", func() {
|
|||
It("should return a valid url given a fully qualified image", func() {
|
||||
expected := "https://ghcr.io/v2/containrrr/watchtower/manifests/latest"
|
||||
imageInfo := apiTypes.ImageInspect{
|
||||
RepoTags: []string {
|
||||
RepoTags: []string{
|
||||
"ghcr.io/containrrr/watchtower:latest",
|
||||
},
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ var _ = Describe("the manifest module", func() {
|
|||
It("should assume dockerhub for non-qualified images", func() {
|
||||
expected := "https://index.docker.io/v2/containrrr/watchtower/manifests/latest"
|
||||
imageInfo := apiTypes.ImageInspect{
|
||||
RepoTags: []string {
|
||||
RepoTags: []string{
|
||||
"containrrr/watchtower:latest",
|
||||
},
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ var _ = Describe("the manifest module", func() {
|
|||
It("should assume latest for images that lack an explicit tag", func() {
|
||||
expected := "https://index.docker.io/v2/containrrr/watchtower/manifests/latest"
|
||||
imageInfo := apiTypes.ImageInspect{
|
||||
RepoTags: []string {
|
||||
RepoTags: []string{
|
||||
"containrrr/watchtower",
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue