Skip to content

Commit f8119bc

Browse files
committedMar 31, 2021
Added support for secret file credentials.
Signed-off-by: Jacek Kikiewicz <[email protected]>
1 parent 0126e12 commit f8119bc

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed
 

‎credentials.go

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ type StringCredentials struct {
5555
Secret string `xml:"secret"`
5656
}
5757

58+
//FileCredentials store a file
59+
//"SecretBytes" is a base64 encoded file content
60+
type FileCredentials struct {
61+
XMLName xml.Name `xml:"org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl"`
62+
ID string `xml:"id"`
63+
Scope string `xml:"scope"`
64+
Description string `xml:"description"`
65+
Filename string `xml:"fileName"`
66+
SecretBytes string `xml:"secretBytes"`
67+
}
68+
5869
//SSHCredentials store credentials for ssh keys.
5970
type SSHCredentials struct {
6071
XMLName xml.Name `xml:"com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey"`

‎credentials_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var (
1414
dockerID = "dockerIDCred"
1515
sshID = "sshIdCred"
1616
usernameID = "usernameIDcred"
17+
fileID = "fileIDcred"
1718
scope = "GLOBAL"
1819
)
1920

@@ -39,6 +40,28 @@ func TestCreateUsernameCredentials(t *testing.T) {
3940
assert.Equal(t, cred.Username, cred.Username, "Username is not equal")
4041
}
4142

43+
func TestCreateFileCredentials(t *testing.T) {
44+
45+
cred := FileCredentials{
46+
ID: fileID,
47+
Scope: scope,
48+
Filename: "testFile.json",
49+
SecretBytes: "VGhpcyBpcyBhIHRlc3Qu\n",
50+
}
51+
52+
ctx := context.Background()
53+
err := cm.Add(ctx, domain, cred)
54+
assert.Nil(t, err, "Could not create credential")
55+
56+
getCred := FileCredentials{}
57+
err = cm.GetSingle(ctx, domain, cred.ID, &getCred)
58+
assert.Nil(t, err, "Could not get credential")
59+
60+
assert.Equal(t, cred.Scope, getCred.Scope, "Scope is not equal")
61+
assert.Equal(t, cred.ID, cred.ID, "ID is not equal")
62+
assert.Equal(t, cred.Filename, cred.Filename, "Filename is not equal")
63+
}
64+
4265
func TestCreateDockerCredentials(t *testing.T) {
4366

4467
cred := DockerServerCredentials{

‎job.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (j *Job) GetBuild(ctx context.Context, id int64) (*Build, error) {
126126
// i.e. Server : https://<domain>/jenkins/job/JOB1
127127
// "https://<domain>/jenkins/" is the server URL,
128128
// we are expecting jobURL = "job/JOB1"
129-
jobURL := strings.Replace(j.Raw.URL,j.Jenkins.Server,"",-1)
129+
jobURL := strings.Replace(j.Raw.URL, j.Jenkins.Server, "", -1)
130130
build := Build{Jenkins: j.Jenkins, Job: j, Raw: new(BuildResponse), Depth: 1, Base: jobURL + "/" + strconv.FormatInt(id, 10)}
131131
status, err := build.Poll(ctx)
132132
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.