Skip to content
Snippets Groups Projects
Commit 628f6e61 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Support a new Credentials API

parent f85855b9
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,9 @@ import ( ...@@ -9,7 +9,9 @@ import (
"strconv" "strconv"
"strings" "strings"
"encoding/base64"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/dustin/gojson"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers" "gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers"
"time" "time"
) )
...@@ -271,6 +273,28 @@ func (b *Build) String() string { ...@@ -271,6 +273,28 @@ func (b *Build) String() string {
return helpers.ToYAML(b) return helpers.ToYAML(b)
} }
func (b *Build) GetDockerConfig() string {
config := &struct {
Authorizations map[string]interface{} `json:"auths"`
}{
Authorizations: make(map[string]interface{}),
}
for _, credential := range b.Credentials.GetByType(CredentialContainerRegistry) {
config.Authorizations[credential.ServerURL] = &struct {
Auth string `json:"auth"`
}{
Auth: credential.EncodeUserAndPassword(),
}
}
data, err := json.Marshal(config)
if err != nil {
return ""
}
return string(data)
}
func (b *Build) GetDefaultVariables() BuildVariables { func (b *Build) GetDefaultVariables() BuildVariables {
return BuildVariables{ return BuildVariables{
{"CI", "true", true, true, false}, {"CI", "true", true, true, false},
...@@ -286,6 +310,7 @@ func (b *Build) GetDefaultVariables() BuildVariables { ...@@ -286,6 +310,7 @@ func (b *Build) GetDefaultVariables() BuildVariables {
{"CI_SERVER_NAME", "GitLab CI", true, true, false}, {"CI_SERVER_NAME", "GitLab CI", true, true, false},
{"CI_SERVER_VERSION", "", true, true, false}, {"CI_SERVER_VERSION", "", true, true, false},
{"CI_SERVER_REVISION", "", true, true, false}, {"CI_SERVER_REVISION", "", true, true, false},
{"DOCKER_CONFIG", b.GetDockerConfig(), false, true, true},
{"GITLAB_CI", "true", true, true, false}, {"GITLAB_CI", "true", true, true, false},
} }
} }
......
...@@ -70,23 +70,24 @@ type BuildInfo struct { ...@@ -70,23 +70,24 @@ type BuildInfo struct {
} }
type GetBuildResponse struct { type GetBuildResponse struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
ProjectID int `json:"project_id,omitempty"` ProjectID int `json:"project_id,omitempty"`
Commands string `json:"commands,omitempty"` Commands string `json:"commands,omitempty"`
RepoURL string `json:"repo_url,omitempty"` RepoURL string `json:"repo_url,omitempty"`
Sha string `json:"sha,omitempty"` Sha string `json:"sha,omitempty"`
RefName string `json:"ref,omitempty"` RefName string `json:"ref,omitempty"`
BeforeSha string `json:"before_sha,omitempty"` BeforeSha string `json:"before_sha,omitempty"`
AllowGitFetch bool `json:"allow_git_fetch,omitempty"` AllowGitFetch bool `json:"allow_git_fetch,omitempty"`
Timeout int `json:"timeout,omitempty"` Timeout int `json:"timeout,omitempty"`
Variables BuildVariables `json:"variables"` Variables BuildVariables `json:"variables"`
Options BuildOptions `json:"options"` Options BuildOptions `json:"options"`
Token string `json:"token"` Token string `json:"token"`
Name string `json:"name"` Name string `json:"name"`
Stage string `json:"stage"` Stage string `json:"stage"`
Tag bool `json:"tag"` Tag bool `json:"tag"`
DependsOnBuilds []BuildInfo `json:"depends_on_builds"` DependsOnBuilds []BuildInfo `json:"depends_on_builds"`
TLSCAChain string `json:"-"` Credentials BuildCredentials `json:"credentials"`
TLSCAChain string `json:"-"`
} }
type RegisterRunnerRequest struct { type RegisterRunnerRequest struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment