objects

package
v0.0.0-...-c28e91b Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 4 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseObject

type BaseObject struct {
	Label string `json:"label" yaml:"label"`
	Type  string `json:"type" yaml:"type"`
}

BaseObject is the "base" struct for all objects in ToDD. All metadata shared by all todd objects should be stored here. Any structs representing todd objects should embed this struct.

Generally, since the "Type" field is present in the "parent", or embedded struct, it is appropriate to first unmarshal YAML or JSON into the base "ToddObject" struct first, to determine type. Then, this value is used to determine which "child" struct should be used to parse the entire structure, using a "switch" statement, we'll call a "type switch".

The process for adding a new object type in ToDD should be done in 3 places:

- Here, a new struct that embeds ToddObject should be added. - The "switch" statement in the ParseToddObject and ParseToddObjects functions below should be augmented to look for the new object type for an incoming YAML file - The "Create" function in the client api contains a "type switch" - update this.

It should be mentioned that the steps above only add a new object type to the various infrastructure elements of ToDD - it does not automatically give those objects meaning.

func (BaseObject) GetLabel

func (b BaseObject) GetLabel() string

GetLabel is a simple function to return the "Label" attribute of a BaseObject struct (or any struct that embeds it). It is necessary for portions of the code that only have a handle on the ToddObject interface, and need to access these properties

func (BaseObject) GetType

func (b BaseObject) GetType() string

GetType is a simple function to return the "Type" attribute of a BaseObject struct (or any struct that embeds it). It is necessary for portions of the code that only have a handle on the ToddObject interface, and need to access these properties

func (BaseObject) ParseToddObject

func (b BaseObject) ParseToddObject(objJSON []byte) ToddObject

ParseToddObject centralizes the logic of generating a specific ToDD object off of an existing base struct. Whenever you need to parse a specific ToDD object in the codebase, you should first Unmarshal into the BaseObject struct. Once you have a handle on that, run this struct method, and pass in the original JSON (the "obj_json" param). This will identify the specific type and return that struct to you. TODO(mierdin): Need a better name for this. Change it, then make sure you're replacing all instances of the old name in this file (in several comments)

type GroupObject

type GroupObject struct {
	BaseObject `yaml:",inline"` // the ",inline" tag is necessary for the go-yaml package to properly see the outer struct fields
	Spec       struct {
		Group   string              `json:"group" yaml:"group"`
		Matches []map[string]string `json:"matches" yaml:"matches"`
	} `json:"spec" yaml:"spec"`
}

GroupObject is a specific implementation of BaseObject. It represents the "group" object in ToDD - which stores specific rules that are used when grouping agents together prior to running a test

func (GroupObject) GetSpec

func (g GroupObject) GetSpec() string

GetSpec is a simple function to return the "Spec" attribute of a GroupObject

type TestRunObject

type TestRunObject struct {
	BaseObject `yaml:",inline"` // the ",inline" tag is necessary for the go-yaml package to properly see the outer struct fields
	Spec       struct {
		TargetType string            `json:"targettype" yaml:"targettype"`
		Source     map[string]string `json:"source" yaml:"source"`
		Target     interface{}       `json:"target" yaml:"target"` // This is an empty interface because targettype of "group" uses this as a map, targettype of "uncontrolled" uses this as a slice.

	} `json:"spec" yaml:"spec"`
}

TestRunObject is a specific implementation of BaseObject. It represents the "testrun" object in ToDD, which is a set of parameters under which a test should be run

func (TestRunObject) GetSpec

func (t TestRunObject) GetSpec() string

GetSpec is a simple function to return the "Spec" attribute of a TestRunObject

type ToddObject

type ToddObject interface {
	GetType() string
	GetLabel() string
	GetSpec() string
	ParseToddObject([]byte) ToddObject
}

ToddObject is an interface that describes all ToDD Objects. You will see this interface referenced in all functions that get, set, or delete ToDD objects.

func ParseToddObjects

func ParseToddObjects(objJSON []byte) []ToddObject

ParseToddObjects is similar to the struct ParseToddObject method but is intended to be used when you know the JSON houses a slice/list of Todd Objects. As a result, it will also return a slice of ToddObjects. TODO(mierdin): This function is still fairly inflexible, as it assumes that all objects in the JSON are of the same type. Currently, this is a safe bet because the objects API doesn't currently support returning all objects, so they will all be the same type. However, if that changes in the future, this function will have to be refactored.

Jump to

Keyboard shortcuts

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