Skip to content

Commit

Permalink
jenkins review fix (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
souvik-karfa authored Aug 14, 2024
1 parent e2a2aa1 commit c189b2e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TraceableASTGenerateReportAction implements RunAction2 {
private Secret clientToken;
private String traceableRootCaFileName;
private String traceableCliCertFileName;
// lgtm[jenkins/plaintext-storage]
private String traceableCliKeyFileName;
private final FilePath workspace;
private final TaskListener listener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.Secret;
import io.jenkins.plugins.traceable.ast.scan.utils.ApiInspector;
import java.io.IOException;
import jenkins.tasks.SimpleBuildStep;
Expand All @@ -23,7 +24,7 @@ public class TraceableApiInspectorStepBuilder extends Builder implements SimpleB
private String repoPath;
private String specFilePath;
private String traceableServer;
private String traceableToken;
private static Secret traceableToken;
private StringBuilder report;

public String getRepoPath() {
Expand All @@ -38,7 +39,7 @@ public String getTraceableServer() {
return traceableServer;
}

public String getTraceableToken() {
public static Secret getTraceableToken() {
return traceableToken;
}

Expand All @@ -58,8 +59,8 @@ public void setTraceableServer(String traceableServer) {
}

@DataBoundSetter
public void setTraceableToken(String traceableToken) {
this.traceableToken = traceableToken;
public static void setTraceableToken(Secret traceableToken) {
TraceableApiInspectorStepBuilder.traceableToken = traceableToken;
}

@DataBoundConstructor
Expand All @@ -79,7 +80,8 @@ public void perform(Run<?, ?> run, FilePath workspace, EnvVars env, Launcher lau
if (StringUtils.isBlank(specFilePath)) {
findAndInspect(workspace, listener, repoWorkspacePath, scriptPath);
} else {
String[] args = new String[] {traceableServer, traceableToken, specFilePath};
String absoluteSpecFilePath = repoWorkspacePath + "/" + specFilePath;
String[] args = new String[] {traceableServer, traceableToken.getPlainText(), absoluteSpecFilePath};
report.append(runScript(workspace, listener, scriptPath, args, true));
}

Expand All @@ -101,7 +103,7 @@ private void findAndInspect(
}

for (String specFile : specFilePathsList) {
String[] args = new String[] {traceableServer, traceableToken, specFile};
String[] args = new String[] {traceableServer, traceableToken.getPlainText(), specFile};
String newOpenApiSpecString =
"========================================\nUploading open api spec : " + specFile + "\n";
listener.getLogger().println(newOpenApiSpecString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import hudson.FilePath.FileCallable;
import hudson.model.TaskListener;
import hudson.remoting.VirtualChannel;
import java.io.BufferedWriter;
Expand All @@ -17,9 +16,9 @@
import java.util.Objects;
import java.util.Scanner;
import java.util.UUID;
import org.jenkinsci.remoting.RoleChecker;
import jenkins.MasterToSlaveFileCallable;

public class ApiInspector implements FileCallable<String> {
public class ApiInspector extends MasterToSlaveFileCallable<String> {

private final TaskListener listener;
private final String scriptPath;
Expand All @@ -46,11 +45,6 @@ public String invoke(File f, VirtualChannel channel) throws IOException, Interru
return returnOutput.toString();
}

@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
return;
}

private void copyScript() throws IOException {

String bundledScript = CharStreams.toString(new InputStreamReader(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.jenkins.plugins.traceable.ast.scan.utils;

import hudson.FilePath.FileCallable;
import hudson.remoting.VirtualChannel;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
Expand All @@ -10,9 +9,9 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import org.jenkinsci.remoting.RoleChecker;
import jenkins.MasterToSlaveFileCallable;

public class DownloadTraceableCliBinary implements FileCallable<Void> {
public class DownloadTraceableCliBinary extends MasterToSlaveFileCallable<Void> {

private String workspacePath;
private String version;
Expand Down Expand Up @@ -50,12 +49,6 @@ public Void invoke(File f, VirtualChannel channel) throws IOException, Interrupt
return null;
}

@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
// We want this to be able to run on any type of machine (controller or agent)
return;
}

private String getKernelName() throws IOException, InterruptedException {
String[] command = {"uname", "-s"};
ProcessBuilder pb = new ProcessBuilder(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import hudson.FilePath.FileCallable;
import hudson.remoting.VirtualChannel;
import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -17,9 +16,9 @@
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jenkinsci.remoting.RoleChecker;
import jenkins.MasterToSlaveFileCallable;

public class GenerateReport implements FileCallable<String[]> {
public class GenerateReport extends MasterToSlaveFileCallable<String[]> {

private final String scriptPath;
private String[] args;
Expand Down Expand Up @@ -47,11 +46,6 @@ public String[] invoke(File f, VirtualChannel channel) throws IOException, Inter
return ret;
}

@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
return;
}

private void copyScript() throws IOException {

String bundledScript = CharStreams.toString(new InputStreamReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import hudson.FilePath.FileCallable;
import hudson.model.TaskListener;
import hudson.remoting.VirtualChannel;
import java.io.BufferedWriter;
Expand All @@ -17,10 +16,10 @@
import java.util.Objects;
import java.util.Scanner;
import java.util.UUID;
import jenkins.MasterToSlaveFileCallable;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.remoting.RoleChecker;

public class RunScript implements FileCallable<String> {
public class RunScript extends MasterToSlaveFileCallable<String> {

private final TaskListener listener;
private final String scriptPath;
Expand All @@ -46,12 +45,6 @@ public String invoke(File f, VirtualChannel channel) throws IOException, Interru
return RunScript.scanId;
}

@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
// We want this to be able to run on any type of machine (controller or agent)
return;
}

private void copyScript() throws IOException {

String bundledScript = CharStreams.toString(new InputStreamReader(
Expand Down

0 comments on commit c189b2e

Please sign in to comment.