parse

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Overview

Package parse provides functions for parsing CloudFormation templates from JSON and YAML inputs.

Example
package main

import (
	"fmt"

	"github.com/aws-cloudformation/rain/cft/parse"
)

func main() {
	template, _ := parse.String(`
Resources:
  Bucket:
    Type: AWS::S3::Bucket
`)

	fmt.Println(template.Map())
}
Output:

map[Resources:map[Bucket:map[Type:AWS::S3::Bucket]]]

Index

Examples

Constants

View Source
const (
	DATA   rune = ' ' // Any other rune
	DOLLAR rune = '$'
	OPEN   rune = '{'
	CLOSE  rune = '}'
	BANG   rune = '!'
)
View Source
const (
	STR    wordtype = iota // A literal string fragment
	REF                    // ${ParamOrResourceName}
	AWS                    // ${AWS::X}
	GETATT                 // ${X.Y}
)
View Source
const (
	READSTR state = iota
	MAYBE
	READVAR
	READLIT
)

Variables

This section is empty.

Functions

func File

func File(fileName string) (cft.Template, error)

File returns a cft.Template parsed from a file specified by fileName

func Map

func Map(input map[string]interface{}) (cft.Template, error)

Map returns a cft.Template parsed from a map[string]interface{}

func Node

func Node(n *yaml.Node) (cft.Template, error)

Node returns a cft.Template parse from a *yaml.Node

func NormalizeNode added in v1.8.0

func NormalizeNode(n *yaml.Node) error

NormalizeNode takes a *yaml.Node and convert tag-style names into map-style, and converts other scalars into a canonical format

func Reader

func Reader(r io.Reader) (cft.Template, error)

Reader returns a cft.Template parsed from an io.Reader

func String

func String(input string) (cft.Template, error)

String returns a cft.Template parsed from a string

func Verify

func Verify(source cft.Template, output string) error

Verify confirms that there is no semantic difference between the source cft.Template and the string representation in output. This can be used to ensure that the parse package hasn't done anything unexpected to your template.

Types

type SubWord added in v1.8.0

type SubWord struct {
	T wordtype
	W string // Does not include the ${} if it's not a STR
}

func ParseSub added in v1.8.0

func ParseSub(sub string) ([]SubWord, error)

ParseSub returns a slice of words, based on a string argument to the Fn::Sub intrinsic function.

"ABC-${XYZ}-123"

returns a slice containing:

SubWord { T: STR, W: "ABC-" }
SubWord { T: REF, W: "XYZ" }
SubWord { T: STR, W: "-123" }

Invalid syntax like "${AAA" returns an error

Jump to

Keyboard shortcuts

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