-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathenvironment_tags.go
56 lines (46 loc) · 1.54 KB
/
environment_tags.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
package scalr
import (
"context"
"fmt"
"net/url"
)
// Compile-time proof of interface implementation.
var _ EnvironmentTags = (*environmentTag)(nil)
// EnvironmentTags describes all the environment tags related methods that the
// Scalr API supports.
type EnvironmentTags interface {
Add(ctx context.Context, envID string, tags []*TagRelation) error
Replace(ctx context.Context, envID string, tags []*TagRelation) error
Delete(ctx context.Context, envID string, tags []*TagRelation) error
}
// environmentTag implements EnvironmentTags.
type environmentTag struct {
client *Client
}
// Add tags to the environment
func (s *environmentTag) Add(ctx context.Context, envID string, trs []*TagRelation) error {
u := fmt.Sprintf("environments/%s/relationships/tags", url.QueryEscape(envID))
req, err := s.client.newRequest("POST", u, trs)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}
// Replace environment's tags
func (s *environmentTag) Replace(ctx context.Context, envID string, trs []*TagRelation) error {
u := fmt.Sprintf("environments/%s/relationships/tags", url.QueryEscape(envID))
req, err := s.client.newRequest("PATCH", u, trs)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}
// Delete environment's tags
func (s *environmentTag) Delete(ctx context.Context, envID string, trs []*TagRelation) error {
u := fmt.Sprintf("environments/%s/relationships/tags", url.QueryEscape(envID))
req, err := s.client.newRequest("DELETE", u, trs)
if err != nil {
return err
}
return s.client.do(ctx, req, nil)
}