1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package br.com.ingenieux.mojo.beanstalk.bundle;
18
19 import com.amazonaws.auth.AWSCredentialsProvider;
20
21 import org.apache.commons.codec.binary.Hex;
22 import org.apache.commons.codec.digest.DigestUtils;
23
24 import java.util.Date;
25
26 public class CodeCommitRequestSigner extends RequestSignerBase {
27 final String repoName;
28
29 public CodeCommitRequestSigner(AWSCredentialsProvider credentialsProvider, String repoName, Date date) {
30 super(credentialsProvider.getCredentials(), "us-east-1", "codecommit", date);
31 this.repoName = repoName;
32 }
33
34 public String getPushUrl() {
35 String user = awsCredentials.getAWSAccessKeyId();
36
37 String host = "git-codecommit.us-east-1.amazonaws.com";
38
39 String path = "/v1/repos/" + repoName;
40
41 String scope = String.format("%s/%s/%s/%s", strDate, region, service, TERMINATOR);
42
43 StringBuilder stringToSign = new StringBuilder();
44
45 stringToSign.append(String.format("%s-%s\n%s\n%s\n", SCHEME, AWS_ALGORITHM, strDateTime, scope));
46
47 stringToSign.append(DigestUtils.sha256Hex(String.format("GIT\n%s\n\nhost:%s\n\nhost\n", path, host).getBytes()));
48
49 byte[] key = deriveKey();
50
51 byte[] digest = hash(key, stringToSign.toString());
52
53 String signature = Hex.encodeHexString(digest);
54
55 String password = strDateTime.concat("Z").concat(signature);
56
57 String returnUrl = String.format("https://%s:%s@%s%s", user, password, host, path);
58
59 return returnUrl;
60 }
61 }