forked from DinoChiesa/go-apigee-edge
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathKeyValueMapEntry.go
107 lines (78 loc) · 3.24 KB
/
KeyValueMapEntry.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
package apigee
import "path"
// KeyValueMapEntryService is an interface for interfacing with the Apigee Edge Admin API
// dealing with KeyValueMapEntry.
type KeyValueMapEntryService interface {
Get(string, string, string) (*KeyValueMapEntry, *Response, error)
Create(string, KeyValueMapEntryKeys, string) (*KeyValueMapEntry, *Response, error)
Delete(string, string, string) (*Response, error)
Update(string, KeyValueMapEntryKeys, string) (*KeyValueMapEntry, *Response, error)
}
// KeyValueMapEntryServiceOp holds creds
type KeyValueMapEntryServiceOp struct {
client *EdgeClient
}
var _ KeyValueMapEntryService = &KeyValueMapEntryServiceOp{}
// KeyValueMapEntryKeys to update
type KeyValueMapEntryKeys struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
}
// KeyValueMapEntry Holds the Key value map
type KeyValueMapEntry struct {
KVMName string `json:"kvmName,omitempty"`
Entry []KeyValueMapEntryKeys `json:"entry,omitempty"`
}
// Get the key value map entry
func (s *KeyValueMapEntryServiceOp) Get(keyValueMapName string, env string, keyValueMapEntry string) (*KeyValueMapEntry, *Response, error) {
path := path.Join("environments", env, "keyvaluemaps", keyValueMapName, "entries", keyValueMapEntry)
req, e := s.client.NewRequest("GET", path, nil, "")
if e != nil {
return nil, nil, e
}
returnedKeyValueMapEntry := KeyValueMapEntry{}
resp, e := s.client.Do(req, &returnedKeyValueMapEntry)
if e != nil {
return nil, resp, e
}
return &returnedKeyValueMapEntry, resp, e
}
// Create a new key value map entry
func (s *KeyValueMapEntryServiceOp) Create(keyValueMapName string, keyValueMapEntry KeyValueMapEntryKeys, env string) (*KeyValueMapEntry, *Response, error) {
return postOrPutKeyValueMapEntry(keyValueMapName, keyValueMapEntry, env, "POST", s)
}
// Update an existing key value map entry
func (s *KeyValueMapEntryServiceOp) Update(keyValueMapName string, keyValueMapEntry KeyValueMapEntryKeys, env string) (*KeyValueMapEntry, *Response, error) {
return postOrPutKeyValueMapEntry(keyValueMapName, keyValueMapEntry, env, "PUT", s)
}
// Delete an existing key value map entry
func (s *KeyValueMapEntryServiceOp) Delete(keyValueMapEntry string, keyValueMapName string, env string) (*Response, error) {
path := path.Join("environments", env, "keyvaluemaps", keyValueMapName, "entries", keyValueMapEntry)
req, e := s.client.NewRequest("DELETE", path, nil, "")
if e != nil {
return nil, e
}
resp, e := s.client.Do(req, nil)
if e != nil {
return resp, e
}
return resp, e
}
func postOrPutKeyValueMapEntry(keyValueMapName string, keyValueMapEntry KeyValueMapEntryKeys, env string, opType string, s *KeyValueMapEntryServiceOp) (*KeyValueMapEntry, *Response, error) {
uripath := ""
if opType == "PUT" {
uripath = path.Join("environments", env, "keyvaluemaps", keyValueMapName, "entries", keyValueMapEntry.Name)
} else {
uripath = path.Join("environments", env, "keyvaluemaps", keyValueMapName, "entries")
}
req, e := s.client.NewRequest(opType, uripath, keyValueMapEntry, "")
if e != nil {
return nil, nil, e
}
returnedKeyValueMapEntry := KeyValueMapEntry{}
resp, e := s.client.Do(req, &returnedKeyValueMapEntry)
if e != nil {
return nil, resp, e
}
return &returnedKeyValueMapEntry, resp, e
}