diff --git a/api/git/git_test.go b/api/git/git_test.go index 8276a0925..2d48d153c 100644 --- a/api/git/git_test.go +++ b/api/git/git_test.go @@ -2,16 +2,17 @@ package git import ( "context" - "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing/object" - "github.com/pkg/errors" - "github.com/portainer/portainer/api/archive" - "github.com/stretchr/testify/assert" "io/ioutil" "log" "os" "path/filepath" "testing" + + "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing/object" + "github.com/pkg/errors" + "github.com/portainer/portainer/api/archive" + "github.com/stretchr/testify/assert" ) var bareRepoDir string diff --git a/api/git/types/types.go b/api/git/types/types.go new file mode 100644 index 000000000..3fddf9fbb --- /dev/null +++ b/api/git/types/types.go @@ -0,0 +1,19 @@ +package gittypes + +// RepoConfig represents a configuration for a repo +type RepoConfig struct { + // The repo url + URL string `example:"https://github.com/portainer/portainer-ee.git"` + // The reference name + ReferenceName string `example:"refs/heads/branch_name"` + // Path to where the config file is in this url/refName + ConfigFilePath string `example:"docker-compose.yml"` + // Git credentials + Authentication *GitAuthentication + ConfigHash []byte +} + +type GitAuthentication struct { + Username string + Password string +} diff --git a/api/http/handler/stacks/create_compose_stack.go b/api/http/handler/stacks/create_compose_stack.go index a12538aff..efb2593ad 100644 --- a/api/http/handler/stacks/create_compose_stack.go +++ b/api/http/handler/stacks/create_compose_stack.go @@ -13,6 +13,7 @@ import ( "github.com/portainer/libhttp/request" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/filesystem" + gittypes "github.com/portainer/portainer/api/git/types" "github.com/portainer/portainer/api/http/security" ) @@ -168,7 +169,7 @@ func (handler *Handler) createComposeStackFromGitRepository(w http.ResponseWrite AdditionalFiles: payload.AdditionalFiles, AutoUpdate: payload.AutoUpdate, Env: payload.Env, - GitConfig: &portainer.GitConfig{ + GitConfig: &gittypes.RepoConfig{ URL: payload.RepositoryURL, ReferenceName: payload.RepositoryReferenceName, }, @@ -177,7 +178,7 @@ func (handler *Handler) createComposeStackFromGitRepository(w http.ResponseWrite } if payload.RepositoryAuthentication { - stack.GitConfig.Authentication = &portainer.GitAuthentication{ + stack.GitConfig.Authentication = &gittypes.GitAuthentication{ Username: payload.RepositoryUsername, Password: payload.RepositoryPassword, } diff --git a/api/http/handler/stacks/create_swarm_stack.go b/api/http/handler/stacks/create_swarm_stack.go index 6838a3bb2..d4f74d460 100644 --- a/api/http/handler/stacks/create_swarm_stack.go +++ b/api/http/handler/stacks/create_swarm_stack.go @@ -13,6 +13,7 @@ import ( "github.com/portainer/libhttp/request" portainer "github.com/portainer/portainer/api" "github.com/portainer/portainer/api/filesystem" + gittypes "github.com/portainer/portainer/api/git/types" "github.com/portainer/portainer/api/http/security" ) @@ -172,7 +173,7 @@ func (handler *Handler) createSwarmStackFromGitRepository(w http.ResponseWriter, EntryPoint: payload.ComposeFile, AdditionalFiles: payload.AdditionalFiles, AutoUpdate: payload.AutoUpdate, - GitConfig: &portainer.GitConfig{ + GitConfig: &gittypes.RepoConfig{ URL: payload.RepositoryURL, ReferenceName: payload.RepositoryReferenceName, }, @@ -182,7 +183,7 @@ func (handler *Handler) createSwarmStackFromGitRepository(w http.ResponseWriter, } if payload.RepositoryAuthentication { - stack.GitConfig.Authentication = &portainer.GitAuthentication{ + stack.GitConfig.Authentication = &gittypes.GitAuthentication{ Username: payload.RepositoryUsername, Password: payload.RepositoryPassword, } diff --git a/api/portainer.go b/api/portainer.go index 14adaf754..58c247862 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -3,6 +3,9 @@ package portainer import ( "io" "time" + + "github.com/portainer/liblicense" + gittypes "github.com/portainer/portainer/api/git/types" ) type ( @@ -686,7 +689,7 @@ type ( // Stack auto update settings AutoUpdate *StackAutoUpdate `json:"AutoUpdate" example:""` // Git settings - GitConfig *GitConfig `json:"GitConfig" example:""` + GitConfig *gittypes.RepoConfig `json:"GitConfig"` // A list of environment variables used during stack deployment Env []Pair `json:"Env" example:""` //