全部产品
阿里云办公

创建证书

更新时间:2018-06-20 18:41:54

描述

说明:在Codepipeline中创建用户证书。

请求信息

请求行 RequestLine

  1. POST /credential/create HTTP/1.1

请求行参数 URI Param

名称 类型 是否必须 描述
CredentialType String 证书类型
JsonContent String 证书内容

返回信息

返回行 ResponseLine

  1. HTTP/1.1 200 OK

返回码 HTTP Status Code

Status Code 描述
204 No Content
401 Authentication failed
403 The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource, or may need an account of some sort.
500 Internal Error

返回体 ResponseBody

  1. {
  2. "RequestId": "string"
  3. }

返回体解释

证书类型及内容说明

1. 用户名和密码 类型证书

示例:
CredentialType:UsernamePasswordCredentials
JsonContent:

  1. {
  2. "credentials": {
  3. "password": "demo-password",
  4. "description": "a demo username password credential",
  5. "id": "demo-id",
  6. "username": "demo-username"
  7. }
  8. }

JsonContent中各个字段的说明:

字段 是否必填 错误异常
credentials args credentials required
username args username required
password args password required
id args id required
description 否,如果为空则默认使用id的值设置

Java 代码示例:

  1. Map outerMap = new HashMap();
  2. Map innerMap = new HashMap();
  3. innerMap.put("username", "demo-username");
  4. innerMap.put("password", "demo-password");
  5. innerMap.put("id", "demo-id");
  6. innerMap.put("description", "a demo username password credential");
  7. outerMap.put("credentials",innerMap);
  8. String jsonStr = JSON.toJSONString(outerMap);
  9. CreateCredentialRequest createCredentialRequest = new CreateCredentialRequest();
  10. try {
  11. createCredentialRequest.setAcceptFormat(FormatType.JSON);
  12. createCredentialRequest.setCredentialType("UsernamePasswordCredentials");
  13. createCredentialRequest.setJsonContent(jsonStr);
  14. CreateCredentialResponse createCredentialResponse = client.getAcsResponse(createCredentialRequest);
  15. System.out.println(createCredentialResponse.getRequestId());
  16. } catch (Exception e) {
  17. e.printStackTrace();;
  18. }

2. registry授权 类型证书

示例:
CredentialType:DockerRegistryCredentials
JsonContent:

  1. {
  2. "credentials": {
  3. "password": "demo-registry-password",
  4. "description": "a demo registry credential",
  5. "id": "demo-registry-id",
  6. "email": "demo-registry-email",
  7. "username": "demo-registry-username"
  8. }
  9. }

JsonContent中各个字段的说明:

字段 是否必填 错误异常
credentials args credentials required
username args username required
password args password required
id args id required
email
description 否,如果为空则默认使用id的值设置

Java 代码示例:

  1. Map outerMap = new HashMap();
  2. Map innerMap = new HashMap();
  3. innerMap.put("username", "demo-registry-username");
  4. innerMap.put("password", "demo-registry-password");
  5. innerMap.put("email", "demo-registry-email");
  6. innerMap.put("id", "demo-registry-id");
  7. innerMap.put("description", "a demo registry credential");
  8. outerMap.put("credentials",innerMap);
  9. String jsonStr = JSON.toJSONString(outerMap);
  10. CreateCredentialRequest createCredentialRequest = new CreateCredentialRequest();
  11. try {
  12. createCredentialRequest.setAcceptFormat(FormatType.JSON);
  13. createCredentialRequest.setCredentialType("DockerRegistryCredentials");
  14. createCredentialRequest.setJsonContent(jsonStr);
  15. CreateCredentialResponse createCredentialResponse = client.getAcsResponse(createCredentialRequest);
  16. System.out.println(createCredentialResponse.getRequestId());
  17. } catch (Exception e) {
  18. e.printStackTrace();;
  19. }

3. Docker授权 类型证书

示例:
CredentialType:DockerServerCredentials
JsonContent:

  1. {
  2. "credentials": {
  3. "clientCertificate": "demo-docker-clientCertificateContent",
  4. "clientKey": "demo-docker-clientKeyContent",
  5. "serverCaCertificate": "demo-docker-serverCaCertificateContent",
  6. "description": "a demo docker credential",
  7. "id": "demo-docker-id"
  8. }
  9. }

JsonContent中各个字段的说明:

字段 是否必填 错误异常
credentials args credentials required
clientKey args clientKey required
clientCertificate args clientCertificate required
serverCaCertificate args serverCaCertificate required
id args id required
description 否,如果为空则默认使用id的值设置

Java 代码示例:

  1. Map outerMap = new HashMap();
  2. Map innerMap = new HashMap();
  3. innerMap.put("clientKey", "demo-docker-clientKeyContent");
  4. innerMap.put("clientCertificate", "demo-docker-clientCertificateContent");
  5. innerMap.put("serverCaCertificate", "demo-docker-serverCaCertificateContent");
  6. innerMap.put("id", "demo-docker-id");
  7. innerMap.put("description", "a demo docker credential");
  8. outerMap.put("credentials",innerMap);
  9. String jsonStr = JSON.toJSONString(outerMap);
  10. CreateCredentialRequest createCredentialRequest = new CreateCredentialRequest();
  11. try {
  12. createCredentialRequest.setAcceptFormat(FormatType.JSON);
  13. createCredentialRequest.setCredentialType("DockerServerCredentials");
  14. createCredentialRequest.setJsonContent(jsonStr);
  15. CreateCredentialResponse createCredentialResponse = client.getAcsResponse(createCredentialRequest);
  16. System.out.println(createCredentialResponse.getRequestId());
  17. } catch (Exception e) {
  18. e.printStackTrace();;
  19. }

4. SSH用户名和私钥 类型证书

示例:
CredentialType:SSHCredentials
JsonContent:

  1. {
  2. "credentials": {
  3. "privateKeySource": {
  4. "privateKey": "demo-ssh-privateKeyContent"
  5. },
  6. "description": "a demo ssh credential",
  7. "passphrase": "demo-ssh-passphrase",
  8. "id": "demo-ssh-id",
  9. "username": "demo-ssh-username"
  10. }
  11. }

JsonContent中各个字段的说明:

字段 是否必填 错误异常
credentials args credentials required
privateKey args privateKey required
username 否,默认为jetty
passphrase
id args id required
privateKeySource args privateKeySource required
description 否,如果为空则默认使用id的值设置

Java 代码示例:

  1. Map outerMap = new HashMap();
  2. Map midMap = new HashMap();
  3. Map innerMap = new HashMap();
  4. innerMap.put("privateKey", "demo-ssh-privateKeyContent");
  5. midMap.put("username", "demo-ssh-username");
  6. midMap.put("passphrase", "demo-ssh-passphrase");
  7. midMap.put("id", "demo-ssh-id");
  8. midMap.put("description", "a demo ssh credential");
  9. midMap.put("privateKeySource", innerMap);
  10. outerMap.put("credentials",midMap);
  11. String jsonStr = JSON.toJSONString(outerMap);
  12. CreateCredentialRequest createCredentialRequest = new CreateCredentialRequest();
  13. try {
  14. createCredentialRequest.setAcceptFormat(FormatType.JSON);
  15. createCredentialRequest.setCredentialType("SSHCredentials");
  16. createCredentialRequest.setJsonContent(jsonStr);
  17. CreateCredentialResponse createCredentialResponse = client.getAcsResponse(createCredentialRequest);
  18. System.out.println(createCredentialResponse.getRequestId());
  19. } catch (Exception e) {
  20. e.printStackTrace();;
  21. }