fflag

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2022 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFeatureNotAvailable = errors.New("this feature is not yet available for you")
	CanCreateCLIAPIKey     = "can_create_cli_api_key"
)
View Source
var Features = map[string]IsEnabledFunc{
	CanCreateCLIAPIKey: func(r *http.Request) error {
		group := middleware.GetGroupFromContext(r.Context())

		cfg, err := config.Get()
		if err != nil {
			return err
		}

		ff := newFliptClient(cfg)

		if ff == nil {
			return nil
		}

		var apiKey models.CreateAppApiKey
		body, err := io.ReadAll(r.Body)
		if err != nil {
			return err
		}

		r.Body = io.NopCloser(bytes.NewBuffer(body))

		err = json.Unmarshal(body, &apiKey)
		if err != nil {
			return err
		}

		if apiKey.KeyType == datastore.CLIKey {
			isEnabled, err := ff.IsEnabled(CanCreateCLIAPIKey, map[string]string{
				"group_id":        group.UID,
				"organisation_id": group.OrganisationID,
			})

			if err != nil {
				log.WithError(err).Error("failed to check flag on flipt")
				return err
			}

			if !isEnabled {
				return ErrFeatureNotAvailable
			}
		}

		return nil
	},
}

Functions

func CanAccessFeature

func CanAccessFeature(fn IsEnabledFunc) func(next http.Handler) http.Handler

Types

type IsEnabledFunc

type IsEnabledFunc func(r *http.Request) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL