forked from mchugh19/jenkins-saltapi
/
SaltAPIBuilder.java
697 lines (602 loc) · 27.9 KB
/
SaltAPIBuilder.java
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
package com.waytta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.logging.Level;
import com.waytta.clientinterface.BasicClient;
import com.waytta.clientinterface.LocalBatchClient;
import com.waytta.clientinterface.LocalClient;
import com.waytta.clientinterface.RunnerClient;
import org.yaml.snakeyaml.Yaml;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import hudson.model.Item;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.security.ACL;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.FormValidation;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.AncestorInPath;
import jenkins.model.Jenkins;
import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONSerializer;
import net.sf.json.JSONObject;
import net.sf.json.util.JSONUtils;
public class SaltAPIBuilder extends Builder {
private static final Logger LOGGER = Logger.getLogger("com.waytta.saltstack");
private String servername;
private String authtype;
private String arguments;
private String kwarguments;
private final String clientInterfaceName;
private Boolean saveEnvVar = false;
private BasicClient clientInterface;
// Fields in config.jelly must match the parameter names in the
// "DataBoundConstructor"
@DataBoundConstructor
public SaltAPIBuilder(String servername, String authtype, String target, String targettype, String function, JSONObject clientInterfaces, String mods, String pillarvalue, String credentialsId) {
this.servername = servername;
this.authtype = authtype;
if (clientInterfaces.has("clientInterface")) {
this.clientInterfaceName = clientInterfaces.get("clientInterface").toString();
} else {
this.clientInterfaceName = "local";
}
switch (clientInterfaceName) {
case "local":
clientInterface = new LocalClient(credentialsId, clientInterfaces.get("target").toString(), clientInterfaces.get("targetType").toString(), function, clientInterfaces.getBoolean("blockbuild"), clientInterfaces.getInt("jobPollTime"));
break;
case "local_batch":
clientInterface = new LocalBatchClient(credentialsId, clientInterfaces.get("target").toString(), clientInterfaces.get("targetType").toString(), function, clientInterfaces.get("batchSize").toString());
break;
case "runner":
clientInterface = new RunnerClient(credentialsId, function, clientInterfaces.get("mods").toString(), clientInterfaces.get("pillarvalue").toString());
break;
default:
clientInterface = new BasicClient(credentialsId, target, targettype, function);
}
}
/*
* We'll use this from the <tt>config.jelly</tt>.
*/
public String getServername() {
return servername;
}
public String getAuthtype() {
return authtype;
}
public String getTarget() {
return clientInterface.getTarget();
}
public String getTargettype() {
return clientInterface.getTargetType();
}
public String getFunction() {
return clientInterface.getFunction();
}
public String getArguments() {
return arguments;
}
@DataBoundSetter
public void setArguments(String arguments) {
this.arguments = arguments;
}
public String getKwarguments() {
return kwarguments;
}
@DataBoundSetter
public void setKwarguments(String kwarguments) {
this.kwarguments = kwarguments;
}
public String getClientInterface() {
return clientInterfaceName;
}
public Boolean getBlockbuild() {
return clientInterface.getBlockBuild();
}
public String getBatchSize() {
return clientInterface.getBatchSize();
}
public Integer getJobPollTime() {
return clientInterface.getJobPollTime();
}
public String getMods() {
return clientInterface.getMods();
}
public String getPillarvalue() {
return clientInterface.getPillarValue();
}
public String getCredentialsId() {
return clientInterface.getCredentialsId();
}
@DataBoundSetter
public void setSaveEnvVar(Boolean saveEnvVar) {
this.saveEnvVar = saveEnvVar;
}
public Boolean getSaveEnvVar() {
return saveEnvVar;
}
@Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {
// This is where you 'build' the project.
String myOutputFormat = getDescriptor().getOutputFormat();
String myClientInterface = clientInterfaceName;
String myservername = Utils.paramorize(build, listener, servername);
String mytarget = Utils.paramorize(build, listener, getTarget());
String myfunction = Utils.paramorize(build, listener, clientInterface.getFunction());
String myarguments = Utils.paramorize(build, listener, arguments);
String mykwarguments = Utils.paramorize(build, listener, kwarguments);
Boolean myBlockBuild = clientInterface.getBlockBuild();
Boolean jobSuccess = true;
Integer minionTimeout = getDescriptor().getTimeoutTime();
StandardUsernamePasswordCredentials credential = getCredentialById(getCredentialsId());
if (credential == null) {
listener.error("Invalid credentials");
return false;
}
// Setup connection for auth
String token = new String();
JSONArray authArray = createAuthArray(credential);
JSONObject httpResponse = new JSONObject();
JSONArray returnArray = new JSONArray();
// Get an auth token
token = Utils.getToken(myservername, authArray);
if (token.contains("Error")) {
// TODO lookup listener.error
listener.error(token);
return false;
}
// If we got this far, auth must have been good and we've got a token
JSONObject saltFunc = prepareSaltFunction(build, listener, myClientInterface, mytarget, myfunction, myarguments,
mykwarguments);
JSONArray saltArray = new JSONArray();
saltArray.add(saltFunc);
LOGGER.log(Level.FINE, "Sending JSON: " + saltArray.toString());
// blocking request
if (myBlockBuild) {
String jid = new String();
// Send request to /minion url. This will give back a jid which we
// will need to poll and lookup for completion
httpResponse = Utils.getJSON(myservername + "/minions", saltArray, token);
try {
returnArray = httpResponse.getJSONArray("return");
for (Object o : returnArray) {
JSONObject line = (JSONObject) o;
jid = line.getString("jid");
}
// Print out success
listener.getLogger().println("Running jid: " + jid);
} catch (Exception e) {
listener.getLogger()
.println("Problem: " + myfunction + " " + myarguments + " to " + myservername
+ " for " + mytarget + ":\n" + e + "\n\n" + httpResponse.toString(2));
return false;
}
// Request successfully sent. Now use jid to check if job complete
int numMinions = 0;
int numMinionsDone = 0;
JSONArray minionsArray = new JSONArray();
httpResponse = Utils.getJSON(myservername + "/jobs/" + jid, null, token);
try {
// info array will tell us how many minions were targeted
returnArray = httpResponse.getJSONArray("info");
for (Object o : returnArray) {
JSONObject line = (JSONObject) o;
minionsArray = line.getJSONArray("Minions");
// Check the info[Minions[]] array to see how many nodes we
// expect to hear back from
numMinions = minionsArray.size();
listener.getLogger().println("Waiting for " + numMinions + " minions");
}
returnArray = httpResponse.getJSONArray("return");
// Check the return[] array to see how many minions have
// responded
if (!returnArray.getJSONObject(0).names().isEmpty()) {
numMinionsDone = returnArray.getJSONObject(0).names().size();
} else {
numMinionsDone = 0;
}
listener.getLogger().println(numMinionsDone + " minions are done");
} catch (Exception e) {
listener.getLogger()
.println("Problem: " + myfunction + " " + myarguments + " to " + myservername
+ " for " + mytarget + ":\n" + e + "\n\n" + httpResponse.toString(2));
return false;
}
// Now that we know how many minions have responded, and how many we
// are waiting on. Let's see more have finished
if (numMinionsDone < numMinions) {
// Don't print annoying messages unless we really are waiting for
// more minions to return
listener.getLogger().println(
"Will check status every " + clientInterface.getJobPollTime() + " seconds...");
}
while (numMinionsDone < numMinions) {
try {
Thread.sleep(clientInterface.getJobPollTime() * 1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
// Allow user to cancel job in jenkins interface
listener.getLogger().println("Cancelling job");
return false;
}
Integer oldMinionsDone = numMinionsDone;
httpResponse = Utils.getJSON(servername + "/jobs/" + jid, null, token);
returnArray = httpResponse.getJSONArray("return");
numMinionsDone = returnArray.getJSONObject(0).names().size();
if (numMinionsDone > oldMinionsDone && numMinionsDone < numMinions) {
// Some minions returned, but not all
// Give them minionTimeout to all return or fail build
try {
listener.getLogger().println(
"Some minions returned. Waiting " + minionTimeout + " seconds");
Thread.sleep(minionTimeout * 1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
// Allow user to cancel job in jenkins interface
listener.getLogger().println("Cancelling job");
return false;
}
httpResponse = Utils.getJSON(servername + "/jobs/" + jid, null, token);
returnArray = httpResponse.getJSONArray("return");
numMinionsDone = returnArray.getJSONObject(0).names().size();
if (numMinionsDone < numMinions) {
JSONArray respondedMinions = returnArray.getJSONObject(0).names();
listener.getLogger().println(
"Minions timed out. Failing\n\n");
// TODO only show minionsArray that aren't in respondedMinions
listener.getLogger().println("Responded: " + respondedMinions.toString());
listener.getLogger().println("Possible minions: " + minionsArray.toString());
jobSuccess = false;
break;
}
}
}
} else {
// Just send a salt request. Don't wait for reply
httpResponse = Utils.getJSON(myservername, saltArray, token);
returnArray = httpResponse.getJSONArray("return");
}
// Finished processing
LOGGER.log(Level.FINE, "Received response: " + returnArray);
// Save saltapi output to env if requested
if (saveEnvVar) {
build.addAction(new PublishEnvVarAction("SALTBUILDOUTPUT", returnArray.toString()));
}
// Check for error and print out results
boolean validFunctionExecution = Utils.validateFunctionCall(returnArray);
if (!validFunctionExecution) {
listener.getLogger()
.println("ERROR occurred!\nERROR: One or more minion did not return code 0\n\n");
jobSuccess = false;
}
// Print results
listener.getLogger().println("Response on " + myfunction + " " + myarguments + " for "
+ mytarget + ":");
if (myOutputFormat.equals("json")) {
listener.getLogger().println(returnArray.toString(2));
} else if (myOutputFormat.equals("yaml")) {
Object outputObject = returnArray.toArray();
Yaml yaml = new Yaml();
listener.getLogger().println(yaml.dump(outputObject));
} else {
listener.getLogger().println("Error: Unknown output Format: x" + myOutputFormat + "x");
jobSuccess = false;
}
// Results now printed. Return success condition
return jobSuccess;
}
private JSONArray createAuthArray(StandardUsernamePasswordCredentials credential) {
JSONArray authArray = new JSONArray();
JSONObject auth = new JSONObject();
auth.put("username", credential.getUsername());
auth.put("password", credential.getPassword().getPlainText());
auth.put("eauth", authtype);
authArray.add(auth);
return authArray;
}
private JSONObject prepareSaltFunction(AbstractBuild build, BuildListener listener, String myClientInterface,
String mytarget, String myfunction, String myarguments, String mykwarguments) {
JSONObject saltFunc = new JSONObject();
saltFunc.put("client", myClientInterface);
if (myClientInterface.equals("local_batch")) {
String mybatch = Utils.paramorize(build, listener, clientInterface.getBatchSize());
saltFunc.put("batch", mybatch);
listener.getLogger().println("Running in batch mode. Batch size: " + mybatch);
}
if (myClientInterface.equals("runner")) {
saltFunc.put("mods", clientInterface.getMods());
String myPillarvalue = Utils.paramorize(build, listener, clientInterface.getPillarValue());
JSONObject jPillar = new JSONObject();
// If value was already a jsonobject, treat it as such
JSON runPillarValue = JSONSerializer.toJSON(myPillarvalue);
saltFunc.put("pillar", runPillarValue);
}
saltFunc.put("tgt", mytarget);
saltFunc.put("expr_form", clientInterface.getTargetType());
saltFunc.put("fun", myfunction);
addArgumentsToSaltFunction(myarguments, saltFunc);
addKwArgumentsToSaltFunction(mykwarguments, saltFunc);
return saltFunc;
}
private void addKwArgumentsToSaltFunction(String mykwarguments, JSONObject saltFunc) {
if (mykwarguments.length() > 0) {
Map<String, String> kwArgs = new HashMap<String, String>();
// spit on comma seperated not inside of single and double quotes
String[] kwargItems = mykwarguments.split(",(?=(?:[^'\"]|'[^']*'|\"[^\"]*\")*$)");
for (String kwarg : kwargItems) {
// remove spaces at begining or end
kwarg = kwarg.replaceAll("^\\s+|\\s+$", "");
kwarg = kwarg.replaceAll("\"|\\\"", "");
if (kwarg.contains("=")) {
String[] kwString = kwarg.split("=");
if (kwString.length > 2) {
// kwarg contained more than one =. Let's put the string
// back together
String kwFull = new String();
for (String kwItem : kwString) {
// Ignore the first item as it will remain the key
if (kwItem == kwString[0]) {
continue;
}
// add the second item
if (kwItem == kwString[1]) {
kwFull += kwItem;
continue;
}
// add all other items with an = to rejoin
kwFull += "=" + kwItem;
}
kwArgs.put(kwString[0], kwFull);
} else {
kwArgs.put(kwString[0], kwString[1]);
}
}
}
// Add any kwargs to json message
saltFunc.element("kwarg", kwArgs);
}
}
private void addArgumentsToSaltFunction(String myarguments, JSONObject saltFunc) {
if (myarguments.length() > 0) {
List<String> saltArguments = new ArrayList<String>();
// spit on comma seperated not inside of single and double quotes
String[] argItems = myarguments.split(",(?=(?:[^'\"]|'[^']*'|\"[^\"]*\")*$)");
for (String arg : argItems) {
// remove spaces at begining or end
arg = arg.replaceAll("^\\s+|\\s+$", "");
// if string wrapped in quotes, remove them since adding to list
// re-quotes
arg = arg.replaceAll("(^')|(^\")|('$)|(\"$)", "");
saltArguments.add(arg);
}
// Add any args to json message
saltFunc.element("arg", saltArguments);
}
}
StandardUsernamePasswordCredentials getCredentialById(String credentialId) {
List<StandardUsernamePasswordCredentials> credentials = getCredentials(Jenkins.getInstance());
for (StandardUsernamePasswordCredentials credential : credentials) {
if (credential.getId().equals(credentialId)) {
return credential;
}
}
return null;
}
static List<StandardUsernamePasswordCredentials> getCredentials(Jenkins context) {
List<DomainRequirement> requirements = URIRequirementBuilder.create().build();
List<StandardUsernamePasswordCredentials> credentials = CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class, context, ACL.SYSTEM, requirements);
return credentials;
}
// Overridden for better type safety.
// If your plugin doesn't really define any property on Descriptor,
// you don't have to do this.
@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}
@Extension // This indicates to Jenkins that this is an implementation of an
// extension point.
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
private int pollTime = 10;
private int timeoutTime = 30;
private String outputFormat = "json";
public DescriptorImpl() {
load();
}
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
try {
// Test that value entered in config is an integer
pollTime = formData.getInt("pollTime");
timeoutTime = formData.getInt("timeoutTime");
} catch (Exception e) {
// Fall back to default
pollTime = 10;
timeoutTime = 30;
}
outputFormat = formData.getString("outputFormat");
save();
return super.configure(req, formData);
}
public int getPollTime() {
return pollTime;
}
public int getTimeoutTime() {
return timeoutTime;
}
public String getOutputFormat() {
return outputFormat;
}
public FormValidation doTestConnection(
@QueryParameter String servername,
@QueryParameter String credentialsId,
@QueryParameter String authtype) {
StandardUsernamePasswordCredentials usedCredential = null;
List<StandardUsernamePasswordCredentials> credentials = getCredentials(Jenkins.getInstance());
for (StandardUsernamePasswordCredentials credential : credentials) {
if (credential.getId().equals(credentialsId)) {
usedCredential = credential;
break;
}
}
if (usedCredential == null) {
return FormValidation.error("CredentialId error: no credential found with given ID.");
}
if (!servername.matches("\\{\\{\\w+\\}\\}")) {
JSONArray authArray = new JSONArray();
JSONObject auth = new JSONObject();
auth.put("username", usedCredential.getUsername());
auth.put("password", usedCredential.getPassword().getPlainText());
auth.put("eauth", authtype);
authArray.add(auth);
String token = Utils.getToken(servername, authArray);
if (token.contains("Error")) {
return FormValidation.error("Client error: " + token);
}
return FormValidation.ok("Success");
}
return FormValidation.warning("Cannot expand parametrized server name.");
}
public StandardListBoxModel doFillCredentialsIdItems(
@AncestorInPath Jenkins context,
@QueryParameter final String servername) {
StandardListBoxModel result = new StandardListBoxModel();
result.withEmptySelection();
result.withMatching(CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class),
getCredentials(context));
return result;
}
public FormValidation doCheckServername(@QueryParameter String value) {
if (!value.matches("\\{\\{\\w+\\}\\}")) {
if (value.length() == 0) {
return FormValidation.error("Please specify a name");
}
if (value.length() < 10) {
return FormValidation.warning("Isn't the name too short?");
}
if (!value.contains("https://") && !value.contains("http://")) {
return FormValidation
.warning("Missing protocol: Servername should be in the format https://host.domain:8000");
}
if (!value.substring(7).contains(":")) {
return FormValidation
.warning("Missing port: Servername should be in the format https://host.domain:8000");
}
return FormValidation.ok();
}
return FormValidation.warning("Cannot expand parametrized server name.");
}
public FormValidation doCheckCredentialsId(@AncestorInPath Item project, @QueryParameter String value) {
if (project == null || !project.hasPermission(Item.CONFIGURE)) {
return FormValidation.ok();
}
if (value == null) {
return FormValidation.ok();
}
StandardUsernamePasswordCredentials usedCredential = null;
List<StandardUsernamePasswordCredentials> credentials = getCredentials(Jenkins.getInstance());
for (StandardUsernamePasswordCredentials credential : credentials) {
if (credential.getId().equals(value)) {
usedCredential = credential;
}
}
if (usedCredential == null) {
return FormValidation.error("Cannot find any credentials with id " + value);
}
return FormValidation.ok();
}
public FormValidation doCheckTarget(@QueryParameter String value) {
return validateFormStringField(value, "Please specify a salt target", "Isn't it too short?");
}
public FormValidation doCheckFunction(@QueryParameter String value) {
return validateFormStringField(value, "Please specify a salt function", "Isn't it too short?");
}
private FormValidation validateFormStringField(String value, String lackOfFieldMessage,
String fieldToShortMessage) {
if (value.length() == 0) {
return FormValidation.error(lackOfFieldMessage);
}
if (value.length() < 3) {
return FormValidation.warning(fieldToShortMessage);
}
return FormValidation.ok();
}
public FormValidation doCheckPollTime(@QueryParameter String value) {
try {
Integer.parseInt(value);
} catch (NumberFormatException e) {
return FormValidation.error("Specify a number larger than 3");
}
if (Integer.parseInt(value) < 3) {
return FormValidation.warning("Specify a number larger than 3");
}
return FormValidation.ok();
}
public FormValidation doCheckTimeoutTime(@QueryParameter String value) {
try {
Integer.parseInt(value);
} catch (NumberFormatException e) {
return FormValidation.error("Specify a number larger than 3");
}
if (Integer.parseInt(value) < 3) {
return FormValidation.warning("Specify a number larger than 3");
}
return FormValidation.ok();
}
public FormValidation doCheckBatchSize(@QueryParameter String value) {
if (value.length() == 0) {
return FormValidation.error("Please specify batch size");
}
return FormValidation.ok();
}
public FormValidation doCheckPillarvalue(@QueryParameter String value) {
// Check to see if paramorized. Ex: {{variable}}
// This cannot be evaluated until build, so trust that all is well
Pattern pattern = Pattern.compile("\\{\\{\\w+\\}\\}");
Matcher matcher = pattern.matcher(value);
if (matcher.matches()) {
return FormValidation.ok();
}
try {
// If value was already a jsonobject, treat it as such
JSON runPillarValue = JSONSerializer.toJSON(value);
} catch (JSONException e) {
// Otherwise it must have been a string
return FormValidation.error("Pillar should be in JSON format");
}
return FormValidation.ok();
}
@Override
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
// Indicates that this builder can be used with all kinds of project
// types
return true;
}
/**
* This human readable name is used in the configuration screen.
*/
@Override
public String getDisplayName() {
return "Send a message to Salt API";
}
}
}