本文整理汇总了Java中com.cloudbees.plugins.credentials.common.StandardCertificateCredentials类的典型用法代码示例。如果您正苦于以下问题:Java StandardCertificateCredentials类的具体用法?Java StandardCertificateCredentials怎么用?Java StandardCertificateCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardCertificateCredentials类属于com.cloudbees.plugins.credentials.common包,在下文中一共展示了StandardCertificateCredentials类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractFromCertificate
import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials; //导入依赖的package包/类
/**
* Extract the private key a client certificate from a X509 certificate and write them to disk.
*
* @param certificatCredential Jenkins certificateCredential
* @param clientCrtFile path where to write of the certificate
* @param clientKeyFile path where to write of the private key
* @throws IOException lol
* @throws InterruptedException on file operation
*/
public static void extractFromCertificate(StandardCertificateCredentials certificatCredential,
FilePath clientCrtFile,
FilePath clientKeyFile) throws IOException, InterruptedException {
try {
KeyStore keyStore = certificatCredential.getKeyStore();
String alias = keyStore.aliases().nextElement();
X509Certificate certificate = (X509Certificate) keyStore.getCertificate(alias);
// Get private key using passphrase
Key key = keyStore.getKey(alias, Secret.toString(certificatCredential.getPassword()).toCharArray());
// Write certificate
String encodedClientCrt = wrapCertificate(Base64.encodeBase64String(certificate.getEncoded()));
clientCrtFile.write(encodedClientCrt, null);
// Write private key
String encodedClientKey = wrapPrivateKey(Base64.encodeBase64String(key.getEncoded()));
clientKeyFile.write(encodedClientKey, null);
} catch (KeyStoreException | UnrecoverableKeyException | NoSuchAlgorithmException | CertificateEncodingException e) {
throw new AbortException(e.getMessage());
}
}
示例2: doFillCredentialsIdItems
import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials; //导入依赖的package包/类
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String serverUrl) {
return new StandardListBoxModel()
.withEmptySelection()
.withMatching(
CredentialsMatchers.anyOf(
CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class),
CredentialsMatchers.instanceOf(TokenProducer.class),
CredentialsMatchers.instanceOf(StandardCertificateCredentials.class)
),
CredentialsProvider.lookupCredentials(
StandardCredentials.class,
item,
null,
URIRequirementBuilder.fromUri(serverUrl).build()
)
);
}
示例3: doFillCredentialsIdItems
import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials; //导入依赖的package包/类
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl) {
return new StandardListBoxModel().withEmptySelection() //
.withMatching( //
CredentialsMatchers.anyOf(
CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class),
CredentialsMatchers.instanceOf(TokenProducer.class),
CredentialsMatchers.instanceOf(
org.jenkinsci.plugins.kubernetes.credentials.TokenProducer.class),
CredentialsMatchers.instanceOf(StandardCertificateCredentials.class),
CredentialsMatchers.instanceOf(StringCredentials.class)), //
CredentialsProvider.lookupCredentials(StandardCredentials.class, //
Jenkins.getInstance(), //
ACL.SYSTEM, //
serverUrl != null ? URIRequirementBuilder.fromUri(serverUrl).build()
: Collections.EMPTY_LIST //
));
}
示例4: basicsPipeline
import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials; //导入依赖的package包/类
@Test
public void basicsPipeline() throws Exception {
// create the Credentials
String alias = "androiddebugkey";
String password = "android";
StandardCertificateCredentials c = new CertificateCredentialsImpl(CredentialsScope.GLOBAL, "my-certificate", alias,
password, new CertificateCredentialsImpl.FileOnMasterKeyStoreSource(certificate.getAbsolutePath()));
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
// create the Pipeline job
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
String pipelineScript = IOUtils.toString(getTestResourceInputStream("basicsPipeline-Jenkinsfile"));
p.setDefinition(new CpsFlowDefinition(pipelineScript, true));
// copy resources into workspace
FilePath workspace = r.jenkins.getWorkspaceFor(p);
copyTestResourceIntoWorkspace(workspace, "basicsPipeline-step1.bat", 0755);
copyTestResourceIntoWorkspace(workspace, "basicsPipeline-step2.bat", 0755);
copyTestResourceIntoWorkspace(workspace, "basicsPipeline-step1.sh", 0755);
copyTestResourceIntoWorkspace(workspace, "basicsPipeline-step2.sh", 0755);
// execute the pipeline
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
r.waitForCompletion(b);
r.assertBuildStatusSuccess(b);
}
示例5: setCredentials
import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials; //导入依赖的package包/类
/**
* Set the user section of the kube configuration file.
*
* @throws IOException on file operations
* @throws InterruptedException on file operations
*/
private void setCredentials(String configFile) throws IOException, InterruptedException {
Set<String> tempFiles = newHashSet();
final StandardCredentials credentials = getCredentials(build);
String credentialsArgs;
int sensitiveFieldsCount = 1;
if (credentials == null) {
throw new AbortException("No credentials defined to setup Kubernetes CLI");
} else if (credentials instanceof TokenProducer) {
credentialsArgs = "--token=\"" + ((TokenProducer) credentials).getToken(serverUrl, null, true) + "\"";
} else if (credentials instanceof StringCredentials) {
credentialsArgs = "--token=\"" + ((StringCredentials) credentials).getSecret() + "\"";
} else if (credentials instanceof UsernamePasswordCredentials) {
UsernamePasswordCredentials upc = (UsernamePasswordCredentials) credentials;
credentialsArgs = "--username=\"" + upc.getUsername() + "\" --password=\"" + Secret.toString(upc.getPassword()) + "\"";
} else if (credentials instanceof StandardCertificateCredentials) {
sensitiveFieldsCount = 0;
FilePath clientCrtFile = workspace.createTempFile("client", "crt");
FilePath clientKeyFile = workspace.createTempFile("client", "key");
CertificateHelper.extractFromCertificate((StandardCertificateCredentials) credentials, clientCrtFile, clientKeyFile);
tempFiles.add(clientCrtFile.getRemote());
tempFiles.add(clientKeyFile.getRemote());
credentialsArgs = "--embed-certs=true --client-certificate=" + clientCrtFile.getRemote() + " --client-key="
+ clientKeyFile.getRemote();
} else {
throw new AbortException("Unsupported Credentials type " + credentials.getClass().getName());
}
String[] cmds = QuotedStringTokenizer.tokenize(String.format("%s config set-credentials %s %s",
KUBECTL_BINARY,
USERNAME,
credentialsArgs));
int status = launcher.launch()
.envs(String.format("KUBECONFIG=%s", configFile))
.cmds(cmds)
.masks(getMasks(cmds.length, sensitiveFieldsCount))
.stdout(launcher.getListener())
.join();
if (status != 0) throw new IOException("Failed to add kubectl credentials (exit code " + status + ")");
for (String tempFile : tempFiles) {
workspace.child(tempFile).delete();
}
}
示例6: type
import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials; //导入依赖的package包/类
@Override
protected Class<StandardCertificateCredentials> type() {
return StandardCertificateCredentials.class;
}
示例7: basics
import com.cloudbees.plugins.credentials.common.StandardCertificateCredentials; //导入依赖的package包/类
@Test
public void basics() throws Exception {
String alias = "androiddebugkey";
String password = "android";
StandardCertificateCredentials c = new CertificateCredentialsImpl(CredentialsScope.GLOBAL, null, alias,
password, new CertificateCredentialsImpl.FileOnMasterKeyStoreSource(certificate.getAbsolutePath()));
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
FreeStyleProject p = r.createFreeStyleProject();
CertificateMultiBinding binding = new CertificateMultiBinding("keystore", c.getId());
binding.setAliasVariable("alias");
binding.setPasswordVariable("password");
p.getBuildWrappersList().add(new SecretBuildWrapper(Collections
.<MultiBinding<?>> singletonList(binding)));
if (Functions.isWindows()) {
p.getBuildersList().add(new BatchFile(
"echo | set /p=\"%alias%/%password%/\" > secrets.txt\r\n"
+ "IF EXIST %keystore% (\r\n"
+ "echo | set /p=\"exists\" >> secrets.txt\r\n"
+ ") ELSE (\r\n"
+ "echo | set /p=\"missing\" >> secrets.txt\r\n"
+ ")\r\n"
+ "exit 0"));
} else {
p.getBuildersList().add(new Shell(
"printf $alias/$password/ > secrets.txt\n"
+ "if [ -f \"$keystore\" ]\n"
+ "then\n"
+ "printf exists >> secrets.txt\n"
+ "else\n"
+ "printf missing >> secrets.txt\n"
+ "fi"));
}
r.configRoundtrip((Item) p);
SecretBuildWrapper wrapper = p.getBuildWrappersList().get(SecretBuildWrapper.class);
assertNotNull(wrapper);
List<? extends MultiBinding<?>> bindings = wrapper.getBindings();
assertEquals(1, bindings.size());
MultiBinding<?> testBinding = bindings.get(0);
assertEquals(c.getId(), testBinding.getCredentialsId());
assertEquals(CertificateMultiBinding.class, testBinding.getClass());
assertEquals("password", ((CertificateMultiBinding) testBinding).getPasswordVariable());
assertEquals("alias", ((CertificateMultiBinding) testBinding).getAliasVariable());
assertEquals("keystore", ((CertificateMultiBinding) testBinding).getKeystoreVariable());
FreeStyleBuild b = r.buildAndAssertSuccess(p);
r.assertLogNotContains(password, b);
assertEquals(alias + '/' + password + "/exists", b.getWorkspace().child("secrets.txt").readToString().trim());
assertThat(b.getSensitiveBuildVariables(), containsInAnyOrder("keystore", "password", "alias"));
}