Skip to content

Commit

Permalink
#1481 access docker private reg without credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh2253 committed Sep 13, 2023
1 parent 43e6272 commit f825af4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions deepfence_server/pkg/registry/dockerprivate/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func listCatalogRegistryV2(url, userName, password string) ([]string, error) {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth(userName, password)
if len(userName) > 0 {
req.SetBasicAuth(userName, password)
}

resp, err := client.Do(req)
if err != nil {
Expand Down Expand Up @@ -100,7 +102,9 @@ func listRepoTagsV2(url, userName, password, repoName string) (RepoTagsResp, err
return repoTags, err
}
req.Header.Set("Content-Type", "application/json")
req.SetBasicAuth(userName, password)
if len(userName) > 0 {
req.SetBasicAuth(userName, password)
}

resp, err := client.Do(req)
if err != nil {
Expand Down Expand Up @@ -145,7 +149,9 @@ func getManifestsV2(url, userName, password, repoName, tag string) (string, Mani
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/vnd.docker.distribution.manifest.list.v2+json")
req.SetBasicAuth(userName, password)
if len(userName) > 0 {
req.SetBasicAuth(userName, password)
}

resp, err := client.Do(req)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions deepfence_server/pkg/registry/dockerprivate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type RegistryDockerPrivate struct {

type NonSecret struct {
DockerRegistryURL string `json:"docker_registry_url" validate:"required,url"`
DockerUsername string `json:"docker_username" validate:"required,min=2"`
DockerUsername string `json:"docker_username" validate:"omitempty,min=2"`
}

type Secret struct {
DockerPassword string `json:"docker_password" validate:"required,min=2"`
DockerPassword string `json:"docker_password" validate:"omitempty,min=2"`
}

type ReposResp struct {
Expand Down

0 comments on commit f825af4

Please sign in to comment.