diff --git a/client.go b/client.go index b05c5bd..d65b340 100644 --- a/client.go +++ b/client.go @@ -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) diff --git a/repository.go b/repository.go index dbe00c3..7c864bc 100644 --- a/repository.go +++ b/repository.go @@ -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 ... diff --git a/repository_docker.go b/repository_docker.go new file mode 100644 index 0000000..3c633d9 --- /dev/null +++ b/repository_docker.go @@ -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) +} diff --git a/repository_docker_test.go b/repository_docker_test.go new file mode 100644 index 0000000..6704d89 --- /dev/null +++ b/repository_docker_test.go @@ -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) +}