Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/jenkins 42120 git creation credential changes #895

Merged
merged 40 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1c2e937
JENKINS-41397# validate git credential
Jan 25, 2017
0b207f7
Field specific error message
Jan 27, 2017
f029779
Merge remote-tracking branch 'origin/master' into task/JENKINS-41397
Jan 31, 2017
b0fb5dc
bug fixes
Jan 31, 2017
8dc82e1
credential validation is now 400 errors.
Jan 31, 2017
19d8621
Merge remote-tracking branch 'origin/master' into task/JENKINS-41397
Feb 14, 2017
718b731
Merge remote-tracking branch 'origin/master' into task/JENKINS-41397
Feb 14, 2017
6c11a94
[JENKINS-42120] fix a bug where some content from the FlowSteps (inac…
Mar 2, 2017
82821ab
[JENKINS-42120] rework Git creation flow to use modal for creating ne…
Mar 2, 2017
23d5978
Merge branch 'master' into task/JENKINS-42120-git-creation-credential…
Mar 6, 2017
954a68e
[JENKINS-42120] remove "System SSH" as an option
Mar 6, 2017
236b875
[JENKINS-42120] width of username / password inputs
Mar 6, 2017
8e9304b
[JENKINS-42120] remove obsolete code for credential type in "Connect"…
Mar 6, 2017
485d986
Merge branch 'task/JENKINS-41397' into task/JENKINS-42120-git-creatio…
Mar 6, 2017
830a0fb
[JENKINS-42120] add a step to Git creation flow that can display unha…
Mar 6, 2017
867f127
[JENKINS-42120] reworking Git creation to support different validatio…
Mar 6, 2017
9e9f778
[JENKINS-42120] fix bug where credentialId was not sent correctly; ad…
Mar 6, 2017
e852705
Merge remote-tracking branch 'origin/master' into task/JENKINS-41397
Mar 7, 2017
43bbde0
Use StandardCredentials in case of git.
Mar 7, 2017
699e1e8
List all credentials that user has access to.
Mar 7, 2017
eac6262
Merge branch 'task/JENKINS-41397' into task/JENKINS-42120-git-creatio…
Mar 8, 2017
3b49071
[JENKINS-42120] fix a ridiculous bug where credentials were being cre…
Mar 8, 2017
ada0ffd
[JENKINS-42120] add an API to remove all steps after the specified step
Mar 9, 2017
e0aad62
[JENKINS-42120] transform Git TransportException "authentication is r…
Mar 9, 2017
dae30b2
[JENKINS-42120] improve the error handling for Git creation, respondi…
Mar 9, 2017
f608ec8
[JENKINS-42120] delint
Mar 9, 2017
594b8a2
[JENKINS-42120] fix broken test
Mar 9, 2017
a8ceb12
Frogot to remove StandardCredentials.
vivek Mar 10, 2017
c8a986c
Merge branch 'task/JENKINS-41397' into task/JENKINS-42120-git-creatio…
Mar 10, 2017
393a791
[JENKINS-42120] use beta JDL with dropdown fixes and enhancements; re…
Mar 13, 2017
8614e64
[JENKINS-42120] fix a bug where selecting a credential would not allo…
Mar 13, 2017
9b95dde
[JENKINS-42120] adjust backend to transform the SSH "connection is no…
Mar 13, 2017
c7250b2
[JENKINS-42120] italicize the special "none" credential
Mar 14, 2017
3da646d
[JENKINS-42120] change Git creation UI to expose "System Default" opt…
Mar 15, 2017
fe568b1
[JENKINS-42120] use JDL that includes useful Dropdown fixes but inclu…
Mar 15, 2017
dfdb8fc
Merge branch 'master' into task/JENKINS-42120-git-creation-credential…
Mar 16, 2017
66ff520
release core-js 0.0.89
Mar 16, 2017
e606c7f
bump core-js version to 0.0.90-SNAPSHOT
Mar 16, 2017
b59388c
[JENKINS-42120] use latest JDL (and core-js, since we have to)
Mar 16, 2017
988d4d0
Merge branch 'master' into task/JENKINS-42120-git-creation-credential…
Mar 16, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/master' into task/JENKINS-41397
  • Loading branch information
Vivek Pandey authored and Vivek Pandey committed Feb 14, 2017
commit 19d862165d78c028bd2866712a285bf600790330
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.jenkins.blueocean.blueocean_git_pipeline;

import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.domains.Domain;
import hudson.model.Cause;
import hudson.model.Failure;
import hudson.model.TopLevelItem;
Expand Down Expand Up @@ -55,13 +56,34 @@ public BluePipeline create(Reachable parent) throws IOException {

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;

//XXX: set credentialId to empty string if null or we get NPE later on
String credentialId = scmConfig.getCredentialId() == null ? "" : scmConfig.getCredentialId();
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
import com.cloudbees.plugins.credentials.domains.Domain;
import com.google.common.collect.ImmutableMap;
import com.mashape.unirest.http.exceptions.UnirestException;
import hudson.ExtensionList;
import hudson.model.Item;
import hudson.model.User;
import io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest;
import io.jenkins.blueocean.rest.model.scm.GitSampleRepoRule;
import jenkins.branch.MultiBranchProject;
Expand Down Expand Up @@ -114,9 +116,8 @@ public void shouldGetBadRequestForBadGitUriOnCreate() throws IOException {


@Test
public void shouldGetForbiddenForBadCredentialIdOnUpdate1() throws IOException {

String mbp = createMbp();
public void shouldGetForbiddenForBadCredentialIdOnUpdate1() throws IOException, UnirestException {
String mbp = createMbp(login());


SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
Expand Down Expand Up @@ -151,9 +152,8 @@ public void shouldGetForbiddenForBadCredentialIdOnUpdate1() throws IOException {


@Test
public void shouldGetForbiddenForBadCredentialIdOnUpdate2() throws IOException {

String mbp = createMbp();
public void shouldGetForbiddenForBadCredentialIdOnUpdate2() throws IOException, UnirestException {
String mbp = createMbp(login());
SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
CredentialsStore systemStore = system.getStore(j.getInstance());
systemStore.addDomain(new Domain("domain1", null, null));
Expand Down Expand Up @@ -183,27 +183,34 @@ public void shouldGetForbiddenForBadCredentialIdOnUpdate2() throws IOException {
}

@Test
public void shouldGetBadRequestForBadGitUriOnUpdate() throws IOException {
public void shouldGetBadRequestForBadGitUriOnUpdate() throws IOException, UnirestException {
User user = login();
String mbp = createMbp(user);

String mbp = createMbp();
put("/organizations/jenkins/pipelines/"+mbp+"/",
ImmutableMap.of("name", mbp,
new RequestBuilder(baseUrl)
.status(400)
.jwtToken(getJwtToken(j.jenkins,user.getId(), user.getId()))
.put("/organizations/jenkins/pipelines/" + mbp + "/")
.data(ImmutableMap.of("name", mbp,
"$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineUpdateRequest",
"scmConfig", ImmutableMap.of("uri", "/sdsd/sdsd/sdsd")
), 400);

))
.build(Map.class);
}


@Test
public void shouldCreateGitMbp(){

Map<String,Object> resp = post("/organizations/jenkins/pipelines/",
ImmutableMap.of("name", "demo",
"$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest",
"scmConfig", ImmutableMap.of("uri", sampleRepo.fileUrl())
), 201);

public void shouldCreateGitMbp() throws IOException, UnirestException {
login();
Map resp = new RequestBuilder(baseUrl)
.status(201)
.jwtToken(getJwtToken(j.jenkins,"bob", "bob"))
.post("/organizations/jenkins/pipelines/")
.data(ImmutableMap.of("name", "demo",
"$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest",
"scmConfig", ImmutableMap.of("uri", sampleRepo.fileUrl())
))
.build(Map.class);

assertEquals("demo", resp.get("name"));
}
Expand Down Expand Up @@ -242,9 +249,13 @@ public void shouldFailOnValidation2(){
}

@Test
public void shouldFailOnValidation3(){
Map<String,Object> resp = post("/organizations/jenkins/pipelines/",
ImmutableMap.of("name", "demo",
public void shouldFailOnValidation3() throws IOException, UnirestException {
login();
Map resp = new RequestBuilder(baseUrl)
.status(400)
.jwtToken(getJwtToken(j.jenkins,"bob", "bob"))
.post("/organizations/jenkins/pipelines/")
.data(ImmutableMap.of("name", "demo",
"$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest",
"scmConfig", ImmutableMap.of()))
.build(Map.class);
Expand All @@ -261,7 +272,8 @@ public void shouldFailOnValidation3(){


@Test
public void shouldFailOnValidation4(){
public void shouldFailOnValidation4() throws IOException, UnirestException {
login();

Map resp = new RequestBuilder(baseUrl)
.status(201)
Expand All @@ -282,8 +294,8 @@ public void shouldFailOnValidation4(){
.post("/organizations/jenkins/pipelines/")
.data(ImmutableMap.of("name", "demo",
"$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest",
"scmConfig", ImmutableMap.of("uri", sampleRepo.fileUrl(), "credentialId", "sdsdsd")
), 400);
"scmConfig", ImmutableMap.of("uri", sampleRepo.fileUrl(),
"credentialId", "sdsdsd"))).build(Map.class);
List<Map<String,String>> errors = (List<Map<String,String>>) resp.get("errors");

boolean nameFound = false;
Expand Down Expand Up @@ -316,13 +328,14 @@ public void shouldFailOnValidation5(){
assertNull(Jenkins.getInstance().getItem("demo"));
}

private String createMbp(){
Map<String,Object> resp = post("/organizations/jenkins/pipelines/",
ImmutableMap.of("name", "demo",
private String createMbp(User user) throws UnirestException {
Map<String,Object> resp = new RequestBuilder(baseUrl)
.status(201)
.jwtToken(getJwtToken(j.jenkins,user.getId(), user.getId()))
.post("/organizations/jenkins/pipelines/")
.data(ImmutableMap.of("name", "demo",
"$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest",
"scmConfig", ImmutableMap.of("uri", sampleRepo.fileUrl())
), 201);

"scmConfig", ImmutableMap.of("uri", sampleRepo.fileUrl()))).build(Map.class);

assertEquals("demo", resp.get("name"));
Item item = Jenkins.getInstance().getItem("demo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ static void validateCredentialId(String credentialId, AbstractFolder item) throw
try {
item.delete();
} catch (InterruptedException e) {
throw new ServiceException.UnexpectedErrorException("No Credentials instance found for credentialId: " + credentialId + ". Failure during cleaing up folder: " + item.getName() + ". Error: " + e.getMessage(), e);
throw new ServiceException.UnexpectedErrorException("Invalid credentialId: " +
credentialId + ". Failure during cleaning up folder: " + item.getName() + ". Error: " +
e.getMessage(), e);
}
throw new ServiceException.BadRequestExpception(new ErrorMessage(400, "Failed to create Git pipeline")
.add(new ErrorMessage.Error("credentialId", ErrorMessage.Error.ErrorCodes.NOT_FOUND.toString(), "No Credentials instance found for credentialId: "+credentialId)));

.add(new ErrorMessage.Error("credentialId",
ErrorMessage.Error.ErrorCodes.NOT_FOUND.toString(),
"No Credentials instance found for credentialId: "+credentialId)));
}
}
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.