modconfig

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockTypeMod       ModBlockType = "mod"
	BlockTypeQuery                  = "query"
	BlockTypeControl                = "control"
	BlockTypeBenchmark              = "benchmark"
	BlockTypeLocals                 = "locals"
)

Variables

View Source
var ResourceTypeMap = map[string]factoryFunc{
	constants.SqlExtension: func(modPath, filePath string) (MappableResource, []byte, error) {
		return QueryFromFile(modPath, filePath)
	},
}

Functions

func BuildModResourceName added in v0.5.0

func BuildModResourceName(blockType ModBlockType, name string) string

func GetCtyTypes added in v0.5.0

func GetCtyTypes(item interface{}) map[string]cty.Type

GetCtyTypes builds a map of cty types for all tagged properties. It is used to convert the struct to a cty value

func PropertyPathToResourceName added in v0.5.0

func PropertyPathToResourceName(propertyPath string) (string, error)

func PseudoResourceNameFromPath

func PseudoResourceNameFromPath(modPath, filePath string) (string, error)

PseudoResourceNameFromPath converts a filepath into a resource name

It operates as follows:

  1. get filename
  2. remove extension
  3. sluggify, with '_' as the divider

func RegisteredFileExtensions

func RegisteredFileExtensions() []string

Types

type Benchmark added in v0.5.0

type Benchmark struct {
	ShortName string
	FullName  string `cty:"name"`

	ChildNames    *[]NamedItem       `cty:"children" hcl:"children"`
	Description   *string            `cty:"description" hcl:"description" column:"description,text"`
	Documentation *string            `cty:"documentation" hcl:"documentation" column:"documentation,text"`
	Tags          *map[string]string `cty:"tags" hcl:"tags" column:"tags,jsonb"`
	Title         *string            `cty:"title" hcl:"title" column:"title,text"`

	// list of all block referenced by the resource
	References []string `column:"refs,jsonb"`

	ChildNameStrings []string `column:"children,jsonb"`
	DeclRange        hcl.Range
	// contains filtered or unexported fields
}

Benchmark is a struct representing the Benchmark resource

func NewBenchmark added in v0.5.0

func NewBenchmark(block *hcl.Block) *Benchmark

func (*Benchmark) AddChild added in v0.5.0

func (b *Benchmark) AddChild(child ControlTreeItem) error

AddChild implements ControlTreeItem

func (*Benchmark) AddParent added in v0.5.0

func (b *Benchmark) AddParent(parent ControlTreeItem) error

AddParent implements ControlTreeItem

func (*Benchmark) AddReference added in v0.5.0

func (b *Benchmark) AddReference(reference string)

AddReference implements HclResource

func (*Benchmark) CtyValue added in v0.5.0

func (b *Benchmark) CtyValue() (cty.Value, error)

CtyValue implements HclResource

func (*Benchmark) GetChildControls added in v0.5.0

func (b *Benchmark) GetChildControls() []*Control

GetChildControls return a flat list of controls underneath the benchmark in the tree

func (*Benchmark) GetChildren added in v0.5.0

func (b *Benchmark) GetChildren() []ControlTreeItem

GetChildren implements ControlTreeItem

func (*Benchmark) GetDescription added in v0.5.0

func (b *Benchmark) GetDescription() string

GetDescription implements ControlTreeItem

func (*Benchmark) GetMetadata added in v0.5.0

func (b *Benchmark) GetMetadata() *ResourceMetadata

GetMetadata implements ResourceWithMetadata

func (*Benchmark) GetParents added in v0.5.0

func (b *Benchmark) GetParents() []ControlTreeItem

GetParents implements ControlTreeItem

func (*Benchmark) GetTags added in v0.5.0

func (b *Benchmark) GetTags() map[string]string

GetTags implements ControlTreeItem

func (*Benchmark) GetTitle added in v0.5.0

func (b *Benchmark) GetTitle() string

GetTitle implements ControlTreeItem

func (*Benchmark) Name added in v0.5.0

func (b *Benchmark) Name() string

Name implements ControlTreeItem, HclResource, ResourceWithMetadata return name in format: 'control.<shortName>'

func (*Benchmark) OnDecoded added in v0.5.0

func (b *Benchmark) OnDecoded(*hcl.Block)

OnDecoded implements HclResource

func (*Benchmark) Path added in v0.5.0

func (b *Benchmark) Path() []string

Path implements ControlTreeItem TODO is this needed - if so it needs to be an array

func (*Benchmark) QualifiedName added in v0.5.0

func (b *Benchmark) QualifiedName() string

QualifiedName returns the name in format: '<modName>.control.<shortName>'

func (*Benchmark) SetMetadata added in v0.5.0

func (b *Benchmark) SetMetadata(metadata *ResourceMetadata)

SetMetadata implements ResourceWithMetadata

func (*Benchmark) String added in v0.5.0

func (b *Benchmark) String() string

type Connection added in v0.5.0

type Connection struct {
	// connection name
	Name string
	// Name of plugin
	Plugin string
	// unparsed HCL of plugin specific connection config
	Config string

	// options
	Options *options.Connection
}

Connection is a struct representing the partially parsed connection

(Partial as the connection config, which is plugin specific, is stored as raw HCL. This will be parsed by the plugin)

func (*Connection) SetOptions added in v0.5.0

func (c *Connection) SetOptions(opts options.Options, block *hcl.Block) hcl.Diagnostics

SetOptions sets the options on the connection verify the options object is a valid options type (only options.Connection currently supported)

func (*Connection) String added in v0.5.0

func (c *Connection) String() string

type Control added in v0.5.0

type Control struct {
	ShortName        string             `json:"-"`
	FullName         string             `cty:"name" json:"control_id"`
	Description      *string            `cty:"description" hcl:"description" column:"description,text" json:"description"`
	Documentation    *string            `cty:"documentation" hcl:"documentation" column:"documentation,text" json:"-"`
	SearchPath       *string            `cty:"search_path" hcl:"search_path" column:"search_path,text"`
	SearchPathPrefix *string            `cty:"search_path_prefix" hcl:"search_path_prefix" column:"search_path_prefix,text"`
	Severity         *string            `cty:"severity" hcl:"severity" column:"severity,text" json:"severity"`
	SQL              *string            `cty:"sql" hcl:"sql" column:"sql,text" json:"-"`
	Tags             *map[string]string `cty:"tags" hcl:"tags" column:"tags,jsonb" json:"tags"`
	Title            *string            `cty:"title" hcl:"title" column:"title,text"`

	// list of all block referenced by the resource
	References []string `column:"refs,jsonb"`

	DeclRange hcl.Range
	// contains filtered or unexported fields
}

Control is a struct representing the Control resource

func NewControl added in v0.5.0

func NewControl(block *hcl.Block) *Control

func (*Control) AddChild added in v0.5.0

func (c *Control) AddChild(child ControlTreeItem) error

AddChild implements ControlTreeItem - controls cannot have children so just return error

func (*Control) AddParent added in v0.5.0

func (c *Control) AddParent(parent ControlTreeItem) error

AddParent implements ControlTreeItem

func (*Control) AddReference added in v0.5.0

func (c *Control) AddReference(reference string)

AddReference implements HclResource

func (*Control) CtyValue added in v0.5.0

func (c *Control) CtyValue() (cty.Value, error)

func (*Control) GetChildren added in v0.5.0

func (m *Control) GetChildren() []ControlTreeItem

GetChildren implements ControlTreeItem

func (*Control) GetDescription added in v0.5.0

func (m *Control) GetDescription() string

GetDescription implements ControlTreeItem

func (*Control) GetMetadata added in v0.5.0

func (c *Control) GetMetadata() *ResourceMetadata

GetMetadata implements HclResource

func (*Control) GetParentNames added in v0.5.0

func (c *Control) GetParentNames() []string

func (*Control) GetParents added in v0.5.0

func (c *Control) GetParents() []ControlTreeItem

GetParents implements ControlTreeItem

func (*Control) GetTags added in v0.5.0

func (m *Control) GetTags() map[string]string

GetTags implements ControlTreeItem

func (*Control) GetTitle added in v0.5.0

func (m *Control) GetTitle() string

GetTitle implements ControlTreeItem

func (*Control) Name added in v0.5.0

func (c *Control) Name() string

Name implements ControlTreeItem, HclResource return name in format: 'control.<shortName>'

func (*Control) OnDecoded added in v0.5.0

func (c *Control) OnDecoded(*hcl.Block)

OnDecoded implements HclResource

func (*Control) Path added in v0.5.0

func (c *Control) Path() []string

Path implements ControlTreeItem

func (*Control) QualifiedName added in v0.5.0

func (c *Control) QualifiedName() string

QualifiedName returns the name in format: '<modName>.control.<shortName>'

func (*Control) SetMetadata added in v0.5.0

func (c *Control) SetMetadata(metadata *ResourceMetadata)

SetMetadata implements ResourceWithMetadata

func (*Control) String added in v0.5.0

func (c *Control) String() string

type ControlTreeItem added in v0.5.0

type ControlTreeItem interface {
	AddParent(ControlTreeItem) error
	AddChild(child ControlTreeItem) error
	Name() string
	GetTitle() string
	GetDescription() string
	GetTags() map[string]string
	GetChildren() []ControlTreeItem
	// Path returns an array of parents in the control hierarchy
	Path() []string
}

ControlTreeItem must be implemented by elements of the control hierararchy i.e. Control and Benchmark

type HclResource added in v0.5.0

type HclResource interface {
	Name() string
	CtyValue() (cty.Value, error)
	OnDecoded(*hcl.Block)
	AddReference(reference string)
}

HclResource must be implemented by resources defined in HCL

type Local added in v0.5.0

type Local struct {
	ShortName string
	FullName  string `cty:"name"`

	Value     cty.Value
	DeclRange hcl.Range
	// contains filtered or unexported fields
}

Local is a struct representing a Local resource

func NewLocal added in v0.5.0

func NewLocal(name string, val cty.Value, declRange hcl.Range) *Local

func (*Local) AddReference added in v0.5.0

func (l *Local) AddReference(string)

AddReference implements HclResource

func (*Local) CtyValue added in v0.5.0

func (l *Local) CtyValue() (cty.Value, error)

CtyValue implements HclResource

func (*Local) GetMetadata added in v0.5.0

func (l *Local) GetMetadata() *ResourceMetadata

GetMetadata implements ResourceWithMetadata

func (*Local) Name added in v0.5.0

func (l *Local) Name() string

Name implements HclResource, ResourceWithMetadata

func (*Local) OnDecoded added in v0.5.0

func (l *Local) OnDecoded(*hcl.Block)

OnDecoded implements HclResource

func (*Local) SetMetadata added in v0.5.0

func (l *Local) SetMetadata(metadata *ResourceMetadata)

SetMetadata implements ResourceWithMetadata

type MappableResource

type MappableResource interface {
	// InitialiseFromFile creates a mappable resource from a file path
	// It returns the resource, and the raw file data
	InitialiseFromFile(modPath, filePath string) (MappableResource, []byte, error)
	Name() string

	GetMetadata() *ResourceMetadata
	SetMetadata(*ResourceMetadata)
}

MappableResource must be implemented by resources which can be created directly from a content file (e.g. sql, markdown)

func QueryFromFile

func QueryFromFile(modPath, filePath string) (MappableResource, []byte, error)

QueryFromFile :: factory function

type Mod

type Mod struct {
	ShortName string `hcl:"name,label"`
	FullName  string `cty:"name"`

	// attributes
	Categories    *[]string          `cty:"categories" hcl:"categories" column:"categories,jsonb"`
	Color         *string            `cty:"color" hcl:"color" column:"color,text"`
	Description   *string            `cty:"description" hcl:"description" column:"description,text"`
	Documentation *string            `cty:"documentation" hcl:"documentation" column:"documentation,text"`
	Icon          *string            `cty:"icon" hcl:"icon" column:"icon,text"`
	Tags          *map[string]string `cty:"tags" hcl:"tags" column:"tags,jsonb"`
	Title         *string            `cty:"title" hcl:"title" column:"title,text"`

	// list of all block referenced by the resource
	References []string `column:"refs,jsonb"`

	// blocks
	Requires  *Requires  `hcl:"requires,block"`
	OpenGraph *OpenGraph `hcl:"opengraph,block"`

	// TODO do we need this?
	Version *string

	Queries    map[string]*Query
	Controls   map[string]*Control
	Benchmarks map[string]*Benchmark

	ModPath   string
	DeclRange hcl.Range
	// contains filtered or unexported fields
}

Mod is a struct representing a Mod resource

func CreateDefaultMod added in v0.5.0

func CreateDefaultMod(modPath string) *Mod

CreateDefaultMod creates a default mod created for a workspace with no mod definition

func NewMod added in v0.5.0

func NewMod(shortName, modPath string, defRange hcl.Range) *Mod

func (*Mod) AddChild added in v0.5.0

func (m *Mod) AddChild(child ControlTreeItem) error

AddChild implements ControlTreeItem

func (*Mod) AddParent added in v0.5.0

func (m *Mod) AddParent(ControlTreeItem) error

AddParent implements ControlTreeItem

func (*Mod) AddPseudoResource added in v0.5.0

func (m *Mod) AddPseudoResource(resource MappableResource)

AddPseudoResource adds the pseudo resource to the mod, as long as there is no existing resource of same name

A pseudo resource ids a resource created by loading a content file (e.g. a SQL file), rather than parsing a HCL defintion

func (*Mod) AddReference added in v0.5.0

func (m *Mod) AddReference(reference string)

AddReference implements HclResource

func (*Mod) AddResource added in v0.5.0

func (m *Mod) AddResource(item HclResource, block *hcl.Block) hcl.Diagnostics

func (*Mod) BuildControlTree added in v0.5.0

func (m *Mod) BuildControlTree() error

BuildControlTree builds the control tree structure by setting the parent property for each control and benchmar NOTE: this also builds the sorted benchmark list

func (*Mod) CtyValue added in v0.5.0

func (m *Mod) CtyValue() (cty.Value, error)

func (*Mod) GetChildControls added in v0.5.0

func (m *Mod) GetChildControls() []*Control

GetChildControls return a flat list of controls underneath the mod

func (*Mod) GetChildren added in v0.5.0

func (m *Mod) GetChildren() []ControlTreeItem

GetChildren implements ControlTreeItem

func (*Mod) GetDescription added in v0.5.0

func (m *Mod) GetDescription() string

GetDescription implements ControlTreeItem

func (*Mod) GetMetadata added in v0.5.0

func (m *Mod) GetMetadata() *ResourceMetadata

GetMetadata implements HclResource

func (*Mod) GetParents added in v0.5.0

func (c *Mod) GetParents() []ControlTreeItem

GetParents implements ControlTreeItem

func (*Mod) GetTags added in v0.5.0

func (m *Mod) GetTags() map[string]string

GetTags implements ControlTreeItem

func (*Mod) GetTitle added in v0.5.0

func (m *Mod) GetTitle() string

GetTitle implements ControlTreeItem

func (*Mod) IsControlTreeItem added in v0.5.0

func (m *Mod) IsControlTreeItem()

IsControlTreeItem implements ControlTreeItem (mod is always top of the tree)

func (*Mod) IsDefaultMod added in v0.5.0

func (m *Mod) IsDefaultMod() bool

IsDefaultMod returns whether this mod is a default mod created for a workspace with no mod definition

func (*Mod) Name

func (m *Mod) Name() string

Name implements ControlTreeItem, HclResource

func (*Mod) OnDecoded added in v0.5.0

func (m *Mod) OnDecoded(*hcl.Block)

OnDecoded implements HclResource

func (*Mod) Path added in v0.5.0

func (m *Mod) Path() []string

Path implements ControlTreeItem

func (*Mod) SetMetadata added in v0.5.0

func (m *Mod) SetMetadata(metadata *ResourceMetadata)

SetMetadata implements ResourceWithMetadata

func (*Mod) String

func (m *Mod) String() string

type ModBlockType added in v0.5.0

type ModBlockType string

type ModMap

type ModMap map[string]*Mod

ModMap is a map of mod name to mod-version

func (ModMap) String

func (m ModMap) String() string

type ModVersion

type ModVersion struct {
	// the fully qualified mod name, e.g. github.com/turbot/mod1
	// TODO THINK ABOUT NAMES
	ShortName string `hcl:"name,label"`
	FullName  string `cty:"name"`

	Version   string  `cty:"version" hcl:"version"`
	Alias     *string `cty:"alias" hcl:"alias,optional"`
	DeclRange hcl.Range
}

func (*ModVersion) HasVersion

func (m *ModVersion) HasVersion() bool

HasVersion returns whether the mod has a version specified, or is the latest if no version is specified, or the version is "latest", this is the latest version

func (*ModVersion) Name

func (m *ModVersion) Name() string

Name returns Name@Version

func (*ModVersion) String

func (m *ModVersion) String() string

type NamedItem added in v0.5.0

type NamedItem struct {
	Name string `cty:"name"`
}

func (NamedItem) String added in v0.5.0

func (c NamedItem) String() string

type OpenGraph added in v0.5.0

type OpenGraph struct {
	// The opengraph description (og:description) of the mod, for use in social media applications
	Description string `cty:"description" hcl:"description"`
	// The opengraph display title (og:title) of the mod, for use in social media applications.
	Title     string  `cty:"title" hcl:"title"`
	Image     *string `cty:"image" hcl:"image"`
	DeclRange hcl.Range
}

OpenGraph is a struct representing the OpenGraph group mod resource

type ParsedPropertyPath added in v0.5.0

type ParsedPropertyPath struct {
	Mod          string
	ItemType     ModBlockType
	Name         string
	PropertyPath []string
}

func ParseResourcePropertyPath added in v0.5.0

func ParseResourcePropertyPath(propertyPath string) (res *ParsedPropertyPath, err error)

type ParsedResourceName added in v0.5.0

type ParsedResourceName struct {
	Mod      string
	ItemType ModBlockType
	Name     string
}

func ParseResourceName added in v0.5.0

func ParseResourceName(fullName string) (res *ParsedResourceName, err error)

func (*ParsedResourceName) TypeString added in v0.5.0

func (m *ParsedResourceName) TypeString() string

type PluginVersion added in v0.5.0

type PluginVersion struct {
	// the fully qualified plugin name, e.g. github.com/turbot/mod1
	Name string `cty:"name" hcl:"name,label"`
	// the version STREAM, can be either a major or minor version stream i.e. 1 or 1.1
	Version   string `cty:"version" hcl:"version,optional"`
	DeclRange hcl.Range
}

func (*PluginVersion) FullName added in v0.5.0

func (p *PluginVersion) FullName() string

func (*PluginVersion) String added in v0.5.0

func (p *PluginVersion) String() string

type Query

type Query struct {
	ShortName string
	FullName  string `cty:"name"`

	Description      *string            `cty:"description" hcl:"description" column:"description,text"`
	Documentation    *string            `cty:"documentation" hcl:"documentation" column:"documentation,text"`
	Tags             *map[string]string `cty:"tags" hcl:"tags" column:"tags,jsonb"`
	SQL              *string            `cty:"sql" hcl:"sql" column:"sql,text"`
	SearchPath       *string            `cty:"search_path" hcl:"search_path" column:"search_path,text"`
	SearchPathPrefix *string            `cty:"search_path_prefix" hcl:"search_path_prefix" column:"search_path_prefix,text"`
	Title            *string            `cty:"title" hcl:"title" column:"title,text"`

	// list of all block referenced by the resource
	References []string `column:"refs,jsonb"`

	DeclRange hcl.Range
	// contains filtered or unexported fields
}

Query is a struct representing the Query resource

func NewQuery added in v0.5.0

func NewQuery(block *hcl.Block) *Query

func (*Query) AddReference added in v0.5.0

func (q *Query) AddReference(reference string)

AddReference implements HclResource

func (*Query) CtyValue added in v0.5.0

func (q *Query) CtyValue() (cty.Value, error)

func (*Query) GetMetadata added in v0.5.0

func (q *Query) GetMetadata() *ResourceMetadata

GetMetadata implements HclResource and MappableResource

func (*Query) InitialiseFromFile

func (q *Query) InitialiseFromFile(modPath, filePath string) (MappableResource, []byte, error)

InitialiseFromFile implements MappableResource

func (*Query) Name

func (q *Query) Name() string

Name implements MappableResource, HclResource

func (*Query) OnDecoded added in v0.5.0

func (q *Query) OnDecoded(*hcl.Block)

OnDecoded implements HclResource

func (*Query) QualifiedName added in v0.5.0

func (q *Query) QualifiedName() string

QualifiedName returns the name in format: '<modName>.control.<shortName>'

func (*Query) SetMetadata added in v0.5.0

func (q *Query) SetMetadata(metadata *ResourceMetadata)

SetMetadata implements MappableResource, HclResource

func (*Query) String

func (q *Query) String() string

type Requires added in v0.5.0

type Requires struct {
	Steampipe string           `hcl:"steampipe,optional"`
	Plugins   []*PluginVersion `hcl:"plugin,block"`
	Mods      []*ModVersion    `hcl:"mod,block"`
	DeclRange hcl.Range
}

Requires is a struct representing mod dependencies

type ResourceMetadata added in v0.5.0

type ResourceMetadata struct {
	ResourceName string `column:"resource_name,text"`
	// mod name in the format mod.<modName>@<version?
	ModName          string `column:"mod_name,text"`
	FileName         string `column:"file_name,text"`
	StartLineNumber  int    `column:"start_line_number,integer"`
	EndLineNumber    int    `column:"end_line_number,integer"`
	IsAutoGenerated  bool   `column:"auto_generated,bool"`
	SourceDefinition string `column:"source_definition,text"`

	// mod short name
	ModShortName string
}

ResourceMetadata ius a struct containing additional data about each resource, used to populate the reflection tables

func (*ResourceMetadata) SetMod added in v0.5.0

func (m *ResourceMetadata) SetMod(mod *Mod)

SetMod sets the mod name and mod short name

type ResourceWithMetadata added in v0.5.0

type ResourceWithMetadata interface {
	Name() string
	GetMetadata() *ResourceMetadata
	SetMetadata(metadata *ResourceMetadata)
}

ResourceWithMetadata must be implenented by resources which supports reflection metadata

type WorkspaceResourceMaps added in v0.5.0

type WorkspaceResourceMaps struct {
	ModMap       map[string]*Mod
	QueryMap     map[string]*Query
	ControlMap   map[string]*Control
	BenchmarkMap map[string]*Benchmark
}

WorkspaceResourceMaps is a struct containing maps of all mod resource types This is provided to avoid db needing to reference workspace package

Jump to

Keyboard shortcuts

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