Skip to content

Commit

Permalink
JENKINS-45964 : Assuming Role does not work in AWS-China
Browse files Browse the repository at this point in the history
- Added selecting resource partition based on currently active region in step.
  • Loading branch information
indyaah committed Aug 13, 2017
1 parent a075bf5 commit 6918461
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/de/taimos/pipeline/aws/WithAWSStep.java
Expand Up @@ -37,6 +37,7 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

import com.amazonaws.regions.Regions;
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient;
import com.amazonaws.services.securitytoken.model.AssumeRoleRequest;
import com.amazonaws.services.securitytoken.model.AssumeRoleResult;
Expand Down Expand Up @@ -202,7 +203,7 @@ private void withRole(@Nonnull EnvVars localEnv) {
accountId = sts.getCallerIdentity(new GetCallerIdentityRequest()).getAccount();
}

String roleARN = String.format("arn:aws:iam::%s:role/%s", accountId, this.step.getRole());
String roleARN = String.format("arn:%s:iam::%s:role/%s", selectPartitionName(), accountId, this.step.getRole());

AssumeRoleRequest request = new AssumeRoleRequest()
.withRoleArn(roleARN)
Expand Down Expand Up @@ -248,6 +249,13 @@ private String createRoleSessionName() {
.build();
}

private String selectPartitionName() {
if (Regions.CN_NORTH_1.getName().equals(this.step.getRegion())) {
return "aws-cn";
}
return "aws";
}

@Override
public void stop(@Nonnull Throwable throwable) throws Exception {
//
Expand Down

0 comments on commit 6918461

Please sign in to comment.