rule

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicate = errors.New("rule conflicted with existing")
	ErrRelation  = errors.New("provider's namespace does not exist")
)

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Name         string
	Namespace    string
	GroupName    string
	TemplateName string
	NamespaceID  uint64
}

type Repository

type Repository interface {
	Transactor
	Upsert(context.Context, *Rule) error
	List(context.Context, Filter) ([]Rule, error)
}

type Rule

type Rule struct {
	ID                uint64         `json:"id"`
	Name              string         `json:"name"`
	Enabled           bool           `json:"enabled" validate:"required"`
	GroupName         string         `json:"group_name" validate:"required"`
	Namespace         string         `json:"namespace" validate:"required"`
	Template          string         `json:"template" validate:"required"`
	Variables         []RuleVariable `json:"variables" validate:"required,dive,required"`
	ProviderNamespace uint64         `json:"provider_namespace" validate:"required"`
	CreatedAt         time.Time      `json:"created_at"`
	UpdatedAt         time.Time      `json:"updated_at"`
}

func FromV1beta1Proto added in v0.6.7

func FromV1beta1Proto(proto *sirenv1beta1.Rule) Rule

func (*Rule) ToV1beta1Proto added in v0.6.7

func (r *Rule) ToV1beta1Proto() *sirenv1beta1.Rule

type RuleFile

type RuleFile struct {
	ApiVersion        string `yaml:"apiVersion"`
	Entity            string `yaml:"entity"`
	Type              string `yaml:"type"`
	Namespace         string `yaml:"namespace"`
	Provider          string `yaml:"provider"`
	ProviderNamespace string `yaml:"providerNamespace"`
	Rules             map[string]struct {
		Template  string      `yaml:"template"`
		Enabled   bool        `yaml:"enabled"`
		Variables []variables `yaml:"variables"`
	} `yaml:"rules"`
}

type RuleUploader

type RuleUploader interface {
	UpsertRule(ctx context.Context, ns namespace.Namespace, prov provider.Provider, rl *Rule, templateToUpdate *template.Template) error
}

type RuleVariable

type RuleVariable struct {
	Name        string `json:"name" validate:"required"`
	Type        string `json:"type"`
	Value       string `json:"value" validate:"required"`
	Description string `json:"description"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles business logic

func NewService

func NewService(
	repository Repository,
	templateService TemplateService,
	namespaceService NamespaceService,
	ruleUploadersRegistry map[string]RuleUploader,
) *Service

NewService returns repository struct

func (*Service) List

func (s *Service) List(ctx context.Context, flt Filter) ([]Rule, error)

func (*Service) Upsert

func (s *Service) Upsert(ctx context.Context, rl *Rule) error

type TemplateService

type TemplateService interface {
	Upsert(context.Context, *template.Template) error
	List(context.Context, template.Filter) ([]template.Template, error)
	GetByName(context.Context, string) (*template.Template, error)
	Delete(context.Context, string) error
}

type Transactor

type Transactor interface {
	WithTransaction(ctx context.Context) context.Context
	Rollback(ctx context.Context, err error) error
	Commit(ctx context.Context) error
}

type Variables

type Variables struct {
	Variables []variable `json:"variables"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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