-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathfeatureflag.go
More file actions
76 lines (61 loc) · 2.29 KB
/
Copy pathfeatureflag.go
File metadata and controls
76 lines (61 loc) · 2.29 KB
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
package api
import (
"context"
"sort"
"github.com/humio/cli/internal/api/humiographql"
)
type FeatureFlagName string
type FeatureFlag struct {
Flag FeatureFlagName
Experimental bool
Description string
}
type FeatureFlags struct {
client *Client
}
func (c *Client) FeatureFlags() *FeatureFlags {
return &FeatureFlags{client: c}
}
func (f *FeatureFlags) SupportedFlags() ([]FeatureFlag, error) {
resp, err := humiographql.GetSupportedFeatureFlags(context.Background(), f.client)
if err != nil {
return nil, err
}
respFeatureFlags := resp.GetFeatureFlags()
supportedFlags := make([]FeatureFlag, len(respFeatureFlags))
for idx, flag := range respFeatureFlags {
supportedFlags[idx] = FeatureFlag{
Flag: FeatureFlagName(flag.GetFlag()),
Experimental: flag.GetExperimental(),
Description: flag.GetDescription(),
}
}
sort.Slice(supportedFlags, func(i, j int) bool {
return supportedFlags[i].Flag < supportedFlags[j].Flag
})
return supportedFlags, nil
}
func (f *FeatureFlags) EnableGlobally(flag FeatureFlagName) error {
_, err := humiographql.EnableFeatureFlagGlobally(context.Background(), f.client, humiographql.FeatureFlag(flag))
return err
}
func (f *FeatureFlags) DisableGlobally(flag FeatureFlagName) error {
_, err := humiographql.DisableFeatureFlagGlobally(context.Background(), f.client, humiographql.FeatureFlag(flag))
return err
}
func (f *FeatureFlags) EnableForOrganization(organizationID string, flag FeatureFlagName) error {
_, err := humiographql.EnableFeatureFlagForOrganization(context.Background(), f.client, humiographql.FeatureFlag(flag), organizationID)
return err
}
func (f *FeatureFlags) DisableForOrganization(organizationID string, flag FeatureFlagName) error {
_, err := humiographql.DisableFeatureFlagForOrganization(context.Background(), f.client, humiographql.FeatureFlag(flag), organizationID)
return err
}
func (f *FeatureFlags) EnableForUser(userID string, flag FeatureFlagName) error {
_, err := humiographql.EnableFeatureFlagForUser(context.Background(), f.client, humiographql.FeatureFlag(flag), userID)
return err
}
func (f *FeatureFlags) DisableForUser(userID string, flag FeatureFlagName) error {
_, err := humiographql.DisableFeatureFlagForUser(context.Background(), f.client, humiographql.FeatureFlag(flag), userID)
return err
}