core

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Namespace     string
	LogLevel      string
	OutputFormat  string
	AllNamespaces bool
	CleanOutput   bool
	NoColor       bool
)
View Source
var (
	GvrCache      map[string]schema.GroupVersionResource
	ResourceSpecs map[string][]string
)

Add these variables at the top with the other vars

Functions

func AddRelationship

func AddRelationship(resourceA, resourceB interface{}, relationshipType string)

func AddRelationshipRule

func AddRelationshipRule(rule RelationshipRule)

func GetRelationships

func GetRelationships() map[string][]string

func InitGVRCache

func InitGVRCache(p provider.Provider) error

Add these functions back

func InitResourceSpecs

func InitResourceSpecs(p provider.Provider) error

func InitializeRelationships

func InitializeRelationships(resourceSpecs map[string][]string, provider provider.Provider)

Types

type Clause

type Clause interface {
	// contains filtered or unexported methods
}

Clause is an interface implemented by all clause types

type ComparisonType

type ComparisonType string
const (
	ExactMatch     ComparisonType = "ExactMatch"
	ContainsAll    ComparisonType = "ContainsAll"
	StringContains ComparisonType = "StringContains"
)

type CreateClause

type CreateClause struct {
	Nodes         []*NodePattern
	Relationships []*Relationship
}

CreateClause represents a CREATE clause

type DefaultProp

type DefaultProp struct {
	FieldA  string      `yaml:"fieldA"`
	FieldB  string      `yaml:"fieldB"`
	Default interface{} `yaml:"default"`
}

type DeleteClause

type DeleteClause struct {
	NodeIds []string
}

DeleteClause represents a DELETE clause

type Direction

type Direction string

Direction represents the direction of a relationship

const (
	Left  Direction = "left"
	Right Direction = "right"
	Both  Direction = "both"
	None  Direction = "none"
)

type Edge

type Edge struct {
	From string
	To   string
	Type string
}

type Expression

type Expression struct {
	Contexts []string
	Clauses  []Clause
}

Expression represents a complete Cyphernetes query

func ParseQuery

func ParseQuery(query string) (*Expression, error)

ParseQuery is the main entry point for parsing Cyphernetes queries

type Graph

type Graph struct {
	Nodes []Node
	Edges []Edge
}

type KeyValuePair

type KeyValuePair struct {
	Key      string
	Value    interface{}
	Operator string
}

KeyValuePair represents a key-value pair with an operator

type Lexer

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

func NewLexer

func NewLexer(input string) *Lexer

func (*Lexer) NextToken

func (l *Lexer) NextToken() Token

NextToken returns the next token in the input

func (*Lexer) Peek

func (l *Lexer) Peek() rune

Add Peek method to Lexer

func (*Lexer) SetParsingContexts

func (l *Lexer) SetParsingContexts(parsing bool)

Add method to set context parsing state

func (*Lexer) SetParsingJsonData added in v0.15.2

func (l *Lexer) SetParsingJsonData(parsing bool)

Add method to set JSON data parsing state

type MatchClause

type MatchClause struct {
	Nodes         []*NodePattern
	Relationships []*Relationship
	ExtraFilters  []*KeyValuePair
}

MatchClause represents a MATCH clause

type MatchCriterion

type MatchCriterion struct {
	FieldA         string         `yaml:"fieldA"`
	FieldB         string         `yaml:"fieldB"`
	ComparisonType ComparisonType `yaml:"comparisonType"`
	DefaultProps   []DefaultProp  `yaml:"defaultProps,omitempty"`
}

type Node

type Node struct {
	Id        string
	Kind      string
	Name      string
	Namespace string
}

type NodePattern

type NodePattern struct {
	ResourceProperties *ResourceProperties
}

NodePattern represents a node pattern in a query

type NodeRelationshipList

type NodeRelationshipList struct {
	Nodes         []*NodePattern
	Relationships []*Relationship
}

NodeRelationshipList represents a list of nodes and relationships

type Parser

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

func NewRecursiveParser

func NewRecursiveParser(input string) *Parser

func (*Parser) Parse

func (p *Parser) Parse() (*Expression, error)

Parse is the entry point for parsing a Cyphernetes query

type Properties

type Properties struct {
	PropertyList []*Property
}

Properties represents a collection of properties

type Property

type Property struct {
	Key   string
	Value interface{}
}

Property represents a key-value property

type QueryExecutor

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

func GetContextQueryExecutor

func GetContextQueryExecutor(context string) (*QueryExecutor, error)

func GetQueryExecutorInstance

func GetQueryExecutorInstance(p provider.Provider) *QueryExecutor

func NewQueryExecutor

func NewQueryExecutor(p provider.Provider) (*QueryExecutor, error)

func (*QueryExecutor) Execute

func (q *QueryExecutor) Execute(ast *Expression, namespace string) (QueryResult, error)

func (*QueryExecutor) ExecuteSingleQuery

func (q *QueryExecutor) ExecuteSingleQuery(ast *Expression, namespace string) (QueryResult, error)

func (*QueryExecutor) GetOpenAPIResourceSpecs

func (q *QueryExecutor) GetOpenAPIResourceSpecs() (map[string][]string, error)

func (*QueryExecutor) PatchK8sResource

func (q *QueryExecutor) PatchK8sResource(resource map[string]interface{}, patchJSON []byte) error

func (*QueryExecutor) Provider

func (q *QueryExecutor) Provider() provider.Provider

type QueryResult

type QueryResult struct {
	Data  map[string]interface{}
	Graph Graph
}

func ExecuteMultiContextQuery

func ExecuteMultiContextQuery(ast *Expression, namespace string) (QueryResult, error)

type Relationship

type Relationship struct {
	ResourceProperties *ResourceProperties
	Direction          Direction
	LeftNode           *NodePattern
	RightNode          *NodePattern
}

Relationship represents a relationship between nodes

type RelationshipRule

type RelationshipRule struct {
	KindA         string           `yaml:"kindA"`
	KindB         string           `yaml:"kindB"`
	Relationship  RelationshipType `yaml:"relationship"`
	MatchCriteria []MatchCriterion `yaml:"matchCriteria"`
}

func GetRelationshipRules

func GetRelationshipRules() []RelationshipRule

type RelationshipType

type RelationshipType string
const (
	DeploymentOwnReplicaset        RelationshipType = "DEPLOYMENT_OWN_REPLICASET"
	ReplicasetOwnPod               RelationshipType = "REPLICASET_OWN_POD"
	StatefulsetOwnPod              RelationshipType = "STATEFULSET_OWN_POD"
	DaemonsetOwnPod                RelationshipType = "DAEMONSET_OWN_POD"
	JobOwnPod                      RelationshipType = "JOB_OWN_POD"
	ServiceExposePod               RelationshipType = "SERVICE_EXPOSE_POD"
	ServiceExposeDeployment        RelationshipType = "SERVICE_EXPOSE_DEPLOYMENT"
	ServiceExposeStatefulset       RelationshipType = "SERVICE_EXPOSE_STATEFULSET"
	ServiceExposeDaemonset         RelationshipType = "SERVICE_EXPOSE_DAEMONSET"
	ServiceExposeReplicaset        RelationshipType = "SERVICE_EXPOSE_REPLICASET"
	CronJobOwnPod                  RelationshipType = "CRONJOB_OWN_POD"
	CronJobOwnJob                  RelationshipType = "CRONJOB_OWN_JOB"
	ServiceHasEndpoints            RelationshipType = "SERVICE_HAS_ENDPOINTS"
	NetworkPolicyApplyPod          RelationshipType = "NETWORKPOLICY_APPLY_POD"
	HPAScaleDeployment             RelationshipType = "HPA_SCALE_DEPLOYMENT"
	RoleBindingReferenceRole       RelationshipType = "ROLEBINDING_REFERENCE_ROLE"
	MutatingWebhookTargetService   RelationshipType = "MUTATINGWEBHOOK_TARGET_SERVICE"
	ValidatingWebhookTargetService RelationshipType = "VALIDATINGWEBHOOK_TARGET_SERVICE"
	PDBProtectPod                  RelationshipType = "PDB_PROTECT_POD"
	// ingresses to services
	Route RelationshipType = "ROUTE"

	// special relationships
	NamespaceHasResource RelationshipType = "NAMESPACE_HAS_RESOURCE"
)

type ResourceProperties

type ResourceProperties struct {
	Name       string
	Kind       string
	Properties *Properties
	JsonData   string
}

ResourceProperties represents the properties of a resource

type ResourceRelationship

type ResourceRelationship struct {
	FromKind string
	ToKind   string
	Type     RelationshipType
}

type ReturnClause

type ReturnClause struct {
	Items []*ReturnItem
}

ReturnClause represents a RETURN clause

type ReturnItem

type ReturnItem struct {
	JsonPath  string
	Alias     string
	Aggregate string
}

ReturnItem represents an item in a RETURN clause

type SetClause

type SetClause struct {
	KeyValuePairs []*KeyValuePair
}

SetClause represents a SET clause

type Token

type Token struct {
	Type    TokenType
	Literal string
}

Token represents a lexical token

type TokenType

type TokenType int

TokenType represents the type of a lexical token

const (
	ILLEGAL TokenType = iota
	EOF
	NULL

	// Keywords
	MATCH
	CREATE
	WHERE
	SET
	DELETE
	RETURN
	IN
	AS

	// Identifiers and literals
	IDENT
	STRING
	INT
	NUMBER
	BOOLEAN
	JSONPATH
	JSONDATA

	// Delimiters
	LPAREN   // (
	RPAREN   // )
	LBRACE   // {
	RBRACE   // }
	LBRACKET // [
	RBRACKET // ]
	COLON    // :
	COMMA    // ,
	DOT      // .

	// Operators
	EQUALS
	NOT_EQUALS
	GREATER_THAN
	LESS_THAN
	GREATER_THAN_EQUALS
	LESS_THAN_EQUALS
	CONTAINS
	REGEX_COMPARE

	// Relationship tokens
	REL_NOPROPS_RIGHT
	REL_NOPROPS_LEFT
	REL_NOPROPS_BOTH
	REL_NOPROPS_NONE
	REL_BEGINPROPS_LEFT
	REL_BEGINPROPS_NONE
	REL_ENDPROPS_RIGHT
	REL_ENDPROPS_NONE

	// Aggregation functions
	COUNT
	SUM
)

Jump to

Keyboard shortcuts

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