forked from aliyun/terraform-provider-alicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_alicloud_cr.go
77 lines (66 loc) · 2.1 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
package alicloud
import (
"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:"namespace"`
} `json:"data"`
}
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 NotFoundError(err) || IsExceptedError(err, ErrorNamespaceNotExist) {
return nil, WrapErrorf(err, NotFoundMsg, AlibabaCloudSdkGoERROR)
}
return nil, WrapErrorf(err, DefaultErrorMsg, namespaceName, req.GetActionName(), AlibabaCloudSdkGoERROR)
}
return resp, nil
}