forked from zambien/go-apigee-edge
/
company_app_credential.go
128 lines (93 loc) · 3.8 KB
/
company_app_credential.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
package apigee
import (
"path"
)
// CompanyAppCredentialService is an interface for interfacing with the Apigee Edge Admin API
// dealing with companyApp credentials/keys.
type CompanyAppCredentialService interface {
Create(string, string, CompanyAppCredential) (*Credential, *Response, error)
Update(string, string, string, CompanyAppCredential) (*Credential, *Response, error)
Get(string, string, string) (*Credential, *Response, error)
Delete(string, string, string) (*Response, error)
RemoveApiProduct(string, string, string, string) (*Response, error)
}
type CompanyAppCredentialServiceOp struct {
client *EdgeClient
}
var _ CompanyAppCredentialService = &CompanyAppCredentialServiceOp{}
type CompanyAppCredential struct {
ConsumerKey string `json:"consumerKey,omitempty"`
ConsumerSecret string `json:"consumerSecret,omitempty"`
ApiProducts []string `json:"apiProducts,omitempty"`
ExpiresAt int `json:"expiresAt,omitempty"`
Attributes []Attribute `json:"attributes,omitempty"`
Scopes []string `json:"scopes,omitempty"`
}
// Create a company app's consumer key and secret
func (s *CompanyAppCredentialServiceOp) Create(companyName string, appName string, companyAppCredential CompanyAppCredential) (*Credential, *Response, error) {
uripath := path.Join("companies", companyName, "apps", appName, "keys", "create")
req, e := s.client.NewRequest("POST", uripath, companyAppCredential, "")
if e != nil {
return nil, nil, e
}
returnedCompanyAppCredentials := Credential{}
resp, e := s.client.Do(req, &returnedCompanyAppCredentials)
if e != nil {
return nil, resp, e
}
return &returnedCompanyAppCredentials, resp, e
}
// Update existing company app's consumer key with new API products or attributes
func (s *CompanyAppCredentialServiceOp) Update(companyName string, appName string, consumerKey string, companyAppCredential CompanyAppCredential) (*Credential, *Response, error) {
uripath := path.Join("companies", companyName, "apps", appName, "keys", consumerKey)
req, e := s.client.NewRequest("POST", uripath, companyAppCredential, "")
if e != nil {
return nil, nil, e
}
returnedCompanyAppCredentials := Credential{}
resp, e := s.client.Do(req, &returnedCompanyAppCredentials)
if e != nil {
return nil, resp, e
}
return &returnedCompanyAppCredentials, resp, e
}
// Get information about a company app's consumer key
func (s *CompanyAppCredentialServiceOp) Get(companyName string, appName string, consumerKey string) (*Credential, *Response, error) {
uripath := path.Join("companies", companyName, "apps", appName, "keys", consumerKey)
req, e := s.client.NewRequest("GET", uripath, nil, "")
if e != nil {
return nil, nil, e
}
returnedCompanyAppCredential := Credential{}
resp, e := s.client.Do(req, &returnedCompanyAppCredential)
if e != nil {
return nil, resp, e
}
return &returnedCompanyAppCredential, resp, e
}
// Delete a company app's consumer key
func (s *CompanyAppCredentialServiceOp) Delete(companyName string, appName string, consumerKey string) (*Response, error) {
uripath := path.Join("companies", companyName, "apps", appName, "keys", consumerKey)
req, e := s.client.NewRequest("DELETE", uripath, nil, "")
if e != nil {
return nil, e
}
resp, e := s.client.Do(req, nil)
if e != nil {
return resp, e
}
return resp, e
}
// Remove an API product from a company app's consumer key
func (s *CompanyAppCredentialServiceOp) RemoveApiProduct(companyName string, appName string, consumerKey string, apiProductName string) (*Response, error) {
uripath := path.Join("companies", companyName, "apps", appName, "keys", consumerKey, "apiproducts", apiProductName)
req, e := s.client.NewRequest("DELETE", uripath, nil, "")
if e != nil {
return nil, e
}
resp, e := s.client.Do(req, nil)
if e != nil {
return resp, e
}
return resp, e
}