build

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

In this file, we convert a version of the SAM spec that has been simplified to the old CloudFormation spec format into the new registry schema format. This allows us to build boilerplate templates for SAM resource types using the same code that we use for normal registry resource types. Ideally we would parse the actual SAM spec, but the file is huge and complex, and SAM transforms are relatively stable, so we shouldn't have issues with the output being out of date.

Example (Omit_read_only)
os.Args = []string{
	os.Args[0],
	"AWS::ECR::ReplicationConfiguration",
}
Cmd.Execute()
Output:

AWSTemplateFormatVersion: 2010-09-09

Description: Generated by rain

Resources:
  ReplicationConfiguration:
    Type: AWS::ECR::ReplicationConfiguration
    Properties:
      ReplicationConfiguration:
        Rules:
          - Destinations:
              - Region: '[0-9a-z-]{2,25}'
                RegistryId: ^[0-9]{12}$
              - Region: '[0-9a-z-]{2,25}'
                RegistryId: ^[0-9]{12}$
            RepositoryFilters:
              - Filter: ^(?:[a-z0-9]+(?:[._-][a-z0-9]*)*/)*[a-z0-9]*(?:[._-][a-z0-9]*)*$
                FilterType: PREFIX_MATCH
              - Filter: ^(?:[a-z0-9]+(?:[._-][a-z0-9]*)*/)*[a-z0-9]*(?:[._-][a-z0-9]*)*$
                FilterType: PREFIX_MATCH
          - Destinations:
              - Region: '[0-9a-z-]{2,25}'
                RegistryId: ^[0-9]{12}$
              - Region: '[0-9a-z-]{2,25}'
                RegistryId: ^[0-9]{12}$
            RepositoryFilters:
              - Filter: ^(?:[a-z0-9]+(?:[._-][a-z0-9]*)*/)*[a-z0-9]*(?:[._-][a-z0-9]*)*$
                FilterType: PREFIX_MATCH
              - Filter: ^(?:[a-z0-9]+(?:[._-][a-z0-9]*)*/)*[a-z0-9]*(?:[._-][a-z0-9]*)*$
                FilterType: PREFIX_MATCH

Index

Examples

Constants

View Source
const (
	LANG_CFN   = "cfn"
	LANG_GUARD = "guard"
	LANG_REGO  = "rego"
)
View Source
const (
	LIST            = "list"
	SCHEMA          = "schema"
	TEMPLATE        = "template"
	POLICY          = "policy"
	ALL             = "all"
	REQUIRED        = "required"
	RECOMMEND       = "recommend"
	PROMPT          = "prompt"
	CLAUDE2         = "claude2"
	CLAUDE3OPUS     = "claude3opus"
	CLAUDE3SONNET   = "claude3sonnet"
	CLAUDE3HAIKU    = "claude3haiku"
	CLAUDE3_5SONNET = "claude3.5sonnet"
	GUARD           = "guard"
	OPA             = "opa"
	GENERIC         = "generic"
	YES             = "yes"
	NO              = "no"
)
View Source
const (
	MAP = iota
	LISTING
	STRINGS
	TYPES
	PRIMITIVE
)

Variables

View Source
var Cmd = &cobra.Command{
	Use:                   "build [<resource type>] or <prompt>",
	Short:                 "Create CloudFormation templates",
	Long:                  "The build command interacts with the CloudFormation registry to list types, output schema files, and build starter CloudFormation templates containing the named resource types.",
	DisableFlagsInUseLine: true,
	Run: func(cmd *cobra.Command, args []string) {

		if buildListFlag {
			prefix := ""
			if len(args) > 0 {
				prefix = args[0]
			}
			list(prefix)
			return
		}

		if recommendFlag {
			recommend(args)
			return
		}

		if showSchema {
			if len(args) == 0 {
				panic("provide a resource type name")
			}
			schema(args[0])
			return
		}

		if promptFlag {
			validLangs := []string{LANG_CFN, LANG_GUARD, LANG_REGO}
			if !slices.Contains(validLangs, promptLanguage) {
				panic(fmt.Sprintf("provide a valid --prompt-lang: %v", validLangs))
			}
			if len(args) == 0 {
				panic("provide a prompt")
			}
			runPrompt(strings.Join(args, " "))
			return
		}

		if pklClass {
			if len(args) == 0 {
				panic("provide a type name")
			}
			typeName := args[0]
			if err := generatePklClass(typeName); err != nil {
				panic(err)
			}
			return
		}

		if len(args) == 0 {

			interactive()
		} else {

			basicBuild(args)
		}
	},
}

Cmd is the build command's entrypoint

View Source
var NoBellStdout = &noBellStdout{}

Functions

This section is empty.

Types

type SamProp added in v1.8.0

type SamProp struct {
	Documentation               string
	Required                    bool
	PrimitiveType               string
	PrimitiveItemType           string
	UpdateType                  string
	PrimitiveTypes              []string
	Type                        string
	Types                       []string
	ItemType                    string
	InclusivePrimitiveItemTypes []string
	InclusiveItemTypes          []string
}

SamProp represents the old cfn spec types, which are... odd

type SamSpec added in v1.8.0

type SamSpec struct {
	ResourceSpecificationVersion   string
	ResourceSpecificationTransform string
	Globals                        any
	ResourceTypes                  map[string]*SamType
	PropertyTypes                  map[string]*SamType
}

type SamType added in v1.8.0

type SamType struct {
	Documentation string
	Properties    map[string]*SamProp
}

Jump to

Keyboard shortcuts

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