forked from aliyun/terraform-provider-alicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_alicloud_cr.go
193 lines (168 loc) · 5.12 KB
/
service_alicloud_cr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package alicloud
import (
"fmt"
"strings"
"github.com/aliyun/alibaba-cloud-sdk-go/services/cr"
"github.com/terraform-providers/terraform-provider-alicloud/alicloud/connectivity"
)
type CrService struct {
client *connectivity.AliyunClient
}
type crDefaultResponse struct {
RequestId string `json:"requestId"`
Data struct {
} `json:"data"`
}
type crCreateNamespaceRequestPayload struct {
Namespace struct {
Namespace string `json:"Namespace"`
} `json:"Namespace"`
}
type crUpdateNamespaceRequestPayload struct {
Namespace struct {
AutoCreate bool `json:"AutoCreate"`
DefaultVisibility string `json:"DefaultVisibility"`
} `json:"Namespace"`
}
type crDescribeNamespaceResponse struct {
RequestId string `json:"requestId"`
Data struct {
Namespace struct {
Namespace string `json:"namespace"`
AuthorizeType string `json:"authorizeType"`
DefaultVisibility string `json:"defaultVisibility"`
AutoCreate bool `json:"autoCreate"`
NamespaceStatus string `json:"namespaceStatus"`
} `json:"namespace"`
} `json:"data"`
}
type crDescribeNamespaceListResponse struct {
RequestId string `json:"requestId"`
Data struct {
Namespace []struct {
Namespace string `json:"namespace"`
AuthorizeType string `json:"authorizeType"`
NamespaceStatus string `json:"namespaceStatus"`
} `json:"namespaces"`
} `json:"data"`
}
const (
RepoTypePublic = "PUBLIC"
RepoTypePrivate = "PRIVATE"
)
type crCreateRepoRequestPayload struct {
Repo struct {
RepoNamespace string `json:"RepoNamespace"`
RepoName string `json:"RepoName"`
Summary string `json:"Summary"`
Detail string `json:"Detail"`
RepoType string `json:"RepoType"`
} `json:"Repo"`
}
type crUpdateRepoRequestPayload struct {
Repo struct {
Summary string `json:"Summary"`
Detail string `json:"Detail"`
RepoType string `json:"RepoType"`
} `json:"Repo"`
}
type crDescribeRepoResponse struct {
RequestId string `json:"requestId"`
Data struct {
Repo struct {
Summary string `json:"summary"`
Detail string `json:"detail"`
RepoNamespace string `json:"repoNamespace"`
RepoName string `json:"repoName"`
RepoType string `json:"repoType"`
RepoDomainList struct {
Public string `json:"public"`
Internal string `json:"internal"`
Vpc string `json:"vpc"`
}
} `json:"repo"`
} `json:"data"`
}
type crDescribeReposResponse struct {
RequestId string `json:"requestId"`
Data struct {
Repos []crRepo `json:"repos"`
Total int `json:"total"`
PageSize int `json:"pageSize"`
Page int `json:"page"`
} `json:"data"`
}
type crRepo struct {
Summary string `json:"summary"`
RepoNamespace string `json:"repoNamespace"`
RepoName string `json:"repoName"`
RepoType string `json:"repoType"`
RegionId string `json:"regionId"`
RepoDomainList struct {
Public string `json:"public"`
Internal string `json:"internal"`
Vpc string `json:"vpc"`
} `json:"repoDomainList"`
}
type crDescribeRepoTagsResponse struct {
RequestId string `json:"requestId"`
Data struct {
Tags []crTag `json:"tags"`
Total int `json:"total"`
PageSize int `json:"pageSize"`
Page int `json:"page"`
} `json:"data"`
}
type crTag struct {
ImageId string `json:"imageId"`
Digest string `json:"digest"`
Tag string `json:"tag"`
Status string `json:"status"`
ImageUpdate int `json:"imageUpdate"`
ImageCreate int `json:"imageCreate"`
ImageSize int `json:"imageSize"`
}
func (c *CrService) DescribeNamespace(namespaceName string) (*cr.GetNamespaceResponse, error) {
invoker := NewInvoker()
req := cr.CreateGetNamespaceRequest()
req.Namespace = namespaceName
var resp *cr.GetNamespaceResponse
if err := invoker.Run(func() error {
var err error
raw, err := c.client.WithCrClient(func(crClient *cr.Client) (interface{}, error) {
return crClient.GetNamespace(req)
})
resp, _ = raw.(*cr.GetNamespaceResponse)
return err
}); err != nil {
if IsExceptedError(err, ErrorNamespaceNotExist) {
return nil, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)
}
return nil, WrapErrorf(err, DefaultErrorMsg, namespaceName, req.GetActionName(), AlibabaCloudSdkGoERROR)
}
return resp, nil
}
func (c *CrService) DescribeRepo(repoPath string) (*cr.GetRepoResponse, error) {
invoker := NewInvoker()
sli := strings.Split(repoPath, SLASH_SEPARATED)
repoNamespace := sli[0]
repoName := sli[1]
req := cr.CreateGetRepoRequest()
req.RepoNamespace = repoNamespace
req.RepoName = repoName
var resp *cr.GetRepoResponse
if err := invoker.Run(func() error {
var err error
raw, err := c.client.WithCrClient(func(crClient *cr.Client) (interface{}, error) {
return crClient.GetRepo(req)
})
resp, _ = raw.(*cr.GetRepoResponse)
return err
}); err != nil {
if IsExceptedError(err, ErrorRepoNotExist) {
return nil, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)
}
return nil, WrapErrorf(err, DefaultErrorMsg, fmt.Sprintf("%s%s%s", repoNamespace, COLON_SEPARATED, repoName), req.GetActionName(), AlibabaCloudSdkGoERROR)
}
return resp, nil
}