Skip to content

Commit

Permalink
Support Docker repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Nosmoht committed Jan 24, 2020
1 parent 5c2eac5 commit 95bf37f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type Client interface {
RepositoryAptCreate(Repository, string) error
RepositoryAptUpdate(string, Repository, string) error
RepositoryAptDelete(string) error
RepositoryDockerCreate(Repository, string) error
RepositoryDockerUpdate(string, Repository, string) error
RepositoryDockerDelete(string) error
RepositoryCreate(Repository, string, string) error
RepositoryUpdate(string, Repository, string, string) error
RepositoryRead(string, string, string) (*Repository, error)
Expand Down
3 changes: 3 additions & 0 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type Repository struct {
// Apt Repository data
*Apt `json:"apt,omitempty"`
*AptSigning `json:"aptSigning,omitempty"`

// Docker Repository data
*Docker `json:"docker"`
}

// RepositoryCleanup ...
Expand Down
25 changes: 25 additions & 0 deletions repository_docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package client

// Docker represents the data used for Repositories of type Docker
type Docker struct {
V1Enabled bool `json:"v1Enabled"`
ForceBasicAuth bool `json:"forceBasicAuth"`
HTTPPort int `json:"httpPort"`
HTTPSPort int `json:"httpsPort"`
}

func (c client) RepositoryDockerCreate(repo Repository, repoType string) error {
return c.RepositoryCreate(repo, "docker", repoType)
}

func (c client) RepositoryDockerRead(id string, repoType string) (*Repository, error) {
return c.RepositoryRead(id, "docker", repoType)
}

func (c client) RepositoryDockerUpdate(id string, repo Repository, repoType string) error {
return c.RepositoryUpdate(id, repo, "docker", repoType)
}

func (c client) RepositoryDockerDelete(id string) error {
return c.RepositoryDelete(id)
}
45 changes: 45 additions & 0 deletions repository_docker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package client

import (
"testing"

"github.com/stretchr/testify/assert"
)

func getTestRepositoryDocker(name string) Repository {
return Repository{
Name: name,
Online: true,
Cleanup: RepositoryCleanup{
PolicyNames: []string{"weekly-cleanup"},
},
Docker: &Docker{
V1Enabled: false,
ForceBasicAuth: true,
HTTPPort: 8082,
HTTPSPort: 8083,
},
Storage: RepositoryStorage{
BlobStoreName: "default",
StrictContentTypeValidation: true,
WritePolicy: "allow_once",
},
}
}

func TestRepositoryDockerHosted(t *testing.T) {
client := NewClient(getDefaultConfig())
repo := getTestRepositoryDocker("test-docker-repo-hosted")

err := client.RepositoryDockerCreate(repo, "hosted")
assert.Nil(t, err)

updatedRepo := repo
updatedRepo.Online = false

err = client.RepositoryDockerUpdate(repo.Name, updatedRepo, "hosted")
assert.Nil(t, err)

err = client.RepositoryDockerDelete(repo.Name)
assert.Nil(t, err)
}

0 comments on commit 95bf37f

Please sign in to comment.