policies

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCreatePolicy            = errors.New("failed to create policy")
	ErrValidatePolicy          = errors.New("failed to validate policy")
	ErrCreateDataset           = errors.New("failed to create dataset")
	ErrInactivateDataset       = errors.New("failed to inactivate dataset")
	ErrUpdateEntity            = errors.New("failed to update entity")
	ErrRemoveEntity            = errors.New("failed to remove entity")
	ErrMalformedEntity         = errors.New("malformed entity")
	ErrNotFound                = errors.New("non-existent entity")
	ErrUnauthorizedAccess      = errors.New("missing or invalid credentials provided")
	ErrNotifyAgentGroupChannel = errors.New("failed to notify agent group channel")
)

Functions

This section is empty.

Types

type Dataset

type Dataset struct {
	ID           string
	Name         types.Identifier
	MFOwnerID    string
	Valid        bool
	AgentGroupID string
	PolicyID     string
	Metadata     types.Metadata
	Created      time.Time
	Tags         types.Tags
	SinkIDs      *[]string
}

type Page

type Page struct {
	PageMetadata
	Policies []Policy
}

type PageDataset

type PageDataset struct {
	PageMetadata
	Datasets []Dataset
}

type PageMetadata

type PageMetadata struct {
	Total    uint64
	Offset   uint64         `json:"offset,omitempty"`
	Limit    uint64         `json:"limit,omitempty"`
	Name     string         `json:"name,omitempty"`
	Order    string         `json:"order,omitempty"`
	Dir      string         `json:"dir,omitempty"`
	Metadata types.Metadata `json:"metadata,omitempty"`
	Tags     types.Tags     `json:"tags,omitempty"`
}

type Policy

type Policy struct {
	ID            string
	Name          types.Identifier
	Description   *string
	MFOwnerID     string
	Backend       string
	SchemaVersion string
	Version       int32
	OrbTags       types.Tags
	Policy        types.Metadata
	PolicyData    string
	Format        string
	Created       time.Time
	LastModified  time.Time
}

type PolicyInDataset

type PolicyInDataset struct {
	Policy
	DatasetID    string
	AgentGroupID string
}

type Repository

type Repository interface {
	// SavePolicy persists a Policy. Successful operation is indicated by non-nil
	// error response.
	SavePolicy(ctx context.Context, policy Policy) (string, error)

	// RetrievePolicyByID Retrieve policy by id
	RetrievePolicyByID(ctx context.Context, policyID string, ownerID string) (Policy, error)

	// RetrievePoliciesByGroupID Retrieve policy list by group id
	RetrievePoliciesByGroupID(ctx context.Context, groupIDs []string, ownerID string) ([]PolicyInDataset, error)

	// RetrieveAll retrieves the subset of Policies owned by the specified user
	RetrieveAll(ctx context.Context, ownerID string, pm PageMetadata) (Page, error)

	// UpdatePolicy update a existing policy by id with a valid token
	UpdatePolicy(ctx context.Context, ownerID string, pol Policy) error

	// DeletePolicy a existing policy by id owned by the specified user
	DeletePolicy(ctx context.Context, ownerID string, policyID string) error

	// SaveDataset persists a Dataset. Successful operation is indicated by non-nil
	// error response.
	SaveDataset(ctx context.Context, dataset Dataset) (string, error)

	// InactivateDatasetByGroupID inactivate a dataset
	InactivateDatasetByGroupID(ctx context.Context, groupID string, ownerID string) error

	// InactivateDatasetByPolicyID inactivate a dataset by policy id
	InactivateDatasetByPolicyID(ctx context.Context, policyID string, ownerID string) error

	// RetrieveDatasetsByPolicyID retrieves the subset of Datasets by policyID owned by the specified user
	RetrieveDatasetsByPolicyID(ctx context.Context, policyID string, ownerID string) ([]Dataset, error)

	// UpdateDataset update a existing dataset by id with a valid token
	UpdateDataset(ctx context.Context, ownerID string, ds Dataset) error

	//DeleteDataset delete a existing dataset by id by ownerID
	DeleteDataset(ctx context.Context, ownerID string, dsID string) error

	// RetrieveDatasetByID Retrieves dataset by id
	RetrieveDatasetByID(ctx context.Context, datasetID string, ownerID string) (Dataset, error)

	// RetrieveAllDatasetsByOwner retrieves the subset of Datasets owned by the specified user
	RetrieveAllDatasetsByOwner(ctx context.Context, ownerID string, pm PageMetadata) (PageDataset, error)

	// InactivateDatasetByID inactivate a dataset
	InactivateDatasetByID(ctx context.Context, sinkID string, ownerID string) error

	// DeleteSinkFromAllDatasets removes a sink from a dataset
	DeleteSinkFromAllDatasets(ctx context.Context, sinkID string, ownerID string) ([]Dataset, error)

	// ActivateDatasetByID Activate a dataset
	ActivateDatasetByID(ctx context.Context, datasetID string, ownerID string) error

	// DeleteAgentGroupFromAllDatasets removes agent group from a dataset
	DeleteAgentGroupFromAllDatasets(ctx context.Context, groupID string, ownerID string) error

	// DeleteAllDatasetsPolicy removes all datasets by policyID
	DeleteAllDatasetsPolicy(ctx context.Context, policyID string, ownerID string) error

	// RetrieveDatasetsByGroupID Retrieve dataset list by group id
	RetrieveDatasetsByGroupID(ctx context.Context, groupIDs []string, ownerID string) ([]Dataset, error)
}

type Service

type Service interface {
	// AddPolicy creates new agent Policy
	AddPolicy(ctx context.Context, token string, p Policy) (Policy, error)

	// ViewPolicyByID retrieving policy by id with token
	ViewPolicyByID(ctx context.Context, token string, policyID string) (Policy, error)

	// ListPolicies
	ListPolicies(ctx context.Context, token string, pm PageMetadata) (Page, error)

	// ViewPolicyByIDInternal gRPC version of retrieving policy by id with no token
	ViewPolicyByIDInternal(ctx context.Context, policyID string, ownerID string) (Policy, error)

	// ListPoliciesByGroupIDInternal gRPC version of retrieving list of policies belonging to specified agent group with no token
	ListPoliciesByGroupIDInternal(ctx context.Context, groupIDs []string, ownerID string) ([]PolicyInDataset, error)

	// EditPolicy edit a existing policy by id with a valid token
	EditPolicy(ctx context.Context, token string, pol Policy) (Policy, error)

	// RemovePolicy remove a existing policy owned by the specified user
	RemovePolicy(ctx context.Context, token string, policyID string) error

	// AddDataset creates new Dataset
	AddDataset(ctx context.Context, token string, d Dataset) (Dataset, error)

	// InactivateDatasetByGroupID inactivate a dataset
	InactivateDatasetByGroupID(ctx context.Context, groupID string, token string) error

	// ListDatasetsByPolicyIDInternal retrieves the subset of Datasets by policyID owned by the specified user
	ListDatasetsByPolicyIDInternal(ctx context.Context, policyID string, token string) ([]Dataset, error)

	// ValidatePolicy validates an agent Policy without saving
	ValidatePolicy(ctx context.Context, token string, p Policy) (Policy, error)

	// EditDataset edit a existing dataset by id with a valid token
	EditDataset(ctx context.Context, token string, ds Dataset) (Dataset, error)
	// RemoveDataset remove a dataset by id with a valid token
	RemoveDataset(ctx context.Context, token string, dsID string) error

	// ValidateDataset validates a new Dataset without saving it
	ValidateDataset(ctx context.Context, token string, d Dataset) (Dataset, error)

	// ViewDatasetByID retrieving dataset by id with token
	ViewDatasetByID(ctx context.Context, token string, datasetID string) (Dataset, error)

	// ViewDatasetByIDInternal retrieving dataset by id with provided ownerID
	ViewDatasetByIDInternal(ctx context.Context, ownerID string, datasetID string) (Dataset, error)

	// ListDatasets retrieve a list of Dataset by owner
	ListDatasets(ctx context.Context, token string, pm PageMetadata) (PageDataset, error)

	// InactivateDatasetByIDInternal inactivate a dataset
	InactivateDatasetByIDInternal(ctx context.Context, ownerID string, datasetID string) error

	// DeleteSinkFromAllDatasetsInternal removes a sink from a dataset
	DeleteSinkFromAllDatasetsInternal(ctx context.Context, sinkID string, ownerID string) ([]Dataset, error)

	// DeleteAgentGroupFromAllDatasets removes an agent group from a dataset
	DeleteAgentGroupFromAllDatasets(ctx context.Context, groupID string, token string) error

	// DuplicatePolicy duplicates existing agent Policy
	DuplicatePolicy(ctx context.Context, token string, policyID string, name string) (Policy, error)

	// RemoveAllDatasetsByPolicyIDInternal removes all datasets by policyID owned by the specified user
	RemoveAllDatasetsByPolicyIDInternal(ctx context.Context, token string, policyID string) error

	// ListDatasetsByGroupIDInternal gRPC version of retrieving list of datasets belonging to specified agent group with no token
	ListDatasetsByGroupIDInternal(ctx context.Context, groupIDs []string, ownerID string) ([]Dataset, error)
}

func New

func New(logger *zap.Logger, auth mainflux.AuthServiceClient, repo Repository, fleetGrpcClient fleetpb.FleetServiceClient, sinksGrpcclient sinkpb.SinkServiceClient) Service

Directories

Path Synopsis
api
grpc
Package grpc contains implementation of service gRPC API.
Package grpc contains implementation of service gRPC API.
orb
Package postgres contains repository implementations using PostgreSQL as the underlying database.
Package postgres contains repository implementations using PostgreSQL as the underlying database.
redis
consumer
Package esconsumer contains events esconsumer for events
Package esconsumer contains events esconsumer for events
producer
Package producer contains the domain events needed to support event sourcing of Sink service actions.
Package producer contains the domain events needed to support event sourcing of Sink service actions.

Jump to

Keyboard shortcuts

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