@@ -31,15 +31,15 @@ import (
31
31
gitHttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
32
32
)
33
33
34
- //GitHub type
35
- type GitHub struct {
34
+ //Git type
35
+ type Git struct {
36
36
Filepath string
37
37
OrgRepo string
38
38
VerifyCircleCISuccess bool
39
39
CircleCIDeployJobName string
40
40
}
41
41
42
- func (gitHub GitHub ) Write (serviceAccountName string , keyWrapper KeyWrapper , creds cred.Credentials ) (updated UpdatedLocation , err error ) {
42
+ func (git Git ) Write (serviceAccountName string , keyWrapper KeyWrapper , creds cred.Credentials ) (updated UpdatedLocation , err error ) {
43
43
44
44
if len (creds .KmsKey ) == 0 {
45
45
err = errors .New ("Not updating un-encrypted new key in a Git repository. Use the" +
@@ -56,81 +56,81 @@ func (gitHub GitHub) Write(serviceAccountName string, keyWrapper KeyWrapper, cre
56
56
defer os .RemoveAll (localDir )
57
57
58
58
var signKey * openpgp.Entity
59
- if signKey , err = crypt .CommitSignKey (creds .GitHubAccount .GitName , creds .GitHubAccount .GitEmail , creds .AkrPass ); err != nil {
59
+ if signKey , err = crypt .CommitSignKey (creds .GitAccount .GitName , creds .GitAccount .GitEmail , creds .AkrPass ); err != nil {
60
60
return
61
61
}
62
62
63
63
var committed * object.Commit
64
64
const singleLine = false
65
65
const disableValidation = true
66
- if committed , err = writeKeyToRemoteGitRepo (gitHub , serviceAccountName ,
66
+ if committed , err = writeKeyToRemoteGitRepo (git , serviceAccountName ,
67
67
crypt .EncryptedServiceAccountKey (key , creds .KmsKey ),
68
68
localDir , signKey , creds ); err != nil {
69
69
return
70
70
}
71
71
72
- if gitHub .VerifyCircleCISuccess {
73
- err = verifyCircleCIJobSuccess (gitHub .OrgRepo ,
72
+ if git .VerifyCircleCISuccess {
73
+ err = verifyCircleCIJobSuccess (git .OrgRepo ,
74
74
fmt .Sprintf ("%s" , committed .ID ()),
75
- gitHub .CircleCIDeployJobName , creds .CircleCIAPIToken )
75
+ git .CircleCIDeployJobName , creds .CircleCIAPIToken )
76
76
}
77
77
78
78
updated = UpdatedLocation {
79
- LocationType : "GitHub " ,
80
- LocationURI : gitHub .OrgRepo ,
81
- LocationIDs : []string {gitHub .Filepath }}
79
+ LocationType : "Git " ,
80
+ LocationURI : git .OrgRepo ,
81
+ LocationIDs : []string {git .Filepath }}
82
82
83
83
return
84
84
}
85
85
86
86
//writeKeyToRemoteGitRepo handles the writing of the supplied key to the *remote*
87
- // Git repo defined in the GitHub struct
88
- func writeKeyToRemoteGitRepo (gitHub GitHub , serviceAccountName string ,
87
+ // Git repo defined in the Git struct
88
+ func writeKeyToRemoteGitRepo (gitt Git , serviceAccountName string ,
89
89
key []byte , localDir string , signKey * openpgp.Entity , creds cred.Credentials ) (committed * object.Commit , err error ) {
90
90
var repo * git.Repository
91
- if repo , err = cloneGitRepo (localDir , gitHub .OrgRepo ,
92
- creds .GitHubAccount . GitHubAccessToken ); err != nil {
91
+ if repo , err = cloneGitRepo (localDir , gitt .OrgRepo ,
92
+ creds .GitAccount . GitAccessToken ); err != nil {
93
93
return
94
94
}
95
- logger .Infof ("Cloned git repo: %s" , gitHub .OrgRepo )
95
+ logger .Infof ("Cloned git repo: %s" , gitt .OrgRepo )
96
96
var commit plumbing.Hash
97
- if commit , err = writeKeyToLocalGitRepo (gitHub , repo , key , serviceAccountName ,
97
+ if commit , err = writeKeyToLocalGitRepo (gitt , repo , key , serviceAccountName ,
98
98
localDir , signKey , creds ); err != nil {
99
99
return
100
100
}
101
101
if committed , err = repo .CommitObject (commit ); err != nil {
102
102
return
103
103
}
104
- logger .Infof ("Committed to local git repo: %s" , gitHub .OrgRepo )
104
+ logger .Infof ("Committed to local git repo: %s" , gitt .OrgRepo )
105
105
if err = repo .Push (& git.PushOptions {Auth : & gitHttp.BasicAuth {
106
106
Username : "abc123" , // yes, this can be anything except an empty string
107
- Password : creds .GitHubAccount . GitHubAccessToken ,
107
+ Password : creds .GitAccount . GitAccessToken ,
108
108
},
109
109
Progress : os .Stdout }); err != nil {
110
110
return
111
111
}
112
- logger .Infof ("Pushed to remote git repo: %s" , gitHub .OrgRepo )
112
+ logger .Infof ("Pushed to remote git repo: %s" , gitt .OrgRepo )
113
113
return
114
114
}
115
115
116
116
//writeKeyToLocalGitRepo handles the writing of the supplied key to the *local*
117
- // Git repo defined in the GitHub struct
118
- func writeKeyToLocalGitRepo (gitHub GitHub , repo * git.Repository , key []byte ,
117
+ // Git repo defined in the Git struct
118
+ func writeKeyToLocalGitRepo (gitt Git , repo * git.Repository , key []byte ,
119
119
serviceAccountName , localDir string , signKey * openpgp.Entity , creds cred.Credentials ) (commmit plumbing.Hash , err error ) {
120
120
var w * git.Worktree
121
121
if w , err = repo .Worktree (); err != nil {
122
122
return
123
123
}
124
- fullFilePath := localDir + "/" + gitHub .Filepath
124
+ fullFilePath := localDir + "/" + gitt .Filepath
125
125
if err = ioutil .WriteFile (fullFilePath , key , 0644 ); err != nil {
126
126
return
127
127
}
128
128
w .Add (fullFilePath )
129
129
autoStage := true
130
130
return w .Commit (fmt .Sprintf ("CKR updating %s" , serviceAccountName ), & git.CommitOptions {
131
131
Author : & object.Signature {
132
- Name : creds .GitHubAccount .GitName ,
133
- Email : creds .GitHubAccount .GitEmail ,
132
+ Name : creds .GitAccount .GitName ,
133
+ Email : creds .GitAccount .GitEmail ,
134
134
When : time .Now (),
135
135
},
136
136
All : autoStage ,
0 commit comments