-
Notifications
You must be signed in to change notification settings - Fork 11
/
MacHost.groovy
177 lines (154 loc) · 5.09 KB
/
MacHost.groovy
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
package fr.edf.jenkins.plugins.mac
import org.apache.commons.lang.StringUtils
import org.kohsuke.stapler.AncestorInPath
import org.kohsuke.stapler.DataBoundConstructor
import org.kohsuke.stapler.DataBoundSetter
import org.kohsuke.stapler.QueryParameter
import fr.edf.jenkins.plugins.mac.util.FormUtils
import hudson.Extension
import hudson.model.Describable
import hudson.model.Descriptor
import hudson.model.Item
import hudson.model.Label
import hudson.model.labels.LabelAtom
import hudson.util.FormValidation
import hudson.util.ListBoxModel
import hudson.util.FormValidation.Kind
import jenkins.model.Jenkins
/**
* Configuration of a Mac SSH Connection
* @author Mathieu DELROCQ
*
*/
class MacHost implements Describable<MacHost> {
String host
String credentialsId
Integer port
Integer maxUsers
Integer connectionTimeout
Integer readTimeout
Integer kexTimeout
Integer agentConnectionTimeout
Integer maxTries
Boolean disabled
String labelString
transient Set<LabelAtom> labelSet
@DataBoundConstructor
MacHost(String host, String credentialsId, Integer port, Integer maxUsers,
Integer connectionTimeout, Integer readTimeout, Integer kexTimeout, Boolean disabled, Integer maxTries, String labelString) {
this.host = host
this.credentialsId = credentialsId
this.port = port
this.maxUsers = maxUsers
this.connectionTimeout = connectionTimeout
this.readTimeout = readTimeout
this.kexTimeout = new Integer(0)
this.agentConnectionTimeout = agentConnectionTimeout
this.disabled = disabled
this.maxTries = maxTries
this.labelString = labelString
labelSet = Label.parse(StringUtils.defaultIfEmpty(labelString, ""))
}
@DataBoundSetter
void setHost(String host) {
this.host = host
}
@DataBoundSetter
void setCredentialsId(String credentialsId) {
this.credentialsId = credentialsId
}
@DataBoundSetter
void setPort(Integer port) {
this.port = port
}
@DataBoundSetter
void setMaxUsers(Integer maxUsers) {
this.maxUsers = maxUsers
}
@DataBoundSetter
void setConnectionTimeout(Integer connectionTimeout) {
this.connectionTimeout = connectionTimeout
}
@DataBoundSetter
void setReadTimeout(Integer readTimeout) {
this.readTimeout = readTimeout
}
@DataBoundSetter
void setKexTimeout(Integer kexTimeout) {
this.kexTimeout = kexTimeout
}
@DataBoundSetter
void setAgentConnectionTimeout(Integer agentConnectionTimeout) {
this.agentConnectionTimeout = agentConnectionTimeout
}
@DataBoundSetter
void setDisabled(Boolean disabled) {
this.disabled = disabled
}
@DataBoundSetter
void setMaxTries(Integer maxTries) {
this.maxTries = maxTries
}
@DataBoundSetter
void setLabelString(String labelString) {
this.labelString = labelString
}
@Override
Descriptor<MacHost> getDescriptor() {
return Jenkins.get().getDescriptorOrDie(this.getClass())
}
Set<LabelAtom> getLabelSet() {
return Label.parse(StringUtils.defaultIfEmpty(this.labelString, ""))
}
/**
* Descriptor of a Mac Host for Jenkins UI
* @see src\main\resources\fr\jenkins\plugins\mac\MacHost\config.groovy
* @author mathieu.delrocq
*
*/
@Extension
static class DescriptorImpl extends Descriptor<MacHost> {
/**
* {@inheritDoc}
*/
@Override
String getDisplayName() {
return Messages.Host_DisplayName()
}
/**
* Check if the value of host field is correct
* @param value
* @return FormValidation
*/
FormValidation doCheckHost(@QueryParameter String value) {
def validation = FormUtils.validateHost(value)
if (validation.kind == Kind.OK) {
validation = FormUtils.validateNotEmpty(value, Messages.Host_HostRequired())
}
return validation
}
/**
* Return ListBoxModel of existing credentials
* @param host
* @param credentialsId
* @param context
* @return ListBoxModel
*/
ListBoxModel doFillCredentialsIdItems(@QueryParameter String host,
@QueryParameter String credentialsId, @AncestorInPath Item ancestor) {
return FormUtils.newCredentialsItemsListBoxModel(host, credentialsId, ancestor)
}
/**
* Verify the connection to the Mac machine
* @param host
* @param credentialsId
* @param context
* @return ok if connection, ko if error
*/
FormValidation doVerifyConnection(@QueryParameter String host, @QueryParameter Integer port,
@QueryParameter String credentialsId, @QueryParameter Integer connectionTimeout,
@QueryParameter Integer readTimeout, @AncestorInPath Item context) {
return FormUtils.verifyCredential(host, port, credentialsId, connectionTimeout, readTimeout, 0, context)
}
}
}