Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from jenkinsci/JENKINS-34762-GHissue-352
Fix for empty parameters in SECURITY-170 updates
- Loading branch information
Showing
4 changed files
with
116 additions
and
81 deletions.
There are no files selected for viewing
78 changes: 0 additions & 78 deletions
78
...main/java/org/jenkinsci/plugins/ghprb/GhprbAdditionalParameterEnvironmentContributor.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
src/main/java/org/jenkinsci/plugins/ghprb/GhprbParametersAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.jenkinsci.plugins.ghprb; | ||
|
||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
import hudson.model.EnvironmentContributor; | ||
import hudson.model.ParameterValue; | ||
import hudson.model.ParametersAction; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
|
||
@Restricted(NoExternalUse.class) | ||
public class GhprbParametersAction extends ParametersAction { | ||
|
||
private List<ParameterValue> parameters; | ||
|
||
public GhprbParametersAction(List<ParameterValue> parameters) { | ||
this.parameters = parameters; | ||
} | ||
|
||
public GhprbParametersAction(ParameterValue... parameters) { | ||
this(Arrays.asList(parameters)); | ||
} | ||
|
||
@Override | ||
public List<ParameterValue> getParameters() { | ||
return Collections.unmodifiableList(parameters); | ||
} | ||
|
||
@Override | ||
public ParameterValue getParameter(String name) { | ||
for (ParameterValue parameter : parameters) { | ||
if (parameter != null && parameter.getName().equals(name)) { | ||
return parameter; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Extension | ||
public static final class GhprbAdditionalParameterEnvironmentContributor extends EnvironmentContributor { | ||
|
||
// See SECURITY-170 | ||
|
||
@Override | ||
@SuppressWarnings("rawtypes") | ||
public void buildEnvironmentFor(@Nonnull Run run, | ||
@Nonnull EnvVars envs, | ||
@Nonnull TaskListener listener) throws IOException, InterruptedException { | ||
|
||
GhprbParametersAction gpa = run.getAction(GhprbParametersAction.class); | ||
if (gpa != null) { | ||
for (ParameterValue p : gpa.getParameters()) { | ||
envs.put(p.getName(), String.valueOf(p.getValue())); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters