use of com.cloudbees.plugins.credentials.domains.Domain in project blueocean-plugin by jenkinsci.
the class GitPipelineCreateRequest method create.
@Override
public BluePipeline create(Reachable parent) throws IOException {
User authenticatedUser = User.current();
if (authenticatedUser == null) {
throw new ServiceException.UnauthorizedException("Must login to create a pipeline");
}
String sourceUri = scmConfig.getUri();
if (sourceUri == null) {
throw new ServiceException.BadRequestExpception(new ErrorMessage(400, "Failed to create Git pipeline:" + getName()).add(new ErrorMessage.Error("scmConfig.uri", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "uri is required")));
}
TopLevelItem item = create(Jenkins.getInstance(), getName(), MODE, MultiBranchProjectDescriptor.class);
if (item instanceof WorkflowMultiBranchProject) {
WorkflowMultiBranchProject project = (WorkflowMultiBranchProject) item;
if (StringUtils.isNotBlank(scmConfig.getCredentialId())) {
Domain domain = CredentialsUtils.findDomain(scmConfig.getCredentialId(), authenticatedUser);
if (domain == null) {
throw new ServiceException.BadRequestExpception(new ErrorMessage(400, "Failed to create pipeline").add(new ErrorMessage.Error("scm.credentialId", ErrorMessage.Error.ErrorCodes.INVALID.toString(), "No domain in user credentials found for credentialId: " + scmConfig.getCredentialId())));
}
if (domain.test(new BlueOceanDomainRequirement())) {
//this is blueocean specific domain
project.addProperty(new BlueOceanCredentialsProvider.FolderPropertyImpl(authenticatedUser.getId(), scmConfig.getCredentialId(), BlueOceanCredentialsProvider.createDomain(sourceUri)));
}
}
String credentialId = StringUtils.defaultString(scmConfig.getCredentialId());
project.getSourcesList().add(new BranchSource(new GitSCMSource(null, sourceUri, credentialId, "*", "", false)));
project.scheduleBuild(new Cause.UserIdCause());
return new MultiBranchPipelineImpl(project);
} else {
try {
// we don't know about this project type
item.delete();
} catch (InterruptedException e) {
throw new ServiceException.UnexpectedErrorException("Failed to delete pipeline: " + getName());
}
}
return null;
}
use of com.cloudbees.plugins.credentials.domains.Domain in project configuration-as-code-plugin by jenkinsci.
the class CredentialsRootConfigurator method configure.
@Override
public CredentialsStore configure(Object config) throws Exception {
Map map = (Map) config;
final Map<?, ?> system = (Map) map.get("system");
final Map<Domain, List<Credentials>> target = SystemCredentialsProvider.getInstance().getDomainCredentialsMap();
target.clear();
final Configurator<Domain> domainConfigurator = Configurator.lookup(Domain.class);
final Configurator<Credentials> credentialsConfigurator = Configurator.lookup(Credentials.class);
for (Map.Entry dc : system.entrySet()) {
final Domain domain = domainConfigurator.configure(dc.getKey());
List values = (List) dc.getValue();
final List<Credentials> credentials = new ArrayList<>();
for (Object value : values) {
credentials.add(credentialsConfigurator.configure(value));
}
logger.info("Setting " + target.getClass().getCanonicalName() + "#system[" + domain.toString() + "] = " + credentials);
target.put(domain, credentials);
}
return null;
}
use of com.cloudbees.plugins.credentials.domains.Domain in project blueocean-plugin by jenkinsci.
the class UserSSHKeyManager method getDomain.
private static Domain getDomain(CredentialsStore store) {
Domain domain = store.getDomainByName(BLUEOCEAN_DOMAIN_NAME);
if (domain == null) {
try {
// create new one
boolean result = store.addDomain(new Domain(BLUEOCEAN_DOMAIN_NAME, null, null));
if (!result) {
throw new ServiceException.UnexpectedErrorException(String.format("Failed to create credential domain: %s", BLUEOCEAN_DOMAIN_NAME));
}
domain = store.getDomainByName(BLUEOCEAN_DOMAIN_NAME);
if (domain == null) {
throw new ServiceException.UnexpectedErrorException(String.format("Domain %s created but not found", BLUEOCEAN_DOMAIN_NAME));
}
} catch (IOException ex) {
throw new ServiceException.UnexpectedErrorException("Failed to save the Blue Ocean domain.", ex);
}
}
return domain;
}
use of com.cloudbees.plugins.credentials.domains.Domain in project blueocean-plugin by jenkinsci.
the class BitbucketServerScmContentProviderTest method mockMbp.
private MultiBranchProject mockMbp(String credentialId, User user) {
MultiBranchProject mbp = mock(MultiBranchProject.class);
when(mbp.getName()).thenReturn("pipeline1");
when(mbp.getParent()).thenReturn(j.jenkins);
BitbucketSCMSource scmSource = mock(BitbucketSCMSource.class);
when(scmSource.getServerUrl()).thenReturn(apiUrl);
when(scmSource.getCredentialsId()).thenReturn(credentialId);
when(scmSource.getRepoOwner()).thenReturn("TESTP");
when(scmSource.getRepository()).thenReturn("pipeline-demo-test");
when(mbp.getSCMSources()).thenReturn(Collections.singletonList(scmSource));
// mock blueocean credential provider stuff
BlueOceanCredentialsProvider.FolderPropertyImpl folderProperty = mock(BlueOceanCredentialsProvider.FolderPropertyImpl.class);
DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties = new DescribableList<>(mbp);
properties.add(new BlueOceanCredentialsProvider.FolderPropertyImpl(user.getId(), credentialId, BlueOceanCredentialsProvider.createDomain(apiUrl)));
Domain domain = mock(Domain.class);
when(domain.getName()).thenReturn(BitbucketServerScm.DOMAIN_NAME);
when(folderProperty.getDomain()).thenReturn(domain);
when(mbp.getProperties()).thenReturn(properties);
return mbp;
}
use of com.cloudbees.plugins.credentials.domains.Domain in project blueocean-plugin by jenkinsci.
the class BitbucketCloudScmContentProviderTest method mockMbp.
private MultiBranchProject mockMbp(String credentialId, User user) {
MultiBranchProject mbp = mock(MultiBranchProject.class);
when(mbp.getName()).thenReturn("pipeline1");
when(mbp.getParent()).thenReturn(j.jenkins);
BitbucketSCMSource scmSource = mock(BitbucketSCMSource.class);
when(scmSource.getServerUrl()).thenReturn(apiUrl);
when(scmSource.getCredentialsId()).thenReturn(credentialId);
when(scmSource.getRepoOwner()).thenReturn(USER_UUID);
when(scmSource.getRepository()).thenReturn("demo1");
when(mbp.getSCMSources()).thenReturn(Collections.singletonList(scmSource));
// mock blueocean credential provider stuff
BlueOceanCredentialsProvider.FolderPropertyImpl folderProperty = mock(BlueOceanCredentialsProvider.FolderPropertyImpl.class);
DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties = new DescribableList<>(mbp);
properties.add(new BlueOceanCredentialsProvider.FolderPropertyImpl(user.getId(), credentialId, BlueOceanCredentialsProvider.createDomain(apiUrl)));
Domain domain = mock(Domain.class);
when(domain.getName()).thenReturn(BitbucketCloudScm.DOMAIN_NAME);
when(folderProperty.getDomain()).thenReturn(domain);
when(mbp.getProperties()).thenReturn(properties);
return mbp;
}
Aggregations