Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature flag methods #167

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions feature_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package rabbithole

import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)

// Feature flags are a mechanism that controls what features are considered to be enabled or available on all cluster nodes.
// If a FeatureFlag is enabled so is its associated feature (or behavior).
// If not then all nodes in the cluster will disable the feature (behavior).
type FeatureFlag struct {
Name string `json:"name"`
// Desc is the description of the feature flag.
Desc string `json:"desc,omitempty"`
// DocURL is the URL to a webpage to learn more about the feature flag.
DocURL string `json:"doc_url,omitempty"`
State State `json:"state,omitempty"`
Stability Stability `json:"stability,omitempty"`
// ProvidedBy is the RabbitMQ component or plugin which provides the feature flag.
ProvidedBy string `json:"provided_by,omitempty"`
}

type State string

const (
StateEnabled State = "enabled"
StateDisabled State = "disabled"
// StateUnsupported means that one or more nodes in the cluster do not know this feature flag (and therefore it cannot be enabled).
StateUnsupported State = "unsupported"
)

type Stability string

const (
StabilityStable Stability = "stable"
StabilityExperimental Stability = "experimental"
)

//
// GET /api/feature-flags
//

// ListFeatureFlags lists all feature flags.
func (c *Client) ListFeatureFlags() (rec []FeatureFlag, err error) {
req, err := newGETRequest(c, "feature-flags")
if err != nil {
return nil, err
}

if err = executeAndParseRequest(c, req, &rec); err != nil {
return nil, err
}

return rec, nil
}

//
// PUT /api/feature-flags/{name}/enable
//

// EnableFeatureFlag enables a feature flag.
func (c *Client) EnableFeatureFlag(featureFlagName string) (res *http.Response, err error) {
body, err := json.Marshal(FeatureFlag{Name: featureFlagName})
if err != nil {
return nil, err
}

path := fmt.Sprintf("feature-flags/%s/enable", url.PathEscape(featureFlagName))
req, err := newRequestWithBody(c, "PUT", path, body)
if err != nil {
return nil, err
}

if res, err = executeRequest(c, req); err != nil {
return nil, err
}

return res, nil
}
16 changes: 4 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
module github.com/michaelklishin/rabbit-hole/v2

require (
cloud.google.com/go/storage v1.8.0
github.com/hpcloud/tail v1.0.0
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
github.com/kr/pretty v0.1.0 // indirect
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.3
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94
go4.org v0.0.0-20200411211856-f5505b9728dd
golang.org/x/build v0.0.0-20200520141049-92427f67eca1
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f
golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25
golang.org/x/text v0.3.2
gopkg.in/fsnotify/fsnotify.v1 v1.4.7
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)

go 1.13
Loading