parser

package
v0.1.58 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2021 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// values
	Slice    = "slice"
	NonSlice = "nonSlice"
	// errors
	ErrJSONMarshal       = "cannot marshal JSON object"
	ErrJSONCompare       = "cannot compare JSON objects"
	ErrJSONMarshalIndent = "cannot marshal JSON object with indent"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigTreeAction added in v0.1.4

type ConfigTreeAction string

ConfigTreeAction defines the states the resource object is reporting

const (
	ConfigTreeActionGet    ConfigTreeAction = "get"
	ConfigTreeActionDelete ConfigTreeAction = "delete"
	ConfigTreeActionCreate ConfigTreeAction = "create"
	ConfigTreeActionUpdate ConfigTreeAction = "update"
	ConfigTreeActionFind   ConfigTreeAction = "find"
	ConfigResolveLeafRef   ConfigTreeAction = "resolve leafref"
)

func (*ConfigTreeAction) String added in v0.1.4

func (c *ConfigTreeAction) String() string

type LeafRef added in v0.1.42

type LeafRef struct {
	LocalPath  *config.Path `json:"localPath,omitempty"`
	RemotePath *config.Path `json:"remotePath,omitempty"`
}

type LeafRefValidationKind added in v0.1.57

type LeafRefValidationKind string
const (
	LeafRefValidationLocal    LeafRefValidationKind = "local"
	LeafRefValidationExternal LeafRefValidationKind = "external"
)

type Operation added in v0.1.58

type Operation struct {
	Type  OperationType
	Path  string
	Value interface{}
}

type OperationType added in v0.1.58

type OperationType string

A OperationType represents an operatio on a JSON resource

const (
	// delete
	OperationTypeDelete OperationType = "Delete"
	// replace
	OperationTypeUpdate OperationType = "Update"
	// create
	OperationTypeCreate OperationType = "Create"
)

Condition Kinds.

type Option

type Option func(p *Parser)

Option can be used to manipulate Options.

func WithLogger

func WithLogger(log logging.Logger) Option

WithLogger specifies how the Parser should log messages.

type Parser

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

func NewParser

func NewParser(opts ...Option) *Parser

func (*Parser) AddJSONDataToList added in v0.1.15

func (p *Parser) AddJSONDataToList(x interface{}) (interface{}, error)

AddJSONDataToList adds the JSON data to a list

func (*Parser) AppendElemInPath added in v0.1.7

func (p *Parser) AppendElemInPath(path *config.Path, name, key string) *config.Path

AppendElemInPath adds a pathElem to the config gnmi path

func (*Parser) AppendElemInPathWithFullKey added in v0.1.50

func (p *Parser) AppendElemInPathWithFullKey(path *config.Path, name string, key map[string]string) *config.Path

AppendElemInPath adds a pathElem to the config gnmi path

func (*Parser) CleanCacheValueForComparison added in v0.1.7

func (p *Parser) CleanCacheValueForComparison(path *config.Path, cacheValue interface{}, valueType string) (x1 interface{}, err error)

we update the cache value for comparison 1. any map[string]interface{} -> will come from another subscription 2. any key in the path can be removed since this is part of the path iso data comparison 3. if the value is a slice we should remove all strings/int/floats, if the data is not a slice we remove all slices -> the gnmi server splits slice data and non slice data

func (*Parser) CleanConfig added in v0.1.7

func (p *Parser) CleanConfig(x1 map[string]interface{}) map[string]interface{}

func (*Parser) CleanConfig2String added in v0.1.7

func (p *Parser) CleanConfig2String(cfg map[string]interface{}) (map[string]interface{}, *string, error)

CleanConfig2String returns a clean config and a string clean means removing the prefixes in the json elements

func (*Parser) CleanDeviceValueForComparison added in v0.1.7

func (p *Parser) CleanDeviceValueForComparison(deviceValue interface{}) (interface{}, error)

CleanDeviceValueForComparison cleans the data coming from the device it cleans the prefixes of the yang value; key and value

func (*Parser) CompareConfigPathsWithResourceKeys added in v0.1.54

func (p *Parser) CompareConfigPathsWithResourceKeys(path *config.Path, resourceKeys map[string]string) (bool, []*config.Path, map[string]string)

CompareConfigPathsWithResourceKeys returns changed true when resourceKeys were provided and if they are different. In this case the deletePath is also valid, otherwise when changd is false the delete path is not reliable

func (*Parser) CompareJSONData added in v0.1.58

func (p *Parser) CompareJSONData(t, s []byte) ([]Operation, error)

CompareJSONData compares the target with the source and provides operation guides

func (*Parser) CompareValues added in v0.1.7

func (p *Parser) CompareValues(path *config.Path, cacheValue, deviceValue interface{}, valueType string) (jsondiff.Patch, error)

CompareValues compares the 2 values and provides a json diff result

func (*Parser) ConfigGnmiPathToName added in v0.1.7

func (p *Parser) ConfigGnmiPathToName(path *config.Path) string

ConfigGnmiPathToName converts a config gnmi path to a name where each element of the path is seperated by a "-"

func (*Parser) ConfigGnmiPathToXPath added in v0.1.7

func (p *Parser) ConfigGnmiPathToXPath(path *config.Path, keys bool) *string

ConfigGnmiPathToXPath converts a config gnmi path with or withour keys to a string pointer

func (*Parser) ConfigPath2GnmiPath added in v0.1.28

func (p *Parser) ConfigPath2GnmiPath(inPath *config.Path) *gnmi.Path

ConfigPath2GnmiPath converts the config path to gnmi path

func (*Parser) CopyAndCleanTxValues added in v0.1.7

func (p *Parser) CopyAndCleanTxValues(value interface{}) interface{}

func (*Parser) CopyPathElemKey added in v0.1.50

func (p *Parser) CopyPathElemKey(key map[string]string) map[string]string

func (*Parser) CreateContainerEntry added in v0.1.53

func (p *Parser) CreateContainerEntry(e *yang.Entry, next, prev *container.Container) *container.Entry

func (*Parser) CreatePathElem added in v0.1.7

func (p *Parser) CreatePathElem(e *yang.Entry) *config.PathElem

CreatePathElem returns a config path element from a yang Entry

func (*Parser) DeepCopy added in v0.1.7

func (p *Parser) DeepCopy(in interface{}) (interface{}, error)

Make a deep copy from in into out object.

func (*Parser) DeepCopyPath added in v0.1.8

func (p *Parser) DeepCopyPath(in *config.Path) *config.Path

func (*Parser) DeepCopyResolvedLeafRef added in v0.1.42

func (p *Parser) DeepCopyResolvedLeafRef(in *ResolvedLeafRef) (out *ResolvedLeafRef)

func (*Parser) FindResourceDelta added in v0.1.58

func (p *Parser) FindResourceDelta(updatesx1, updatesx2 []*config.Update, log logging.Logger) ([]*config.Path, []*config.Update, error)

func (*Parser) GetKeyInfo added in v0.1.7

func (p *Parser) GetKeyInfo(keys map[string]string) ([]string, []string)

GetKeyInfo returns all keys and values in a []slice

func (*Parser) GetKeyNamesFromConfigPaths added in v0.1.9

func (p *Parser) GetKeyNamesFromConfigPaths(path *config.Path, lastElem string, refPaths []*config.Path) []string

GetKeyNamesFromConfigPaths returns the keyNames for a path based on a reference path list (predetermined path list, coming from yang processing) due to yang processing this should always return keys, if not something was not configured properly

func (*Parser) GetRemotePathsFromResolvedLeafRef added in v0.1.50

func (p *Parser) GetRemotePathsFromResolvedLeafRef(resolvedLeafRef *ResolvedLeafRef) []*config.Path

func (*Parser) GetTypeKind added in v0.1.7

func (p *Parser) GetTypeKind(e *yang.Entry) string

GetTypeKind return a string of the kind of the yang entry

func (*Parser) GetTypeName added in v0.1.7

func (p *Parser) GetTypeName(e *yang.Entry) string

GetypeName return a string of the type of the yang entry

func (*Parser) GetUpdatesFromJSONData added in v0.1.9

func (p *Parser) GetUpdatesFromJSONData(rootPath, path *config.Path, x1 interface{}, refPaths []*config.Path) []*config.Update

GetUpdatesFromJSONData returns config.Updates based on the JSON input data and config.Path/reference Paths These updates are used prepared so they can be send to a GNMI capable device

func (*Parser) GetValue added in v0.1.7

func (p *Parser) GetValue(updValue *gnmi.TypedValue) (interface{}, error)

GetValue return the data of the gnmo typed value

func (*Parser) GetValueType added in v0.1.7

func (p *Parser) GetValueType(value interface{}) string

GetValueType return if a value is a slice or not

func (*Parser) GnmiPath2ConfigPath added in v0.1.7

func (p *Parser) GnmiPath2ConfigPath(inPath *gnmi.Path) *config.Path

GnmiPath2ConfigPath converts the gnmi path to config path

func (*Parser) GnmiPathToXPath added in v0.1.7

func (p *Parser) GnmiPathToXPath(path *gnmi.Path, keys bool) *string

GnmiPathToXPath converts a gnmi path with or withour keys to a string pointer

func (*Parser) HandleEndOfListWithKeyInParseKeyWithAction added in v0.1.42

func (p *Parser) HandleEndOfListWithKeyInParseKeyWithAction(x interface{}, value string, tc *TraceCtxt)

HandleEndOfListWithKeyInParseKeyWithAction is called to assist Get, Create, Delete, Update Action it validates if the value of the JSON object matches the key value of the path

func (*Parser) HandleNotEndOfListWithKeyInParseKeyWithAction added in v0.1.42

func (p *Parser) HandleNotEndOfListWithKeyInParseKeyWithAction(x interface{}, value string, tc *TraceCtxt) bool

HandleNotEndOfListWithKeyInParseKeyWithAction is called to assist Get, Create, Delete, Update Action it validates if the value of the JSON object matches the key value of the path

func (*Parser) ParseJSONData2ConfigUpdates added in v0.1.9

func (p *Parser) ParseJSONData2ConfigUpdates(tc *TraceCtxt, path *config.Path, x1 interface{}, idx int, updates []*config.Update, refPaths []*config.Path) ([]*config.Update, *TraceCtxt)

ParseJSONData2UpdatePaths returns config.Updates according to the gnmi spec based on JSON input data

func (*Parser) ParseTreeWithAction added in v0.1.7

func (p *Parser) ParseTreeWithAction(x1 interface{}, tc *TraceCtxt, idx, lridx int) interface{}

p.ParseTreeWithAction parses various actions on a json object in a recursive way actions can be Get, Update, Delete and Create, LeafRef, Find and LeafRefResolution NOTE1: idx and lridx are indexes that needs to be relevant in the ctxt of the recursive resolution and cannot be put in tc since tc is a global conext NOTE2: ConfigResolveLeafRef is a run to completion and hsould not find a return in the path until the end NOTE3: all other actions are returning something based on the path they traverse

func (*Parser) PopulateLocalLeafRefKey added in v0.1.42

func (p *Parser) PopulateLocalLeafRefKey(x interface{}, tc *TraceCtxt, idx, lridx int)

func (*Parser) PopulateLocalLeafRefValue added in v0.1.42

func (p *Parser) PopulateLocalLeafRefValue(x interface{}, tc *TraceCtxt, idx, lridx int)

PopulateLocalLeafRefValue, populates the values and the keyvalues in the resolved leafref objects

func (*Parser) PopulateRemoteLeafRefKey added in v0.1.43

func (p *Parser) PopulateRemoteLeafRefKey(rlref *ResolvedLeafRef)

Populates the Key of the remote leafref

func (*Parser) PostProcessAugmentValues added in v0.1.41

func (p *Parser) PostProcessAugmentValues(updates []*config.Update, objKeyValues map[int]map[string][]string, objKeyValuesIdx map[int]map[string]int) []*config.Update

func (*Parser) PostProcessUpdates added in v0.1.9

func (p *Parser) PostProcessUpdates(rootPath *config.Path, updates []*config.Update) []*config.Update

the order of the processed paths should remain fixed since this allows to fill out the data ina consistent way First we process the data to capture the values of all resolved keys per pathElem level Second we augment the values with the recorded data from the previous step Lastly we augment the path with the rootPath information

func (*Parser) PostProcessUpdatesCaptureValues added in v0.1.41

func (p *Parser) PostProcessUpdatesCaptureValues(updates []*config.Update) (map[int]map[string][]string, map[int]map[string]int)

PostProcessUpdatesCaptureValues captures the values of all resolved keys per pathElem level map[int]map[string][]string -> map[int -> level in path]map[string -> keyName][]string -> Value

func (*Parser) ProcessLeafRef added in v0.1.7

func (p *Parser) ProcessLeafRef(e *yang.Entry, resfullPath string, activeResPath *config.Path) (*config.Path, *config.Path, bool)

ProcessLeafRef processes the leafref and returns if a leafref localPath, remotePath and if the leafRef is local or external to the resource used for yang parser

func (*Parser) RemoveFirstEntry added in v0.1.7

func (p *Parser) RemoveFirstEntry(s string) string

RemoveFirstEntry removes the first entry of the xpath, so it trims the first element of the /

func (*Parser) RemoveLeafsFromJSONData added in v0.1.14

func (p *Parser) RemoveLeafsFromJSONData(x interface{}, leafStrings []string) interface{}

RemoveLeafsFromJSONData removes the leaf keys from the data

func (*Parser) TransformPathAsRelative2Resource added in v0.1.7

func (p *Parser) TransformPathAsRelative2Resource(localPath, activeResPath *config.Path) *config.Path

TransformPathAsRelative2Resource returns a relative path

func (*Parser) TransformPathToLeafRefPath added in v0.1.7

func (p *Parser) TransformPathToLeafRefPath(path *config.Path) *config.Path

TransformPathToLeafRefPath returns a config gnmi path tailored for leafrefs For a leafRef path the last entry of the name should be a key in the previous element

func (*Parser) ValidateLeafRef added in v0.1.57

func (p *Parser) ValidateLeafRef(kind LeafRefValidationKind, x1, x2 interface{}, definedLeafRefs []*LeafRef, log logging.Logger) (bool, []*ResolvedLeafRef, error)

ValidateLocalLeafRef validates the local leafred information on the local resource data first the local leafrefs are resolved and if they are resolved the remote leaf refs within the objects are located / based on the result this funciton return the result + information on the validation

func (*Parser) ValidateParentDependency added in v0.1.57

func (p *Parser) ValidateParentDependency(x1 interface{}, value string, definedParentDependencies []*LeafRef, log logging.Logger) (bool, []*ResolvedLeafRef, error)

NOT SURE IF A SINGLE VALUE IS SOMETHING THAT WILL BE OK ACCROSS THE BOARD ValidateParentDependency validates the parent resource dependency the remote leaf refs within the objects are located / based on the result this funciton return the result + information on the validation

func (*Parser) XpathToConfigGnmiPath added in v0.1.8

func (p *Parser) XpathToConfigGnmiPath(xpath string, offset int) (path *config.Path)

XpathToGnmiPath convertss a xpath string to a config gnmi path

type ResolvedLeafRef added in v0.1.42

type ResolvedLeafRef struct {
	LocalPath  *config.Path `json:"localPath,omitempty"`
	RemotePath *config.Path `json:"remotePath,omitempty"`
	Value      string       `json:"value,omitempty"`
	Resolved   bool         `json:"resolved,omitempty"`
}

type TraceCtxt added in v0.1.4

type TraceCtxt struct {
	Action           ConfigTreeAction
	Found            bool
	Idx              int
	Path             *config.Path       // the input path data
	ResolvedLeafRefs []*ResolvedLeafRef // holds all the resolved leafRefs if they get resolved
	Data             interface{}
	Value            interface{} // used for leafref resolution
	Msg              []string
}

func (*TraceCtxt) AddMsg added in v0.1.42

func (tc *TraceCtxt) AddMsg(s string)

Jump to

Keyboard shortcuts

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