Skip to content

Commit

Permalink
rename fn::rotate provider -> rotator
Browse files Browse the repository at this point in the history
  • Loading branch information
nyobe committed Jan 22, 2025
1 parent 1a386a8 commit 53ccc3c
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 186 deletions.
34 changes: 17 additions & 17 deletions ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,32 +439,32 @@ func Open(provider string, inputs *ObjectExpr) *OpenExpr {
type RotateExpr struct {
builtinNode

Provider *StringExpr
Inputs Expr
State *ObjectExpr
Rotator *StringExpr
Inputs Expr
State *ObjectExpr
}

func RotateSyntax(node *syntax.ObjectNode, name *StringExpr, args Expr, provider *StringExpr, inputs Expr, state *ObjectExpr) *RotateExpr {
func RotateSyntax(node *syntax.ObjectNode, name *StringExpr, args Expr, rotator *StringExpr, inputs Expr, state *ObjectExpr) *RotateExpr {
return &RotateExpr{
builtinNode: builtin(node, name, args),
Provider: provider,
Rotator: rotator,
Inputs: inputs,
State: state,
}
}

func Rotate(provider string, inputs, state *ObjectExpr) *RotateExpr {
name, providerX := String("fn::rotate"), String(provider)
func Rotate(rotator string, inputs, state *ObjectExpr) *RotateExpr {
name, rotatorX := String("fn::rotate"), String(rotator)

entries := []ObjectProperty{
{Key: String("provider"), Value: providerX},
{Key: String("rotator"), Value: rotatorX},
{Key: String("inputs"), Value: inputs},
{Key: String("state"), Value: state},
}

return &RotateExpr{
builtinNode: builtin(nil, name, Object(entries...)),
Provider: providerX,
Rotator: rotatorX,
Inputs: inputs,
State: state,
}
Expand Down Expand Up @@ -745,33 +745,33 @@ func parseRotate(node *syntax.ObjectNode, name *StringExpr, args Expr) (Expr, sy
return RotateSyntax(node, name, args, nil, nil, nil), diags
}

var providerExpr, inputs, stateExpr Expr
var rotatorExpr, inputs, stateExpr Expr
var diags syntax.Diagnostics

for i := 0; i < len(obj.Entries); i++ {
kvp := obj.Entries[i]
key := kvp.Key
switch key.GetValue() {
case "provider":
providerExpr = kvp.Value
case "rotator":
rotatorExpr = kvp.Value
case "inputs":
inputs = kvp.Value
case "state":
stateExpr = kvp.Value
}
}

provider, ok := providerExpr.(*StringExpr)
provider, ok := rotatorExpr.(*StringExpr)
if !ok {
if providerExpr == nil {
diags.Extend(ExprError(obj, "missing provider name ('provider')"))
if rotatorExpr == nil {
diags.Extend(ExprError(obj, "missing rotator name ('rotator')"))
} else {
diags.Extend(ExprError(providerExpr, "provider name must be a string literal"))
diags.Extend(ExprError(rotatorExpr, "rotator name must be a string literal"))
}
}

if inputs == nil {
diags.Extend(ExprError(obj, "missing provider inputs ('inputs')"))
diags.Extend(ExprError(obj, "missing rotator inputs ('inputs')"))
}

state, ok := stateExpr.(*ObjectExpr)
Expand Down
6 changes: 3 additions & 3 deletions eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func declare[Expr exprNode](e *evalContext, path string, x Expr, base *value) *e
case *ast.RotateExpr:
repr := &rotateExpr{
node: x,
provider: declare(e, "", x.Provider, nil),
rotator: declare(e, "", x.Rotator, nil),
inputs: declare(e, "", x.Inputs, nil),
state: declare(e, "", x.State, nil),
inputSchema: schema.Always().Schema(),
Expand Down Expand Up @@ -974,13 +974,13 @@ func (e *evalContext) evaluateBuiltinRotate(x *expr, repr *rotateExpr) *value {
v := &value{def: x}

// Can happen if there are parse errors.
if repr.node.Provider == nil {
if repr.node.Rotator == nil {
v.schema = schema.Always()
v.unknown = true
return v
}

rotator, err := e.providers.LoadRotator(e.ctx, repr.node.Provider.GetValue())
rotator, err := e.providers.LoadRotator(e.ctx, repr.node.Rotator.GetValue())
if err != nil {
e.errorf(repr.syntax(), "%v", err)
} else {
Expand Down
18 changes: 9 additions & 9 deletions eval/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ func (x *expr) export(environment string) esc.Expr {
Name: name,
NameRange: convertRange(repr.node.Name().Syntax().Syntax().Range(), environment),
ArgSchema: schema.Record(schema.SchemaMap{
"provider": schema.String().Schema(),
"inputs": repr.inputSchema,
"state": repr.stateSchema,
"rotator": schema.String().Schema(),
"inputs": repr.inputSchema,
"state": repr.stateSchema,
}).Schema(),
Arg: esc.Expr{
Object: map[string]esc.Expr{
"provider": repr.provider.export(environment),
"inputs": repr.inputs.export(environment),
"state": repr.state.export(environment),
"rotator": repr.rotator.export(environment),
"inputs": repr.inputs.export(environment),
"state": repr.state.export(environment),
},
},
}
Expand Down Expand Up @@ -410,9 +410,9 @@ func (x *openExpr) syntax() ast.Expr {
type rotateExpr struct {
node *ast.RotateExpr

provider *expr
inputs *expr
state *expr
rotator *expr
inputs *expr
state *expr

inputSchema *schema.Schema
stateSchema *schema.Schema
Expand Down
8 changes: 4 additions & 4 deletions eval/rotate_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ values:
a:
a:
fn::rotate:
provider: swap
rotator: swap
inputs:
foo: bar
state:
Expand Down Expand Up @@ -63,15 +63,15 @@ values:
// values:
// a:
// a:
// fn::open:
// provider: swap
// fn::rotate:
// rotator: swap
// inputs:
// state:
// a: b
// b: a
// b:
// - c:
// fn::open::swap:
// fn::rotate::swap:
// state:
// a: b
// b:
Expand Down
2 changes: 1 addition & 1 deletion eval/testdata/eval/rotate/env.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
values:
full:
fn::rotate:
provider: swap
rotator: swap
inputs: {}
state:
a: bar1
Expand Down
Loading

0 comments on commit 53ccc3c

Please sign in to comment.