| 1 | package cs |
| 2 | |
| 3 | import ( |
| 4 | "net/http" |
| 5 | ) |
| 6 | |
| 7 | const ( |
| 8 | CRDefaultEndpoint = "https://cr.cn-hangzhou.aliyuncs.com" |
| 9 | CRAPIVersion = "2016-06-07" |
| 10 | ) |
| 11 | |
| 12 | func NewCRClientWithSecurityToken(region, accessKeyId, accessKeySecret, securityToken string) *Client { |
| 13 | return &Client{ |
| 14 | AccessKeyId: accessKeyId, |
| 15 | AccessKeySecret: accessKeySecret, |
| 16 | SecurityToken: securityToken, |
| 17 | endpoint: "https://cr." + region + ".aliyuncs.com", |
| 18 | Version: CRAPIVersion, |
| 19 | httpClient: &http.Client{}, |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | type CRAuthorizationToken struct { |
| 24 | Data struct { |
| 25 | AuthorizationToken string `json:"authorizationToken"` |
| 26 | TempUserName string `json:"tempUserName"` |
| 27 | ExpireDate int64 `json:"expireDate"` |
| 28 | } `json:"data"` |
| 29 | RequestId string `json:"requestId"` |
| 30 | } |
| 31 | |
| 32 | func (client *Client) GetCRAuthorizationToken() (crtoken CRAuthorizationToken, err error) { |
| 33 | err = client.Invoke("", http.MethodGet, "/tokens", nil, nil, &crtoken) |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | func (client *Client) GetCRRepoInfo(repoNamespace, repoName string) (str string, err error) { |
| 38 | err = client.Invoke("", http.MethodGet, "/repos/"+repoNamespace+"/"+repoName, nil, nil, &str) |
| 39 | return |
| 40 | } |