utils

package
v0.0.0-...-5785f03 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Must   = "must"
	Prefer = "prefer"
	Reject = "reject"
	Any    = "any"
)

Variables

View Source
var (
	SymphonyAPIAddressBase = "http://symphony-service:8080/v1alpha2/"
)

Functions

func AssignComponentsToTargets

func AssignComponentsToTargets(components []model.ComponentSpec, targets map[string]model.TargetState) (map[string]string, error)

func CatalogHook

func CatalogHook(context context.Context, baseUrl string, user string, password string, payload []byte) error

func CollectStringMap

func CollectStringMap(col map[string]string, prefix string) map[string]string

func ContainsString

func ContainsString(names []string, name string) bool

func CreateInstance

func CreateInstance(context context.Context, baseUrl string, instance string, user string, password string, payload []byte, namespace string) error

func CreateSymphonyDeployment

func CreateSymphonyDeployment(instance model.InstanceState, solution model.SolutionState, targets []model.TargetState, devices []model.DeviceState, namespace string) (model.DeploymentSpec, error)

func CreateSymphonyDeploymentFromTarget

func CreateSymphonyDeploymentFromTarget(target model.TargetState, namespace string) (model.DeploymentSpec, error)

func CreateTarget

func CreateTarget(context context.Context, baseUrl string, target string, user string, password string, payload []byte, namespace string) error

func DeleteCatalog

func DeleteCatalog(context context.Context, baseUrl string, catalog string, user string, password string) error

func DeleteInstance

func DeleteInstance(context context.Context, baseUrl string, instance string, user string, password string, namespace string) error

func DeleteSolution

func DeleteSolution(context context.Context, baseUrl string, solution string, user string, password string, namespace string) error

func DeleteTarget

func DeleteTarget(context context.Context, baseUrl string, target string, user string, password string, namespace string) error

func EvaluateDeployment

func EvaluateDeployment(context utils.EvaluationContext) (model.DeploymentSpec, error)

func FormatAsString

func FormatAsString(val interface{}) string

func FormatObject

func FormatObject(obj interface{}, isArray bool, path string, format string) ([]byte, error)

func GetABatchForSite

func GetABatchForSite(context context.Context, baseUrl string, site string, user string, password string) (model.SyncPackage, error)

func GetActivation

func GetActivation(context context.Context, baseUrl string, activation string, user string, password string) (model.ActivationState, error)

func GetCampaign

func GetCampaign(context context.Context, baseUrl string, campaign string, user string, password string, namespace string) (model.CampaignState, error)

func GetCatalog

func GetCatalog(context context.Context, baseUrl string, catalog string, user string, password string, namespace string) (model.CatalogState, error)

func GetCatalogs

func GetCatalogs(context context.Context, baseUrl string, user string, password string, namespace string) ([]model.CatalogState, error)

func GetCatalogsWithFilter

func GetCatalogsWithFilter(context context.Context, baseUrl string, user string, password string, namespace string, filterType string, filterValue string) ([]model.CatalogState, error)

func GetInstance

func GetInstance(context context.Context, baseUrl string, instance string, user string, password string, namespace string) (model.InstanceState, error)

func GetInstances

func GetInstances(context context.Context, baseUrl string, user string, password string, namespace string) ([]model.InstanceState, error)

func GetInstancesForAllNamespaces

func GetInstancesForAllNamespaces(context context.Context, baseUrl string, user string, password string) ([]model.InstanceState, error)

func GetSites

func GetSites(context context.Context, baseUrl string, user string, password string) ([]model.SiteState, error)

func GetSolution

func GetSolution(context context.Context, baseUrl string, solution string, user string, password string, namespace string) (model.SolutionState, error)

func GetSolutions

func GetSolutions(context context.Context, baseUrl string, user string, password string, namespace string) ([]model.SolutionState, error)

func GetSolutionsForAllNamespaces

func GetSolutionsForAllNamespaces(context context.Context, baseUrl string, user string, password string) ([]model.SolutionState, error)

func GetString

func GetString(col map[string]string, key string) (string, error)

func GetSummary

func GetSummary(context context.Context, baseUrl string, user string, password string, id string, namespace string) (model.SummaryResult, error)

func GetSymphonyAPIAddressBase

func GetSymphonyAPIAddressBase() string

func GetTarget

func GetTarget(context context.Context, baseUrl string, target string, user string, password string, namespace string) (model.TargetState, error)

func GetTargets

func GetTargets(context context.Context, baseUrl string, user string, password string, namespace string) ([]model.TargetState, error)

func GetTargetsForAllNamespaces

func GetTargetsForAllNamespaces(context context.Context, baseUrl string, user string, password string) ([]model.TargetState, error)

func JsonPathQuery

func JsonPathQuery(obj interface{}, jsonPath string) (interface{}, error)

func MatchTargets

func MatchTargets(instance model.InstanceState, targets []model.TargetState) []model.TargetState

func MergeCollection

func MergeCollection(cols ...map[string]string) map[string]string

func NewAPIClient

func NewAPIClient(ctx context.Context, baseUrl string, opts ...ApiClientOption) (*apiClient, error)

func ParseValue

func ParseValue(v string) (interface{}, error)

TODO: we should get rid of this

func ProjectValue

func ProjectValue(val string, name string) string

TODO: This should not be used anymore

func PublishActivationEvent

func PublishActivationEvent(context context.Context, baseUrl string, user string, password string, event v1alpha2.ActivationData) error

func QueueJob

func QueueJob(context context.Context, baseUrl string, user string, password string, id string, namespace string, isDelete bool, isTarget bool) error

func ReadInt32

func ReadInt32(col map[string]string, key string, defaultVal int32) int32

func ReadString

func ReadString(col map[string]string, key string, defaultVal string) string

func ReadStringFromMapCompat

func ReadStringFromMapCompat(col map[string]interface{}, key string, defaultVal string) string

func ReadStringWithOverrides

func ReadStringWithOverrides(col1 map[string]string, col2 map[string]string, key string, defaultVal string) string

func Reconcile

func Reconcile(context context.Context, baseUrl string, user string, password string, deployment model.DeploymentSpec, namespace string, isDelete bool) (model.SummarySpec, error)

func ReportActivationStatus

func ReportActivationStatus(context context.Context, baseUrl string, name string, user string, password string, activation model.ActivationStatus) error

func ReportCatalogs

func ReportCatalogs(context context.Context, baseUrl string, user string, password string, instance string, components []model.ComponentSpec) error

func SendVisualizationPacket

func SendVisualizationPacket(context context.Context, baseUrl string, user string, password string, payload []byte) error

func ShouldUseSATokens

func ShouldUseSATokens() bool

func SyncActivationStatus

func SyncActivationStatus(context context.Context, baseUrl string, user string, password string, status model.ActivationStatus) error

func UpdateSite

func UpdateSite(context context.Context, baseUrl string, site string, user string, password string, payload []byte) error

func UpsertCatalog

func UpsertCatalog(context context.Context, baseUrl string, catalog string, user string, password string, payload []byte) error

func UpsertSolution

func UpsertSolution(context context.Context, baseUrl string, solution string, user string, password string, payload []byte, namespace string) error

Types

type ApiClient

type ApiClient interface {
	SummaryGetter
	Dispatcher
	GetInstancesForAllNamespaces(ctx context.Context) ([]model.InstanceState, error)
	GetInstances(ctx context.Context, namespace string) ([]model.InstanceState, error)
	GetInstance(ctx context.Context, instance string, namespace string) (model.InstanceState, error)
	CreateInstance(ctx context.Context, instance string, payload []byte, namespace string) error
	DeleteInstance(ctx context.Context, instance string, namespace string) error
	DeleteTarget(ctx context.Context, target string, namespace string) error
	GetSolutions(ctx context.Context, namespace string) ([]model.SolutionState, error)
	GetSolution(ctx context.Context, solution string, namespace string) (model.SolutionState, error)
	CreateSolution(ctx context.Context, solution string, payload []byte, namespace string) error
	DeleteSolution(ctx context.Context, solution string, namespace string) error
	GetTargetsForAllNamespaces(ctx context.Context) ([]model.TargetState, error)
	GetTarget(ctx context.Context, target string, namespace string) (model.TargetState, error)
	GetTargets(ctx context.Context, namespace string) ([]model.TargetState, error)
	CreateTarget(ctx context.Context, target string, payload []byte, namespace string) error
	Reconcile(ctx context.Context, deployment model.DeploymentSpec, isDelete bool, namespace string) (model.SummarySpec, error)
}

type ApiClientOption

type ApiClientOption func(*apiClient)

func WithCertAuth

func WithCertAuth(caCertPath string) ApiClientOption

func WithServiceAccountToken

func WithServiceAccountToken() ApiClientOption

func WithUserPassword

func WithUserPassword(ctx context.Context, user string, password string) ApiClientOption

type BinaryNode

type BinaryNode struct {
	Op    Token
	Left  Node
	Right Node
}

func (*BinaryNode) Eval

func (n *BinaryNode) Eval(context utils.EvaluationContext) (interface{}, error)

type Dispatcher

type Dispatcher interface {
	QueueJob(ctx context.Context, id string, namespace string, isDelete bool, isTarget bool) error
	QueueDeploymentJob(ctx context.Context, namespace string, isDelete bool, deployment model.DeploymentSpec) error
}

type ExpressionParser

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

func (*ExpressionParser) Eval

func (p *ExpressionParser) Eval(context utils.EvaluationContext) (interface{}, error)

type FunctionNode

type FunctionNode struct {
	Name string
	Args []Node
}

func (*FunctionNode) Eval

func (n *FunctionNode) Eval(context utils.EvaluationContext) (interface{}, error)

type IdentifierNode

type IdentifierNode struct {
	Value string
}

func (*IdentifierNode) Eval

func (n *IdentifierNode) Eval(context utils.EvaluationContext) (interface{}, error)

type IntNode

type IntNode struct {
	Value int64
}

func (*IntNode) Eval

func (n *IntNode) Eval(context utils.EvaluationContext) (interface{}, error)

type Node

type Node interface {
	Eval(context utils.EvaluationContext) (interface{}, error)
}

type NullNode

type NullNode struct {
}

func (*NullNode) Eval

func (n *NullNode) Eval(context utils.EvaluationContext) (interface{}, error)

type NumberNode

type NumberNode struct {
	Value float64
}

func (*NumberNode) Eval

func (n *NumberNode) Eval(context utils.EvaluationContext) (interface{}, error)

type Parser

type Parser struct {
	Segments     []string
	OriginalText string
}

func NewParser

func NewParser(text string) *Parser

func (*Parser) Eval

func (p *Parser) Eval(context utils.EvaluationContext) (interface{}, error)

type Rule

type Rule struct {
	Type       string `json:"type,omitempty"`
	Required   bool   `json:"required,omitempty"`
	Pattern    string `json:"pattern,omitempty"`
	Expression string `json:"expression,omitempty"`
}

type RuleResult

type RuleResult struct {
	Valid bool   `json:"valid"`
	Error string `json:"error,omitempty"`
}

type Schema

type Schema struct {
	Rules map[string]Rule `json:"rules,omitempty"`
}

func (*Schema) CheckProperties

func (s *Schema) CheckProperties(properties map[string]interface{}, evaluationContext *coa_utils.EvaluationContext) (SchemaResult, error)

type SchemaResult

type SchemaResult struct {
	Valid  bool                  `json:"valid"`
	Errors map[string]RuleResult `json:"errors,omitempty"`
}

type SummaryGetter

type SummaryGetter interface {
	GetSummary(ctx context.Context, id string, namespace string) (*model.SummaryResult, error)
}

type SummarySpecError

type SummarySpecError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

We shouldn't use specific error types SummarySpecError represents an error that includes a SummarySpec in its message field.

func (*SummarySpecError) Error

func (e *SummarySpecError) Error() string

type Token

type Token int
const (
	EOF Token = iota
	NUMBER
	INT
	DOLLAR
	IDENT
	OPAREN
	CPAREN
	OBRACKET
	CBRACKET
	OCURLY
	CCURLY
	PLUS
	MINUS
	MULT
	DIV
	COMMA
	PERIOD
	COLON
	QUESTION
	EQUAL
	STRING
	RUNON
	AMPHERSAND
	SLASH
	TILDE
)

type TokenProvider

type TokenProvider func(ctx context.Context, baseUrl string, client *http.Client) (string, error)

type UnaryNode

type UnaryNode struct {
	Op   Token
	Expr Node
}

func (*UnaryNode) Eval

func (n *UnaryNode) Eval(context utils.EvaluationContext) (interface{}, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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