forked from forj-oss/forjj-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins-plugin-model.go
49 lines (41 loc) · 1.27 KB
/
jenkins-plugin-model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
// JenkinsPluginModel provides the structure to evaluate with template before running commands.
type JenkinsPluginModel struct {
Env map[string]string
Creds map[string]string
Config YamlJenkins
}
var JP_Model *JenkinsPluginModel
// Model creates the Model data used by gotemplates in maintain context.
func (p *JenkinsPlugin) Model() (model *JenkinsPluginModel) {
if JP_Model != nil {
return JP_Model
}
JP_Model = new(JenkinsPluginModel)
JP_Model.Creds = make(map[string]string)
JP_Model.Env = make(map[string]string)
JP_Model.Config = p.yaml
return JP_Model
}
func (jpm *JenkinsPluginModel) loadCreds(userName, instanceName string, creds map[string]string) {
if jpm == nil || jpm.Creds == nil {
return
}
// Predefine credentials from jenkins.yaml
appPrefix := "app-" + instanceName + "-"
credList := map[string]string{
"SslPrivateKey": appPrefix + "ssl-private-key",
"AdminPwd": appPrefix + "admin-pwd",
"GithubUserPassword": appPrefix + "github-user-password",
}
for credName, credValue := range credList {
if v, found := creds[credValue]; found && v != "" {
jpm.Creds[credName] = v
}
}
// Extended Credentials
for credName, credValue := range creds {
jpm.Creds[credName] = credValue
}
jpm.Env["Username"] = userName
}