-
Notifications
You must be signed in to change notification settings - Fork 75
/
SSHAgentStep.java
112 lines (94 loc) · 3.52 KB
/
SSHAgentStep.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
package com.cloudbees.jenkins.plugins.sshagent;
import com.cloudbees.jenkins.plugins.sshcredentials.SSHAuthenticator;
import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import hudson.Extension;
import hudson.model.Item;
import hudson.model.Queue;
import hudson.model.queue.Tasks;
import hudson.security.ACL;
import hudson.security.AccessControlled;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
public class SSHAgentStep extends AbstractStepImpl implements Serializable {
private static final long serialVersionUID = 1L;
/**
* The {@link com.cloudbees.plugins.credentials.common.StandardUsernameCredentials#getId()}s of the credentials
* to use.
*/
private final List<String> credentials;
/**
* If a credentials is missed, the SSH Agent is launched anyway.
* By the fault is false. Initialized in the constructor.
*/
private boolean ignoreMissing;
/**
* Default parameterized constructor.
*
* @param credentials
*/
@DataBoundConstructor
public SSHAgentStep(final List<String> credentials) {
this.credentials = credentials;
this.ignoreMissing = false;
}
@Extension
public static final class DescriptorImpl extends AbstractStepDescriptorImpl {
public DescriptorImpl() {
super(SSHAgentStepExecution.class);
}
@Override
public String getFunctionName() {
return "sshagent";
}
@Override
public String getDisplayName() {
return Messages.SSHAgentBuildWrapper_DisplayName();
}
@Override
public boolean takesImplicitBlockArgument() {
return true;
}
/**
* Populate the list of credentials available to the job.
*
* @return the list box model.
*/
@SuppressWarnings("unused") // used by stapler
public ListBoxModel doFillCredentialsItems(@AncestorInPath Item item) {
AccessControlled contextToCheck = item == null ? Jenkins.get() : item;
if (!contextToCheck.hasPermission(CredentialsProvider.VIEW)) {
return new StandardUsernameListBoxModel();
}
return new StandardUsernameListBoxModel()
.includeMatchingAs(
item instanceof Queue.Task ? Tasks.getAuthenticationOf((Queue.Task)item) : ACL.SYSTEM,
item,
SSHUserPrivateKey.class,
Collections.<DomainRequirement>emptyList(),
SSHAuthenticator.matcher()
);
}
}
@DataBoundSetter
public void setIgnoreMissing(final boolean ignoreMissing) {
this.ignoreMissing = ignoreMissing;
}
public boolean isIgnoreMissing() {
return ignoreMissing;
}
public List<String> getCredentials() {
return credentials;
}
}