fflag

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MPL-2.0 Imports: 12 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 {

		project := &datastore.Project{}

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

		ff := newFliptClient(cfg)

		if ff == nil {
			return nil
		}

		var apiKey models.CreateEndpointApiKey
		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{
				"project_id":      project.UID,
				"organisation_id": project.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