secrets

package
v1.41.3 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SecretsParser = &resourceparser.Parser{
	Name:               "Secrets",
	InterestingImports: resourceparser.RunAlways,

	Run: func(p *resourceparser.Pass) {
		secrets := p.Pkg.Names().PkgDecls["secrets"]
		if secrets == nil || secrets.Type != token.VAR {
			return
		}

		spec := secrets.Spec.(*ast.ValueSpec)
		if spec.Type == nil {
			p.Errs.Add(errSecretsMustBeStruct.AtGoNode(spec, errors.AsError(fmt.Sprintf("got %s", parseutil.NodeType(spec)))))
			return
		} else if len(spec.Names) != 1 {
			p.Errs.Add(errSecretsDefinedSeperately.AtGoNode(spec))
			return
		} else if len(spec.Values) != 0 {
			p.Errs.Add(errSecretsGivenValue.AtGoNode(spec.Values[0]))
			return
		}

		st, ok := p.SchemaParser.ParseType(secrets.File, spec.Type).(schema.StructType)
		if !ok {
			p.Errs.Add(errSecretsMustBeStruct.AtGoNode(spec, errors.AsError(fmt.Sprintf("got %s", parseutil.NodeType(spec)))))
			return
		}

		res := &Secrets{
			AST:   spec.Type.(*ast.StructType),
			File:  secrets.File,
			Spec:  spec,
			Ident: spec.Names[0],
		}

		for _, f := range st.Fields {
			if f.IsAnonymous() {
				p.Errs.Add(errAnonymousFields.AtGoNode(f.AST))
				continue
			}
			if !schemautil.IsBuiltinKind(f.Type, schema.String) {
				p.Errs.Add(errSecretsMustBeString.AtGoNode(f.AST.Type, errors.AsError(fmt.Sprintf("got %s", literals.PrettyPrint(f.Type.ASTExpr())))))
				continue
			}
			res.Keys = append(res.Keys, f.Name.MustGet())
		}

		p.RegisterResource(res)
		p.AddNamedBind(res.File, res.Ident, res)
	},
}

Functions

This section is empty.

Types

type SecretKey

type SecretKey struct {
	Name string
}

type Secrets

type Secrets struct {
	AST   *ast.StructType
	File  *pkginfo.File // Where the secrets struct is declared
	Ident *ast.Ident    // The identifier of the secrets struct
	Keys  []string      // Secret keys to load

	// Spec is the value spec that defines the 'secrets' variable.
	Spec *ast.ValueSpec
}

Secrets represents a secrets struct.

func (*Secrets) ASTExpr

func (s *Secrets) ASTExpr() ast.Expr

func (*Secrets) End

func (s *Secrets) End() token.Pos

func (*Secrets) Kind

func (*Secrets) Kind() resource.Kind

func (*Secrets) Package

func (s *Secrets) Package() *pkginfo.Package

func (*Secrets) Pos

func (s *Secrets) Pos() token.Pos

func (*Secrets) SortKey added in v1.16.3

func (s *Secrets) SortKey() string

Jump to

Keyboard shortcuts

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