utils

package
v0.0.0-...-3c07d94 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 34 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 AreSlicesEqual

func AreSlicesEqual(slice1, slice2 []string) bool

func AssignComponentsToTargets

func AssignComponentsToTargets(ctx context.Context, 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 ConstructSummaryId

func ConstructSummaryId(name string, guid string) string

func ContainsString

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

func ConvertObjectNameToReference

func ConvertObjectNameToReference(name string) string

func ConvertReferenceToObjectName

func ConvertReferenceToObjectName(name string) string

func CreateInstance

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

func CreateSymphonyDeployment

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

func CreateSymphonyDeploymentFromTarget

func CreateSymphonyDeploymentFromTarget(ctx context.Context, 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 DetermineObjectTerminalStatus

func DetermineObjectTerminalStatus(objectMeta model.ObjectMeta, status model.DeployableStatus) bool

func EvaluateDeployment

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

func FilterIncompleteDelete

func FilterIncompleteDelete(ctx context.Context, apiclient *ApiClient, namespace string, objectNames []string, isInstance bool, username string, password string) []string

func FilterIncompleteDeploymentUsingSummary

func FilterIncompleteDeploymentUsingSummary(ctx context.Context, apiclient *ApiClient, namespace string, objects []ObjectInfo, isInstance bool, username string, password string) ([]ObjectInfo, []FailedDeployment)

func FormatAsString

func FormatAsString(val interface{}) string

func FormatObject

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

func GenerateKeyLockName

func GenerateKeyLockName(strs ...string) string

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 GetApiClient

func GetApiClient() (*apiClient, 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 GetNamespaceFromContext

func GetNamespaceFromContext(localContext interface{}) string

func GetParentApiClient

func GetParentApiClient(baseUrl string) (*apiClient, 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 GetTargetRuntimeKey

func GetTargetRuntimeKey(guid string) string

Add target-runtime prefix to notify the object is a target.

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 IsNotFound

func IsNotFound(err error) bool

func JsonParseProperty

func JsonParseProperty(properties interface{}, fieldPath string) (any, bool)

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 ShouldUseUserCreds

func ShouldUseUserCreds() bool

func SyncStageStatus

func SyncStageStatus(context context.Context, baseUrl string, user string, password string, status model.StageStatus) error

func ToCOAError

func ToCOAError(apiErr APIError) v1alpha2.COAError

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 APIError

type APIError struct {
	Code    v1alpha2.State `json:"code"`
	Message string         `json:"message"`
}

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

func NewAPIError

func NewAPIError(state v1alpha2.State, msg string) APIError

func (APIError) Error

func (e APIError) Error() string

func (APIError) IsRetriableErr

func (e APIError) IsRetriableErr() bool

type ApiClient

type ApiClient interface {
	SummaryGetter
	Dispatcher
	GetInstancesForAllNamespaces(ctx context.Context, user string, password string) ([]model.InstanceState, error)
	GetInstances(ctx context.Context, namespace string, user string, password string) ([]model.InstanceState, error)
	GetInstance(ctx context.Context, instance string, namespace string, user string, password string) (model.InstanceState, error)
	CreateInstance(ctx context.Context, instance string, payload []byte, namespace string, user string, password string) error
	DeleteInstance(ctx context.Context, instance string, namespace string, user string, password string) error
	DeleteTarget(ctx context.Context, target string, namespace string, user string, password string) error
	GetSolutions(ctx context.Context, namespace string, user string, password string) ([]model.SolutionState, error)
	GetSolution(ctx context.Context, solution string, namespace string, user string, password string) (model.SolutionState, error)
	CreateSolution(ctx context.Context, solution string, payload []byte, namespace string, user string, password string) error
	DeleteSolution(ctx context.Context, solution string, namespace string, user string, password string) error
	GetTargetsForAllNamespaces(ctx context.Context, user string, password string) ([]model.TargetState, error)
	GetTarget(ctx context.Context, target string, namespace string, user string, password string) (model.TargetState, error)
	GetTargets(ctx context.Context, namespace string, user string, password string) ([]model.TargetState, error)
	CreateTarget(ctx context.Context, target string, payload []byte, namespace string, user string, password string) error
	Reconcile(ctx context.Context, deployment model.DeploymentSpec, isDelete bool, namespace string, user string, password string) (model.SummarySpec, error)
	CatalogHook(ctx context.Context, payload []byte, user string, password string) error
	PublishActivationEvent(ctx context.Context, event v1alpha2.ActivationData, user string, password string) error
	GetActivation(ctx context.Context, activation string, namespace string, user string, password string) (model.ActivationState, error)
	GetCatalog(ctx context.Context, catalog string, namespace string, user string, password string) (model.CatalogState, error)
	UpsertCatalog(ctx context.Context, catalog string, payload []byte, user string, password string) error
	DeleteCatalog(ctx context.Context, catalog string, user string, password string) error
	UpsertSolution(ctx context.Context, solution string, payload []byte, namespace string, user string, password string) error
	GetSites(ctx context.Context, user string, password string) ([]model.SiteState, error)
	GetCatalogs(ctx context.Context, namespace string, user string, password string) ([]model.CatalogState, error)
	GetCatalogsWithFilter(ctx context.Context, namespace string, filterType string, filterValue string, user string, password string) ([]model.CatalogState, error)
	UpdateSite(ctx context.Context, site string, payload []byte, user string, password string) error
	GetABatchForSite(ctx context.Context, site string, user string, password string) (model.SyncPackage, error)
	SyncStageStatus(ctx context.Context, status model.StageStatus, user string, password string) error
	SendVisualizationPacket(ctx context.Context, payload []byte, user string, password string) error
	ReportCatalogs(ctx context.Context, instance string, components []model.ComponentSpec, user string, password string) error
	CreateSolutionContainer(ctx context.Context, instanceContainer string, payload []byte, namespace string, user string, password string) error
	DeleteSolutionContainer(ctx context.Context, instanceContainer string, namespace string, user string, password string) error
	GetSolutionContainer(ctx context.Context, instanceContainer string, namespace string, user string, password string) (model.SolutionContainerState, error)
	CreateCatalogContainer(ctx context.Context, instanceContainer string, payload []byte, namespace string, user string, password string) error
	DeleteCatalogContainer(ctx context.Context, instanceContainer string, namespace string, user string, password string) error
	GetCatalogContainer(ctx context.Context, instanceContainer string, namespace string, user string, password string) (model.CatalogContainerState, error)
	CreateCampaignContainer(ctx context.Context, instanceContainer string, payload []byte, namespace string, user string, password string) error
	DeleteCampaignContainer(ctx context.Context, instanceContainer string, namespace string, user string, password string) error
	GetCampaignContainer(ctx context.Context, instanceContainer string, namespace string, user string, password string) (model.CampaignContainerState, error)
	GetParsedCatalogProperties(ctx context.Context, name string, namespace string, user string, password string) (map[string]interface{}, 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) 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, user string, password string) error
	QueueDeploymentJob(ctx context.Context, namespace string, isDelete bool, deployment model.DeploymentSpec, user string, password string) error
}

type ExpressionParser

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

func (*ExpressionParser) Eval

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

type FailedDeployment

type FailedDeployment struct {
	Name    string `json:"name"`
	Message string `json:"FailedMessage"`
}

func FilterIncompleteDeploymentUsingStatus

func FilterIncompleteDeploymentUsingStatus(ctx context.Context, apiclient *ApiClient, namespace string, objectNames []string, isInstance bool, username string, password string) ([]string, []FailedDeployment)

Once status report is enabled in standalone mode, we need to use object status rather than summary to check the deployment status

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 ObjectInfo

type ObjectInfo struct {
	Name      string
	SummaryId string
}

Define the struct

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(ctx context.Context, 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"`
}

func (*SchemaResult) ToErrorMessages

func (s *SchemaResult) ToErrorMessages() string

type SummaryGetter

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

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, user string, password string) (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