Skip to content

Commit 5a9c2b8

Browse files
committed
- Removed the checkUrl from TokenCredentials jelly form and updated the pom file.
1 parent a996b00 commit 5a9c2b8

File tree

8 files changed

+87
-40
lines changed

8 files changed

+87
-40
lines changed

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<dependency>
6262
<groupId>io.jenkins.tools.bom</groupId>
6363
<artifactId>bom-${jenkins.baseline}.x</artifactId>
64-
<version>5750.vec44cb_c78352</version>
64+
<version>5774.v5c6d72f56a_61</version>
6565
<type>pom</type>
6666
<scope>import</scope>
6767
</dependency>
@@ -76,6 +76,11 @@
7676
<artifactId>credentials</artifactId>
7777
</dependency>
7878

79+
<dependency>
80+
<groupId>org.jenkins-ci.plugins</groupId>
81+
<artifactId>plain-credentials</artifactId>
82+
</dependency>
83+
7984
<!-- Pipeline Step API -->
8085
<dependency>
8186
<groupId>org.jenkins-ci.plugins.workflow</groupId>

src/main/java/io/jenkins/plugins/vigilnz/build/SecurityCheckBuilder.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.jenkins.plugins.vigilnz.build;
22

33
import com.cloudbees.plugins.credentials.CredentialsProvider;
4+
import com.fasterxml.jackson.core.JsonProcessingException;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
46
import hudson.EnvVars;
57
import hudson.Extension;
68
import hudson.Launcher;
@@ -12,8 +14,6 @@
1214
import hudson.tasks.Builder;
1315
import hudson.util.FormValidation;
1416
import hudson.util.ListBoxModel;
15-
import com.fasterxml.jackson.core.JsonProcessingException;
16-
import com.fasterxml.jackson.databind.ObjectMapper;
1717
import io.jenkins.cli.shaded.org.apache.commons.lang.StringUtils;
1818
import io.jenkins.plugins.vigilnz.api.ApiService;
1919
import io.jenkins.plugins.vigilnz.credentials.TokenCredentials;
@@ -142,9 +142,14 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
142142
String result = "";
143143

144144
try {
145+
145146
result = ApiService.triggerScan(tokenText, targetFile, scanTypes, env, listener);
146147
// Attach results to build
147-
build.addAction(new ScanResultAction(result));
148+
if (result != null && !result.isEmpty()) {
149+
build.addAction(new ScanResultAction(result));
150+
} else {
151+
listener.getLogger().println("API call failed, no action added.");
152+
}
148153
} catch (Exception e) {
149154
listener.error("Scan failed");
150155
attachResult(build, buildErrorResponse("Scan failed: " + e.getMessage()));
@@ -155,6 +160,24 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
155160
return true;
156161
}
157162

163+
private void attachResult(AbstractBuild build, String json) {
164+
try {
165+
build.addAction(new ScanResultAction(json));
166+
} catch (Exception ignored) {
167+
// Swallow to avoid masking original error
168+
}
169+
}
170+
171+
private String buildErrorResponse(String message) {
172+
ApiResponse resp = new ApiResponse();
173+
resp.setMessage(message);
174+
try {
175+
return new ObjectMapper().writeValueAsString(resp);
176+
} catch (JsonProcessingException e) {
177+
return "{\"message\":\"" + message.replace("\"", "\\\"") + "\"}";
178+
}
179+
}
180+
158181
@Extension
159182
public static class DescriptorImpl extends BuildStepDescriptor<Builder> {
160183

@@ -228,22 +251,4 @@ public FormValidation doCheckScanType(@AncestorInPath Item project, @QueryParame
228251
}
229252

230253
}
231-
232-
private void attachResult(AbstractBuild build, String json) {
233-
try {
234-
build.addAction(new ScanResultAction(json));
235-
} catch (Exception ignored) {
236-
// Swallow to avoid masking original error
237-
}
238-
}
239-
240-
private String buildErrorResponse(String message) {
241-
ApiResponse resp = new ApiResponse();
242-
resp.setMessage(message);
243-
try {
244-
return new ObjectMapper().writeValueAsString(resp);
245-
} catch (JsonProcessingException e) {
246-
return "{\"message\":\"" + message.replace("\"", "\\\"") + "\"}";
247-
}
248-
}
249254
}

src/main/java/io/jenkins/plugins/vigilnz/credentials/TokenCredentials.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
import com.cloudbees.plugins.credentials.CredentialsDescriptor;
44
import com.cloudbees.plugins.credentials.CredentialsScope;
55
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
6+
import edu.umd.cs.findbugs.annotations.NonNull;
67
import hudson.Extension;
78
import hudson.model.Item;
89
import hudson.util.FormValidation;
910
import hudson.util.Secret;
1011
import jenkins.model.Jenkins;
1112
import org.jenkinsci.Symbol;
13+
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
1214
import org.kohsuke.stapler.AncestorInPath;
1315
import org.kohsuke.stapler.DataBoundConstructor;
1416
import org.kohsuke.stapler.QueryParameter;
1517
import org.kohsuke.stapler.verb.POST;
1618

17-
public class TokenCredentials extends BaseStandardCredentials {
19+
public class TokenCredentials extends BaseStandardCredentials implements StringCredentials {
1820

1921
private final Secret token;
2022

@@ -40,6 +42,12 @@ public Secret getToken() {
4042
return token;
4143
}
4244

45+
@NonNull
46+
@Override
47+
public Secret getSecret() {
48+
return token;
49+
}
50+
4351

4452
// Descriptor for Jenkins UI
4553
@Symbol("vigilnzToken")

src/main/java/io/jenkins/plugins/vigilnz/pipeline/PipelineStep.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.kohsuke.stapler.DataBoundConstructor;
1111
import org.kohsuke.stapler.DataBoundSetter;
1212

13+
import java.util.Arrays;
1314
import java.util.List;
1415
import java.util.Set;
1516

@@ -22,9 +23,15 @@ public class PipelineStep extends Step {
2223
private String targetFile; // Optional parameter
2324

2425
@DataBoundConstructor
25-
public PipelineStep(String credentialsId, List<String> scanTypes) {
26+
public PipelineStep(String credentialsId, String scanTypes) {
2627
this.credentialsId = credentialsId;
27-
this.scanTypes = scanTypes != null ? scanTypes : List.of();
28+
29+
// Split comma-separated string into a list
30+
if (scanTypes != null && !scanTypes.trim().isEmpty()) {
31+
this.scanTypes = Arrays.asList(scanTypes.split("\\s*,\\s*"));
32+
} else {
33+
this.scanTypes = List.of();
34+
}
2835
}
2936

3037
public String getCredentialsId() {

src/main/java/io/jenkins/plugins/vigilnz/pipeline/PipelineStepExecution.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package io.jenkins.plugins.vigilnz.pipeline;
22

33
import com.cloudbees.plugins.credentials.CredentialsProvider;
4+
import com.fasterxml.jackson.core.JsonProcessingException;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
46
import hudson.AbortException;
57
import hudson.EnvVars;
68
import hudson.FilePath;
79
import hudson.model.Run;
810
import hudson.model.TaskListener;
9-
import com.fasterxml.jackson.core.JsonProcessingException;
10-
import com.fasterxml.jackson.databind.ObjectMapper;
1111
import io.jenkins.plugins.vigilnz.api.ApiService;
1212
import io.jenkins.plugins.vigilnz.credentials.TokenCredentials;
1313
import io.jenkins.plugins.vigilnz.models.ApiResponse;
@@ -126,7 +126,11 @@ public boolean start() throws Exception {
126126
String result;
127127
try {
128128
result = ApiService.triggerScan(token, step.getTargetFile(), scanTypes, env, listener);
129-
run.addAction(new ScanResultAction(result));
129+
if (result != null && !result.isEmpty()) {
130+
run.addAction(new ScanResultAction(result));
131+
} else {
132+
listener.getLogger().println("API call failed, no action added.");
133+
}
130134
} catch (Exception e) {
131135
listener.error("Scan failed");
132136
attachResult(run, buildErrorResponse("Scan failed: " + e.getMessage()));

src/main/resources/io/jenkins/plugins/vigilnz/credentials/TokenCredentials/config.jelly renamed to src/main/resources/io/jenkins/plugins/vigilnz/credentials/TokenCredentials/credentials.jelly

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
<?jelly escape-by-default='true'?>
2-
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
2+
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
33

44
<f:entry title="Token" field="token">
5-
<f:password checkUrl="${descriptor.checkToken}" clazz="passwordClass"/>
6-
<script>
7-
console.log("The script is calling")
8-
const element = document.querySelector(".passwordClass");
9-
element.addEventListener("blur", myFunction);
10-
function myFunction() {
11-
// Manually trigger the onchange event
12-
const event = new Event("change", { bubbles: true });
13-
element.dispatchEvent(event);
14-
}
15-
</script>
5+
<f:password clazz="passwordClass"/>
6+
<st:adjunct includes="js/token.js"/>
167
</f:entry>
178

189
<f:entry field="id" title="ID">
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div>
2+
<p>
3+
This step runs a Vigilnz security scan.
4+
</p>
5+
<p>
6+
Example usage:
7+
</p>
8+
<pre>
9+
vigilnzSecurityScan scanTypes: 'cve,sbom,sast'
10+
</pre>
11+
<p>
12+
<b>scanTypes:</b> Comma-separated list of scan types to run.
13+
</p>
14+
</div>

src/main/webapp/js/token.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
document.addEventListener("DOMContentLoaded", () => {
2+
console.log("The script is calling.")
3+
setTimeout(()=>{
4+
console.log("CHECKING Its coming or not 222 ")
5+
},1000)
6+
const element = document.querySelector(".passwordClass");
7+
if (element) {
8+
element.addEventListener("blur", () => {
9+
const event = new Event("change", { bubbles: true });
10+
element.dispatchEvent(event);
11+
});
12+
}
13+
});

0 commit comments

Comments
 (0)