-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from strongdm/idx-48/stable-ast
Add JSON, programmatic AST, marshaling to Cedar for 0.2.0 release
- Loading branch information
Showing
100 changed files
with
12,590 additions
and
6,998 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.idea/ | ||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ast | ||
|
||
import ( | ||
"github.com/cedar-policy/cedar-go/internal/ast" | ||
"github.com/cedar-policy/cedar-go/types" | ||
) | ||
|
||
type Annotations ast.Annotations | ||
|
||
func (a *Annotations) unwrap() *ast.Annotations { | ||
return (*ast.Annotations)(a) | ||
} | ||
|
||
func wrapAnnotations(a *ast.Annotations) *Annotations { | ||
return (*Annotations)(a) | ||
} | ||
|
||
// Annotation allows AST constructors to make policy in a similar shape to textual Cedar with | ||
// annotations appearing before the actual policy scope: | ||
// | ||
// ast := Annotation("foo", "bar"). | ||
// Annotation("baz", "quux"). | ||
// Permit(). | ||
// PrincipalEq(superUser) | ||
func Annotation(key types.Ident, value types.String) *Annotations { | ||
return wrapAnnotations(ast.Annotation(key, value)) | ||
} | ||
|
||
// Annotation adds an annotation. If a previous annotation exists with the same key, this builder will replace it. | ||
func (a *Annotations) Annotation(key types.Ident, value types.String) *Annotations { | ||
return wrapAnnotations(a.unwrap().Annotation(key, value)) | ||
} | ||
|
||
// Permit begins a permit policy from the given annotations. | ||
func (a *Annotations) Permit() *Policy { | ||
return wrapPolicy(a.unwrap().Permit()) | ||
} | ||
|
||
// Forbid begins a forbid policy from the given annotations. | ||
func (a *Annotations) Forbid() *Policy { | ||
return wrapPolicy(a.unwrap().Forbid()) | ||
} | ||
|
||
// If a previous annotation exists with the same key, this builder will replace it. | ||
func (p *Policy) Annotate(key types.Ident, value types.String) *Policy { | ||
return wrapPolicy(p.unwrap().Annotate(key, value)) | ||
} |
Oops, something went wrong.