Documentation
¶
Overview ¶
Package schema provides schema parsing, serialization, and resolution.
Index ¶
- type Schema
- func (s *Schema) AST() *ast.Schema
- func (s *Schema) MarshalCedar() ([]byte, error)
- func (s *Schema) MarshalJSON() ([]byte, error)
- func (s *Schema) Resolve() (*resolved.Schema, error)
- func (s *Schema) SetFilename(filename string)
- func (s *Schema) UnmarshalCedar(b []byte) error
- func (s *Schema) UnmarshalJSON(b []byte) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema provides parsing and marshaling for Cedar schemas.
Example ¶
package main
import (
"fmt"
"github.com/cedar-policy/cedar-go/x/exp/schema"
)
const exampleCedar = `entity User in [Group] {
name: String,
age?: Long
};
entity Group;
entity Photo {
owner: User,
tags: Set<String>
};
entity Status enum ["active", "inactive"];
action viewPhoto appliesTo {
principal: User,
resource: Photo,
context: {}
};
`
func main() {
var s schema.Schema
if err := s.UnmarshalCedar([]byte(exampleCedar)); err != nil {
fmt.Println("schema parse error:", err)
return
}
resolved, err := s.Resolve()
if err != nil {
fmt.Println("schema resolve error:", err)
return
}
for entityType := range resolved.Entities {
fmt.Println("entity:", entityType)
}
for _, enum := range resolved.Enums {
fmt.Println("enum:", enum.Name)
}
for actionUID := range resolved.Actions {
fmt.Println("action:", actionUID)
}
}
Output: entity: User entity: Group entity: Photo enum: Status action: Action::"viewPhoto"
func NewSchemaFromAST ¶ added in v1.5.1
NewSchemaFromAST creates a Schema from an AST.
func (*Schema) MarshalCedar ¶
MarshalCedar encodes the Schema in the human-readable format.
func (*Schema) MarshalJSON ¶
MarshalJSON encodes the Schema in the JSON format.
func (*Schema) Resolve ¶ added in v1.5.1
Resolve returns a resolved.Schema with type references resolved and declarations indexed.
func (*Schema) SetFilename ¶
SetFilename sets the filename for error reporting.
func (*Schema) UnmarshalCedar ¶
UnmarshalCedar parses a Schema in the human-readable format.
func (*Schema) UnmarshalJSON ¶
UnmarshalJSON parses a Schema in the JSON format.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ast provides types for constructing Cedar schema ASTs programmatically.
|
Package ast provides types for constructing Cedar schema ASTs programmatically. |
|
internal
|
|
|
json
Package json provides JSON marshaling and unmarshaling for Cedar schema ASTs.
|
Package json provides JSON marshaling and unmarshaling for Cedar schema ASTs. |
|
parser
Package parser provides Cedar schema text parsing and formatting.
|
Package parser provides Cedar schema text parsing and formatting. |
|
Package resolved transforms an AST schema into a resolved schema where all type references are fully qualified and common types are inlined.
|
Package resolved transforms an AST schema into a resolved schema where all type references are fully qualified and common types are inlined. |
Click to show internal directories.
Click to hide internal directories.