/
configuration.go
242 lines (208 loc) · 9.02 KB
/
configuration.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package gocd
import (
"context"
)
// ConfigurationService describes the HAL _link resource for the api response object for a pipelineconfig
type ConfigurationService service
// ConfigXML part of cruise-control.xml. @TODO better documentation
type ConfigXML struct {
Repositories []ConfigMaterialRepository `xml:"repositories>repository"`
Server ConfigServer `xml:"server"`
SCMS []ConfigSCM `xml:"scms>scm"`
ConfigRepositories []ConfigRepository `xml:"config-repos>config-repo"`
PipelineGroups []ConfigPipelineGroup `xml:"pipelines"`
}
// ConfigPipelineGroup contains a single pipeline groups
type ConfigPipelineGroup struct {
Name string `xml:"group,attr"`
Pipelines []ConfigPipeline `xml:"pipeline"`
}
// ConfigPipeline part of cruise-control.xml. @TODO better documentation
// codebeat:disable[TOO_MANY_IVARS]
type ConfigPipeline struct {
Name string `xml:"name,attr"`
LabelTemplate string `xml:"labeltemplate,attr"`
Params []ConfigParam `xml:"params>param"`
GitMaterials []GitRepositoryMaterial `xml:"materials>git,omitempty"`
PipelineMaterials []PipelineMaterial `xml:"materials>pipeline,omitempty"`
Timer string `xml:"timer"`
EnvironmentVariables []ConfigEnvironmentVariable `xml:"environmentvariables>variable"`
Stages []ConfigStage `xml:"stage"`
}
// codebeat:enable[TOO_MANY_IVARS]
// ConfigStage part of cruise-control.xml. @TODO better documentation
type ConfigStage struct {
Name string `xml:"name,attr"`
Approval ConfigApproval `xml:"approval,omitempty" json:",omitempty"`
Jobs []ConfigJob `xml:"jobs>job"`
}
// ConfigJob part of cruise-control.xml. @TODO better documentation
type ConfigJob struct {
Name string `xml:"name,attr"`
EnvironmentVariables []ConfigEnvironmentVariable `xml:"environmentvariables>variable" json:",omitempty"`
Tasks ConfigTasks `xml:"tasks"`
Resources []string `xml:"resources>resource" json:",omitempty"`
Artifacts []ConfigArtifact `xml:"artifacts>artifact" json:",omitempty"`
}
// ConfigArtifact part of cruise-control.xml. @TODO better documentation
type ConfigArtifact struct {
Src string `xml:"src,attr"`
Destination string `xml:"dest,attr,omitempty" json:",omitempty"`
}
// ConfigApproval part of cruise-control.xml. @TODO better documentation
type ConfigApproval struct {
Type string `xml:"type,attr,omitempty" json:",omitempty"`
}
// ConfigEnvironmentVariable part of cruise-control.xml. @TODO better documentation
type ConfigEnvironmentVariable struct {
Name string `xml:"name,attr"`
Value string `xml:"value"`
}
// PipelineMaterial part of cruise-control.xml. @TODO better documentation
type PipelineMaterial struct {
Name string `xml:"pipelineName,attr"`
StageName string `xml:"stageName,attr"`
MaterialName string `xml:"materialName,attr"`
}
// GitRepositoryMaterial part of cruise-control.xml. @TODO better documentation
type GitRepositoryMaterial struct {
URL string `xml:"url,attr"`
Filters []ConfigFilter `xml:"filter>ignore,omitempty"`
}
// ConfigFilter part of cruise-control.xml. @TODO better documentation
type ConfigFilter struct {
Ignore string `xml:"pattern,attr,omitempty"`
}
// ConfigParam part of cruise-control.xml. @TODO better documentation
type ConfigParam struct {
Name string `xml:"name,attr"`
Value string `xml:",chardata"`
}
// ConfigRepository part of cruise-control.xml. @TODO better documentation
type ConfigRepository struct {
Plugin string `xml:"plugin,attr"`
ID string `xml:"id,attr"`
Git ConfigRepositoryGit `xml:"git"`
}
// ConfigRepositoryGit part of cruise-control.xml. @TODO better documentation
type ConfigRepositoryGit struct {
URL string `xml:"url,attr"`
}
// ConfigSCM part of cruise-control.xml. @TODO better documentation
type ConfigSCM struct {
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
PluginConfiguration ConfigPluginConfiguration `xml:"pluginConfiguration"`
Configuration []ConfigProperty `xml:"configuration>property"`
}
// ConfigMaterialRepository part of cruise-control.xml. @TODO better documentation
type ConfigMaterialRepository struct {
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
PluginConfiguration ConfigPluginConfiguration `xml:"pluginConfiguration"`
Configuration []ConfigProperty `xml:"configuration>property"`
Packages []ConfigPackage `xml:"packages>package"`
}
// ConfigPackage part of cruise-control.xml. @TODO better documentation
type ConfigPackage struct {
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
Configuration []ConfigProperty `xml:"configuration>property"`
}
// ConfigPluginConfiguration part of cruise-control.xml. @TODO better documentation
type ConfigPluginConfiguration struct {
ID string `xml:"id,attr"`
Version string `xml:"version,attr"`
}
// ConfigServer part of cruise-control.xml. @TODO better documentation
// codebeat:disable[TOO_MANY_IVARS]
type ConfigServer struct {
MailHost MailHost `xml:"mailhost"`
Security ConfigSecurity `xml:"security"`
Elastic ConfigElastic `xml:"elastic"`
ArtifactsDir string `xml:"artifactsdir,attr"`
SiteURL string `xml:"siteUrl,attr"`
SecureSiteURL string `xml:"secureSiteUrl,attr"`
PurgeStart string `xml:"purgeStart,attr"`
PurgeUpTo string `xml:"purgeUpto,attr"`
JobTimeout int `xml:"jobTimeout,attr"`
AgentAutoRegisterKey string `xml:"agentAutoRegisterKey,attr"`
WebhookSecret string `xml:"webhookSecret,attr"`
CommandRepositoryLocation string `xml:"commandRepositoryLocation,attr"`
ServerID string `xml:"serverId,attr"`
}
// codebeat:enable[TOO_MANY_IVARS]
// MailHost part of cruise-control.xml. @TODO better documentation
type MailHost struct {
Hostname string `xml:"hostname,attr"`
Port int `xml:"port,attr"`
TLS bool `xml:"tls,attr"`
From string `xml:"from,attr"`
Admin string `xml:"admin,attr"`
}
// ConfigSecurity part of cruise-control.xml. @TODO better documentation
type ConfigSecurity struct {
AuthConfigs []ConfigAuthConfig `xml:"authConfigs>authConfig"`
Roles []ConfigRole `xml:"roles>role"`
Admins []string `xml:"admins>user"`
PasswordFile PasswordFilePath `xml:"passwordFile"`
}
// PasswordFilePath describes the location to set of user/passwords on disk
type PasswordFilePath struct {
Path string `xml:"path,attr"`
}
// ConfigRole part of cruise-control.xml. @TODO better documentation
type ConfigRole struct {
Name string `xml:"name,attr"`
Users []string `xml:"users>user"`
}
// ConfigAuthConfig part of cruise-control.xml. @TODO better documentation
type ConfigAuthConfig struct {
ID string `xml:"id,attr"`
PluginID string `xml:"pluginId,attr"`
Properties []ConfigProperty `xml:"property"`
}
// ConfigElastic part of cruise-control.xml. @TODO better documentation
type ConfigElastic struct {
Profiles []ConfigElasticProfile `xml:"profiles>profile"`
}
// ConfigElasticProfile part of cruise-control.xml. @TODO better documentation
type ConfigElasticProfile struct {
ID string `xml:"id,attr"`
PluginID string `xml:"pluginId,attr"`
Properties []ConfigProperty `xml:"property"`
}
// ConfigProperty part of cruise-control.xml. @TODO better documentation
type ConfigProperty struct {
Key string `xml:"key"`
Value string `xml:"value"`
}
// Version part of cruise-control.xml. @TODO better documentation
type Version struct {
Links *HALLinks `json:"_links"`
Version string `json:"version"`
BuildNumber string `json:"build_number"`
GitSHA string `json:"git_sha"`
FullVersion string `json:"full_version"`
CommitURL string `json:"commit_url"`
}
// Get the config.xml document from the server and... render it as JSON... 'cause... eyugh.
func (cs *ConfigurationService) Get(ctx context.Context) (cx *ConfigXML, resp *APIResponse, err error) {
cx = &ConfigXML{}
_, resp, err = cs.client.getAction(ctx, &APIClientRequest{
Path: "admin/config.xml",
ResponseBody: cx,
ResponseType: responseTypeXML,
})
return
}
// GetVersion of the GoCD server and other metadata about the software version.
func (cs *ConfigurationService) GetVersion(ctx context.Context) (v *Version, resp *APIResponse, err error) {
v = &Version{}
_, resp, err = cs.client.getAction(ctx, &APIClientRequest{
Path: "version",
ResponseBody: v,
APIVersion: apiV1,
})
return
}