本文整理汇总了Java中com.cloudbees.plugins.credentials.domains.Domain类的典型用法代码示例。如果您正苦于以下问题:Java Domain类的具体用法?Java Domain怎么用?Java Domain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Domain类属于com.cloudbees.plugins.credentials.domains包,在下文中一共展示了Domain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBasicWithCa
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test
public void testBasicWithCa() throws Exception {
String encodedCertificate = new String(Base64.getEncoder().encode(CA_CERTIFICATE.getBytes()));
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredential());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testBasicWithCa");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("kubectl configuration cleaned up", b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("certificate-authority-data: " + encodedCertificate));
assertTrue(configDumpContent.contains("server: " + SERVER_URL));
}
示例2: testBasicWithoutCa
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test
public void testBasicWithoutCa() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredential());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testBasicWithoutCa");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithoutCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("kubectl configuration cleaned up", b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("insecure-skip-tls-verify: true"));
assertTrue(configDumpContent.contains("server: " + SERVER_URL));
}
示例3: testUsernamePasswordCredentials
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test
public void testUsernamePasswordCredentials() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredentialWithSpace());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testUsernamePasswordCredentials");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithoutCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains(PASSWORD_WITH_SPACE, b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("username: " + USERNAME_WITH_SPACE));
assertTrue(configDumpContent.contains("password: " + PASSWORD_WITH_SPACE));
}
示例4: testSecretCredentials
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test
public void testSecretCredentials() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), secretCredentialWithSpace());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testSecretCredentials");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithoutCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains(PASSWORD_WITH_SPACE, b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("token: " + PASSWORD_WITH_SPACE));
}
示例5: testRecorderInvalidToken
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
/**
* Test that a JSON credential without a "jenkins_token" field and without a proper DC/OS service account value
* results in a 401 and only 1 web request.
*
* @throws Exception
*/
@Test
public void testRecorderInvalidToken() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject();
final SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
final CredentialsStore systemStore = system.getStore(j.getInstance());
final String credentialValue = "{\"field1\":\"some value\"}";
final Secret secret = Secret.fromString(credentialValue);
final StringCredentials credential = new StringCredentialsImpl(CredentialsScope.GLOBAL, "invalidtoken", "a token for JSON token test", secret);
TestUtils.enqueueFailureResponse(httpServer, 401);
systemStore.addCredentials(Domain.global(), credential);
addBuilders(TestUtils.loadFixture("idonly.json"), project);
// add post-builder
addPostBuilders(project, "invalidtoken");
final FreeStyleBuild build = j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get());
j.assertLogContains("[Marathon] Authentication to Marathon instance failed:", build);
j.assertLogContains("[Marathon] Invalid DC/OS service account JSON", build);
assertEquals("Only 1 request should have been made.", 1, httpServer.getRequestCount());
}
示例6: checkForDuplicates
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@CheckForNull
private static FormValidation checkForDuplicates(String value, ModelObject context, ModelObject object) {
for (CredentialsStore store : CredentialsProvider.lookupStores(object)) {
if (!store.hasPermission(CredentialsProvider.VIEW)) {
continue;
}
ModelObject storeContext = store.getContext();
for (Domain domain : store.getDomains()) {
if (CredentialsMatchers.firstOrNull(store.getCredentials(domain), CredentialsMatchers.withId(value))
!= null) {
if (storeContext == context) {
return FormValidation.error("This ID is already in use");
} else {
return FormValidation.warning("The ID ‘%s’ is already in use in %s", value,
storeContext instanceof Item
? ((Item) storeContext).getFullDisplayName()
: storeContext.getDisplayName());
}
}
}
}
return null;
}
示例7: configRoundTrip
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test public void configRoundTrip() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
IdCredentials registryCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "registryCreds", null, "me", "pass");
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), registryCredentials);
StepConfigTester sct = new StepConfigTester(story.j);
Map<String,Object> registryConfig = new TreeMap<String,Object>();
registryConfig.put("url", "https://docker.my.com/");
registryConfig.put("credentialsId", registryCredentials.getId());
Map<String,Object> config = Collections.<String,Object>singletonMap("registry", registryConfig);
RegistryEndpointStep step = DescribableHelper.instantiate(RegistryEndpointStep.class, config);
step = sct.configRoundTrip(step);
DockerRegistryEndpoint registry = step.getRegistry();
assertNotNull(registry);
assertEquals("https://docker.my.com/", registry.getUrl());
assertEquals(registryCredentials.getId(), registry.getCredentialsId());
assertEquals(config, DescribableHelper.uninstantiate(step));
}
});
}
示例8: configRoundTrip
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test public void configRoundTrip() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
IdCredentials serverCredentials = new DockerServerCredentials(CredentialsScope.GLOBAL, "serverCreds", null, "clientKey", "clientCertificate", "serverCaCertificate");
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), serverCredentials);
StepConfigTester sct = new StepConfigTester(story.j);
Map<String,Object> serverConfig = new TreeMap<String,Object>();
serverConfig.put("uri", "tcp://host:2375");
serverConfig.put("credentialsId", serverCredentials.getId());
Map<String,Object> config = Collections.<String,Object>singletonMap("server", serverConfig);
ServerEndpointStep step = DescribableHelper.instantiate(ServerEndpointStep.class, config);
step = sct.configRoundTrip(step);
DockerServerEndpoint server = step.getServer();
assertNotNull(server);
assertEquals("tcp://host:2375", server.getUri());
assertEquals(serverCredentials.getId(), server.getCredentialsId());
assertEquals(config, DescribableHelper.uninstantiate(step));
}
});
}
示例9: configRoundTrip
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test
public void configRoundTrip() throws Exception {
story.addStep(new Statement() {
@SuppressWarnings("rawtypes")
@Override
public void evaluate() throws Throwable {
CredentialsStore store = CredentialsProvider.lookupStores(story.j.getInstance()).iterator().next();
assertThat(store, instanceOf(SystemCredentialsProvider.StoreImpl.class));
Domain domain = new Domain("docker", "A domain for docker credentials",
Collections.<DomainSpecification> singletonList(new DockerServerDomainSpecification()));
DockerServerCredentials c = new DockerServerCredentials(CredentialsScope.GLOBAL,
"docker-client-cert", "desc", "clientKey", "clientCertificate", "serverCaCertificate");
store.addDomain(domain, c);
BindingStep s = new StepConfigTester(story.j)
.configRoundTrip(new BindingStep(Collections.<MultiBinding> singletonList(
new DockerServerCredentialsBinding("DOCKER_CERT_PATH", "docker-client-cert"))));
story.j.assertEqualDataBoundBeans(s.getBindings(), Collections.singletonList(
new DockerServerCredentialsBinding("DOCKER_CERT_PATH", "docker-client-cert")));
}
});
}
示例10: createCredentials
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
private static String createCredentials(String serverAPIUrl, StandardCredentials credentials) throws Exception {
List<DomainSpecification> specifications = new ArrayList<DomainSpecification>(2);
URI serverUri = new URI(serverAPIUrl);
if (serverUri.getPort() > 0) {
specifications.add(new HostnamePortSpecification(serverUri.getHost() + ":" + serverUri.getPort(), null));
} else {
specifications.add(new HostnameSpecification(serverUri.getHost(), null));
}
specifications.add(new SchemeSpecification(serverUri.getScheme()));
String path = serverUri.getPath();
if (StringUtils.isEmpty(path)) {
path = "/";
}
specifications.add(new PathSpecification(path, null, false));
Domain domain = new Domain(serverUri.getHost(), "Auto generated credentials domain", specifications);
CredentialsStore provider = new SystemCredentialsProvider.StoreImpl();
provider.addDomain(domain, credentials);
return credentials.getId();
}
示例11: migrate
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Initializer(after = InitMilestone.PLUGINS_STARTED)
public static void migrate() throws IOException {
GitLabConnectionConfig descriptor = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class);
for (GitLabConnection connection : descriptor.getConnections()) {
if (connection.apiTokenId == null && connection.apiToken != null) {
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
List<Domain> domains = credentialsStore.getDomains();
connection.apiTokenId = UUID.randomUUID().toString();
credentialsStore.addCredentials(domains.get(0),
new GitLabApiTokenImpl(CredentialsScope.SYSTEM, connection.apiTokenId, "GitLab API Token", Secret.fromString(connection.apiToken)));
}
}
}
}
descriptor.save();
}
示例12: testMultiBranchClassicWithCredentialsInFolder
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test
public void testMultiBranchClassicWithCredentialsInFolder() throws Exception {
WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "multi-classic-creds-in-folder");
CredentialsStore folderStore = getFolderStore(multi);
P4BaseCredentials inFolderCredentials = new P4PasswordImpl(
CredentialsScope.GLOBAL, "idInFolder", "desc:passwd", p4d.getRshPort(),
null, "jenkins", "0", "0", null, "jenkins");
folderStore.addCredentials(Domain.global(), inFolderCredentials);
String format = "jenkins-${NODE_NAME}-${JOB_NAME}";
String includes = "//stream/...";
SCMSource source = new BranchesScmSource(inFolderCredentials.getId(), includes, null, format);
multi.getSourcesList().add(new BranchSource(source));
multi.scheduleBuild2(0);
jenkins.waitUntilNoActivity();
assertEquals("Branch Indexing succeeded", Result.SUCCESS, multi.getComputation().getResult());
assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder()));
}
示例13: testMultiBranchStreamWithCredentialsInFolder
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test
public void testMultiBranchStreamWithCredentialsInFolder() throws Exception {
WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "multi-streams-creds-in-folder");
CredentialsStore folderStore = getFolderStore(multi);
P4BaseCredentials inFolderCredentials = new P4PasswordImpl(
CredentialsScope.GLOBAL, "idInFolder", "desc:passwd", p4d.getRshPort(),
null, "jenkins", "0", "0", null, "jenkins");
folderStore.addCredentials(Domain.global(), inFolderCredentials);
String format = "jenkins-${NODE_NAME}-${JOB_NAME}";
String includes = "//stream/...";
SCMSource source = new StreamsScmSource(inFolderCredentials.getId(), includes, null, format);
multi.getSourcesList().add(new BranchSource(source));
multi.scheduleBuild2(0);
jenkins.waitUntilNoActivity();
assertEquals("Branch Indexing succeeded", Result.SUCCESS, multi.getComputation().getResult());
assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder()));
}
示例14: testPerformWrongCredentials
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的package包/类
@Test
public void testPerformWrongCredentials() throws Exception {
FreeStyleProject project = j.createFreeStyleProject();
project.setScm(new ExtractResourceSCM(getClass().getResource("hello-java.zip")));
CredentialsStore store = CredentialsProvider.lookupStores(j.getInstance()).iterator().next();
store.addCredentials(Domain.global(),
new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "wrongCredentialsId", "",
"wrongName", "wrongPass"));
CloudFoundryPushPublisher cf = new CloudFoundryPushPublisher(TEST_TARGET, TEST_ORG, TEST_SPACE,
"wrongCredentialsId", false, false, 0, null, ManifestChoice.defaultManifestFileConfig());
project.getPublishersList().add(cf);
FreeStyleBuild build = project.scheduleBuild2(0).get();
System.out.println(build.getDisplayName() + " completed");
String s = FileUtils.readFileToString(build.getLogFile());
System.out.println(s);
assertTrue("Build succeeded where it should have failed", build.getResult().isWorseOrEqualTo(Result.FAILURE));
assertTrue("Build did not write error message", s.contains("ERROR: Wrong username or password"));
}
示例15: basicsPipeline
import com.cloudbees.plugins.credentials.domains.Domain; //导入依赖的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);
}