variables

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// AWS IAM variables
	VarUsername    = "aws:username"    // Current authenticated username
	VarUserID      = "aws:userid"      // Current authenticated user UUID
	VarSourceIP    = "aws:SourceIp"    // Request source IP address
	VarCurrentTime = "aws:CurrentTime" // Current timestamp (ISO 8601)
	VarUserAgent   = "aws:UserAgent"   // HTTP User-Agent header

	// S3-specific variables
	VarS3Prefix    = "s3:prefix"    // Object key prefix for ListObjects
	VarS3Delimiter = "s3:delimiter" // Delimiter for ListObjects
)

Variable names supported by the policy engine

Variables

This section is empty.

Functions

func ExtractVariables

func ExtractVariables(input string) []string

ExtractVariables returns a list of all variable names found in the input string

func HasVariables

func HasVariables(input string) bool

HasVariables returns true if the input string contains any ${...} variable patterns

func Normalize

func Normalize(varName string) string

Normalize ensures commonly-used variable names work with different casing AWS uses inconsistent casing (aws:SourceIp vs aws:username), so we normalize

Types

type Context

type Context struct {
	// User identity
	Username string
	UserID   uuid.UUID

	// Request metadata
	SourceIP    net.IP
	CurrentTime time.Time
	UserAgent   string

	// S3-specific context
	S3Prefix    string
	S3Delimiter string
}

Context holds values for variable substitution during policy evaluation

func ForUser

func ForUser(user *iam.User) *Context

ForUser creates a minimal variable context for a specific user Useful when you have user info but no HTTP request

func ForUserSimple

func ForUserSimple(username string, userID uuid.UUID) *Context

ForUserSimple creates a context from basic user info (username and UUID)

func FromRequest

func FromRequest(r *http.Request) *Context

FromRequest builds a variable context from an HTTP request It extracts user identity, request metadata, and prepares for S3-specific context

func Minimal

func Minimal() *Context

Minimal creates a context with only current time Useful for anonymous requests or when user info isn't available

func (*Context) Substitute

func (c *Context) Substitute(input string) (string, error)

Substitute replaces all ${variable} patterns in the input string with their values from the context. Returns the substituted string and any error encountered.

Examples:

  • "arn:aws:s3:::bucket/${aws:username}/*" → "arn:aws:s3:::bucket/alice/*"
  • "prefix/${aws:userid}/data" → "prefix/550e8400-e29b-41d4-a716-446655440000/data"

func (*Context) SubstituteInterface

func (c *Context) SubstituteInterface(input any) (any, error)

SubstituteInterface handles substitution for interface{} values (string or []string) This is useful for Resource and Action fields in policy statements which can be either type

func (*Context) SubstituteSlice

func (c *Context) SubstituteSlice(inputs []string) ([]string, error)

SubstituteSlice applies substitution to all strings in a slice

func (*Context) WithS3Context

func (c *Context) WithS3Context(prefix, delimiter string) *Context

WithS3Context adds S3-specific variables (prefix, delimiter) to the context This should be called when evaluating policies for ListObjects operations

Jump to

Keyboard shortcuts

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