35
35
import org .jenkinsci .Symbol ;
36
36
import org .kohsuke .stapler .DataBoundConstructor ;
37
37
import org .kohsuke .stapler .QueryParameter ;
38
+ import org .kohsuke .stapler .verb .POST ;
38
39
import org .kohsuke .stapler .StaplerRequest ;
39
40
import org .yaml .snakeyaml .Yaml ;
41
+ import org .yaml .snakeyaml .constructor .SafeConstructor ;
40
42
41
43
import java .io .IOException ;
42
44
import java .util .regex .Pattern ;
@@ -55,24 +57,18 @@ public class ValidatingYamlParameterDefinition extends ParameterDefinition{
55
57
56
58
private static final Logger LOGGER = Logger .getLogger (ValidatingYamlParameterDefinition .class .getName ());
57
59
private String defaultValue ;
58
- private boolean syntaxHighlighting ;
59
60
private String failedValidationMessage ;
60
61
private static boolean result ;
61
62
62
63
private String value ;
63
64
64
65
@ DataBoundConstructor
65
- public ValidatingYamlParameterDefinition (String name , String defaultValue , boolean syntaxHighlighting , String failedValidationMessage , String description ) {
66
+ public ValidatingYamlParameterDefinition (String name , String defaultValue , String failedValidationMessage , String description ) {
66
67
super (name , description );
67
68
this .defaultValue = defaultValue ;
68
- this .syntaxHighlighting = syntaxHighlighting ;
69
69
this .failedValidationMessage = failedValidationMessage ;
70
70
}
71
71
72
- public boolean getSyntaxHighlighting () {
73
- return this .syntaxHighlighting ;
74
- }
75
-
76
72
public String getDefaultValue () {
77
73
return this .defaultValue ;
78
74
}
@@ -97,14 +93,13 @@ public String getFailedValidationMessage() {
97
93
98
94
@ Override
99
95
public ValidatingYamlParameterValue getDefaultParameterValue () {
100
- // LOGGER.info(String.format(getName(), defaultValue, getSyntaxHighlighting()));
101
- ValidatingYamlParameterValue v = new ValidatingYamlParameterValue (getName (), defaultValue , getSyntaxHighlighting ());
96
+ ValidatingYamlParameterValue v = new ValidatingYamlParameterValue (getName (), defaultValue );
102
97
return v ;
103
98
}
104
99
105
100
private static ValidationResult doCheckYaml (String value ) {
106
101
ValidationResult vres = new ValidationResult ();
107
- Yaml yaml = new Yaml ();
102
+ Yaml yaml = new Yaml (new SafeConstructor () );
108
103
try {
109
104
yaml .load (value );
110
105
vres .setResult (true );
@@ -115,7 +110,7 @@ private static ValidationResult doCheckYaml(String value) {
115
110
return vres ;
116
111
}
117
112
118
- @ Extension
113
+ @ Extension @ Symbol ( "validatingYamlParameter" )
119
114
public static class DescriptorImpl extends ParameterDescriptor {
120
115
121
116
@ Override
@@ -126,6 +121,7 @@ public String getDisplayName() {
126
121
/**
127
122
* Check yaml syntax
128
123
*/
124
+ @ POST
129
125
public FormValidation doValidate (
130
126
@ QueryParameter ("value" ) final String value ,
131
127
@ QueryParameter ("failedValidationMessage" ) final String failedValidationMessage
@@ -153,8 +149,6 @@ public ParameterValue createValue(StaplerRequest req, JSONObject jo) {
153
149
throw new Failure ("Req: Invalid YAML syntax for parameter [" + getName () + "] specified: " + req_value );
154
150
}
155
151
156
- value .setSyntaxHighlighting (getSyntaxHighlighting ());
157
-
158
152
return value ;
159
153
}
160
154
@@ -169,7 +163,7 @@ public ParameterValue createValue(StaplerRequest req) {
169
163
if (!vres .result ) {
170
164
throw new Failure ("Req: Invalid value for parameter [" + getName () + "] specified: " + value [0 ]);
171
165
}
172
- return new ValidatingYamlParameterValue (getName (), value [0 ], getSyntaxHighlighting () );
166
+ return new ValidatingYamlParameterValue (getName (), value [0 ]);
173
167
}
174
168
}
175
169
@@ -182,15 +176,15 @@ public ParameterValue createValue(CLICommand command, String value) throws IOExc
182
176
if (!vres .result ) {
183
177
throw new AbortException ("Invalid value for parameter [" + getName () + "] specified: " + value );
184
178
}
185
- return new ValidatingYamlParameterValue (getName (), value , syntaxHighlighting , failedValidationMessage );
179
+ return new ValidatingYamlParameterValue (getName (), value , failedValidationMessage );
186
180
}
187
181
}
188
182
189
183
@ Override
190
184
public ParameterDefinition copyWithDefaultValue (ParameterValue defaultValue ) {
191
185
if (defaultValue instanceof ValidatingYamlParameterValue ) {
192
186
ValidatingYamlParameterValue value = (ValidatingYamlParameterValue ) defaultValue ;
193
- return new ValidatingYamlParameterDefinition (getName (), value .value , getSyntaxHighlighting (), getFailedValidationMessage (), getDescription ());
187
+ return new ValidatingYamlParameterDefinition (getName (), value .value , getFailedValidationMessage (), getDescription ());
194
188
} else {
195
189
return this ;
196
190
}
0 commit comments