core

package
v0.0.0-...-ab923f7 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadSwagger

func LoadSwagger(swaggerURI string) (*openapispec.Swagger, error)

LoadSwagger load a certain swagger spec (document) from either file or http

func NormalizeFileRef

func NormalizeFileRef(ref *openapispec.Ref, relativeBase string) *openapispec.Ref

relativeBase could be an ABSOLUTE file path or an ABSOLUTE URL

Types

type SWGGrant

type SWGGrant map[SWGSchemaAddr]SWGSchemaGrant

func NewSWGGrantFromFiles

func NewSWGGrantFromFiles(grantBaseDir string) (SWGGrant, error)

NewSWGGrantFromFiles construct a SWGGrant from a grantBaseDir which contains the folder layout as defined by the SWGSchemaAddr.

type SWGPropertyCoverageStore

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

func NewSWGPropertyCoverageStore

func NewSWGPropertyCoverageStore() SWGPropertyCoverageStore

func (*SWGPropertyCoverageStore) Add

Add adds a SWGSchemaProperty and record the coverage state in each property level. If a property is added more than once, an error will be returned. NOTE: The granted property will be ignored

func (*SWGPropertyCoverageStore) FindCoverage

func (store *SWGPropertyCoverageStore) FindCoverage(propAddr propertyaddr.SwaggerPropertyAddr) (covered, total int, ok bool)

func (*SWGPropertyCoverageStore) SchemaCoverage

func (store *SWGPropertyCoverageStore) SchemaCoverage() (covered, total int)

type SWGSchema

type SWGSchema struct {
	SwaggerRelPath string
	Name           string
	Properties     SWGSchemaProperties

	// Whether this property is granted to be not to implement in Terraform
	IsGranted    bool   `json:",omitempty"`
	GrantComment string `json:",omitempty"`
	// contains filtered or unexported fields
}

func CollectSWGSchemas

func CollectSWGSchemas(swaggerBaseURL, swaggerRelPath string, collector SWGSchemaCollector) ([]SWGSchema, error)

CollectSWGSchemas collects the schemas from a swagger spec

func NewSWGSchema

func NewSWGSchema(swaggerBaseURL, swaggerRelPath string, schemaName string) (*SWGSchema, error)
func (s *SWGSchema) AddTFLink(swgPropAddr propertyaddr.SwaggerPropertyAddr, tfPropAddr propertyaddr.TerraformPropertyAddr) error

func (*SWGSchema) CalcCoverage

func (s *SWGSchema) CalcCoverage() error

CalcCoverage calculates the property coverage (<=1) of the schema/property, and fill in the SWGSchema. Those granted properties are not counted during the calculation.

func (*SWGSchema) ExpandPropertyOneLevelDeep

func (s *SWGSchema) ExpandPropertyOneLevelDeep(addr propertyaddr.SwaggerPropertyAddr) error

ExpandPropertyOneLevelDeep expand the specified swagger schemas property one level deep, with any allOf and $ref taken into consideration.

func (*SWGSchema) FindCoverage

func (s *SWGSchema) FindCoverage(propAddr propertyaddr.SwaggerPropertyAddr) (covered, total int, ok bool)

func (*SWGSchema) SchemaCoverage

func (s *SWGSchema) SchemaCoverage() (covered, total int)

type SWGSchemaAddr

type SWGSchemaAddr string

func NewSWGSchemaAddr

func NewSWGSchemaAddr(swaggerRelPath, schemaName string) SWGSchemaAddr

func (SWGSchemaAddr) SchemaName

func (addr SWGSchemaAddr) SchemaName() string

func (SWGSchemaAddr) SwaggerRelPath

func (addr SWGSchemaAddr) SwaggerRelPath() string

type SWGSchemaCollector

type SWGSchemaCollector func(swagger *openapispec.Swagger) (schemaNames []string)

type SWGSchemaGrant

type SWGSchemaGrant struct {
	// The grant comment why the schema is granted.
	Comment string `json:",omitempty"`

	// Property grant map, whose key is the propertyaddr, whose value is the grant comment.
	Properties map[string]string `json:",omitempty"`
}

func (SWGSchemaGrant) IsSchemaGranted

func (g SWGSchemaGrant) IsSchemaGranted() bool

type SWGSchemaProperties

type SWGSchemaProperties map[string]*SWGSchemaProperty // the key is swagger schemas relative property addr

func NewSWGSchemaProperties

func NewSWGSchemaProperties() SWGSchemaProperties

func (SWGSchemaProperties) Add

type SWGSchemaProperty

type SWGSchemaProperty struct {
	// Terraform property addresses
	TFLinks TFLinks `json:",omitempty"`

	// Whether this property is granted to be not to implement in Terraform
	IsGranted    bool   `json:",omitempty"`
	GrantComment string `json:",omitempty"`
	// contains filtered or unexported fields
}

func NewSWGSchemaProperty

func NewSWGSchemaProperty(schema openapispec.Schema, tflinks []TFLink, resolvedRefs map[string]interface{}, schemaURI string) *SWGSchemaProperty

type SWGSchemas

type SWGSchemas struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SWGSchemas caches the SWGSchema using swagger + schemas as key. During each link operation from terraform schemas to swagger schemas, it will manipulate one of the SWGSchema. Afterwards, this type contains all the mapping info from swagger to terraform.

func NewSGWSchemas

func NewSGWSchemas() *SWGSchemas

func NewSWGSchemasFromTerraformSchema

func NewSWGSchemasFromTerraformSchema(swaggerBasePath, tfSchemaDir, swaggerGrantBaseDir string) (*SWGSchemas, error)

Build SWGSchemas by processing on Terraform schema files (which resides in the tfSchemaDir) and the Swagger specs (which resides in the swaggerBaseDir, can be either a local path or an http URI) Optionally, users can specify the swaggerGrantDir which contains the grants for those non-terraform appropriate swagger schema/properties.

func (*SWGSchemas) Get

func (c *SWGSchemas) Get(addr SWGSchemaAddr) *SWGSchema

func (*SWGSchemas) GetAll

func (c *SWGSchemas) GetAll() map[SWGSchemaAddr]*SWGSchema

GetSWGSchema get all SWGSchema from cache.

func (*SWGSchemas) Grant

func (c *SWGSchemas) Grant(grant SWGGrant) error

Grant inquiries the SWGGrant to add the granting information onto the SWGSchemas

func (*SWGSchemas) LinkSWGSchema

func (c *SWGSchemas) LinkSWGSchema(swaggerBasePath, swaggerRelPath string, swgPropAddr propertyaddr.SwaggerPropertyAddr, tfPropAddr propertyaddr.TerraformPropertyAddr) error

func (*SWGSchemas) Lock

func (c *SWGSchemas) Lock()

func (*SWGSchemas) Set

func (c *SWGSchemas) Set(addr SWGSchemaAddr, schema *SWGSchema)

func (*SWGSchemas) Unlock

func (c *SWGSchemas) Unlock()

type SwaggerCache

type SwaggerCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}
type SwaggerLink struct {
	Spec       *string                          `json:"swagger,omitempty"` // swagger spec relative path that this propertyaddr resides in, this overrides the global swagger scope
	SchemaProp propertyaddr.SwaggerPropertyAddr `json:"prop"`              // dot-separated swagger schemas propertyaddr, starting from the schemas used as the PUT body parameter
}
type TFLink struct {
	Prop propertyaddr.TerraformPropertyAddr
}
type TFLinks []TFLink

func (TFLinks) MarshalJSON

func (links TFLinks) MarshalJSON() ([]byte, error)

func (*TFLinks) UnmarshalJSON

func (links *TFLinks) UnmarshalJSON(b []byte) error

type TFSchema

type TFSchema struct {
	Name          string
	SwaggerSpec   string `json:"swagger"` // swagger spec relative path path that all the linked swagger property resides in by default
	PropertyLinks TFSchemaPropertyLinks
}

func NewSchema

func NewSchema(name string) *TFSchema

func NewSchemaScaffoldFromTerraformBlock

func NewSchemaScaffoldFromTerraformBlock(name string, block *TerraformBlock) *TFSchema

NewSchemaScaffoldFromTerraformBlock construct the TFSchema for a certain resource from the terraform resource block derived from `terraform providers schema -json`.

func UpdateSchemaScaffoldFromTerraformBlock

func UpdateSchemaScaffoldFromTerraformBlock(name string, block *TerraformBlock, oldSchema *TFSchema) (*TFSchema, error)

UpdateSchemaScaffoldFromTerraformBlock is similart to NewSchemaScaffoldFromTerraformBlock, except it will update the constrcutred TFSchema with the existing TFSchema.

func (TFSchema) LinkSwagger

func (schema TFSchema) LinkSwagger(swgSchemaCache *SWGSchemas, swaggerBasePath string) error

func (TFSchema) Validate

func (schema TFSchema) Validate() error

Validate validates the swagger property and tf schemas property has the correct form

type TFSchemaPropertyLinks map[string][]SwaggerLink

type TerraformAttribute

type TerraformAttribute struct {
	Type *cty.Type `json:"type"`
}

type TerraformBlock

type TerraformBlock struct {
	Attributes map[string]*TerraformAttribute   `json:"attributes"`
	BlockTypes map[string]*TerraformNestedBlock `json:"block_types"`
}

type TerraformNestedBlock

type TerraformNestedBlock struct {
	TerraformBlock `json:"block"`
}

type TerraformProvider

type TerraformProvider struct {
	ResourceSchemas   map[string]*TerraformSchema `json:"resource_schemas,omitempty"`
	DataSourceSchemas map[string]*TerraformSchema `json:"data_source_schemas,omitempty"`
}

type TerraformProviderSchemas

type TerraformProviderSchemas struct {
	FormatVersion string                       `json:"format_version"`
	Schemas       map[string]TerraformProvider `json:"provider_schemas"`
}

type TerraformSchema

type TerraformSchema struct {
	Block *TerraformBlock `json:"block,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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