Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Assertion ¶
type Assertion struct {
// contains filtered or unexported fields
}
Assertion is an unparsed assertion.
type Assertions ¶
type Assertions struct {
// AssertTrue is the set of relationships to assert true.
AssertTrue []Assertion `yaml:"assertTrue"`
// AssertFalse is the set of relationships to assert false.
AssertFalse []Assertion `yaml:"assertFalse"`
}
Assertions represents assertions defined in the validation file.
func ParseAssertionsBlock ¶
func ParseAssertionsBlock(contents []byte) (Assertions, error)
ParseAssertionsBlock attempts to parse the given contents as a YAML assertions block.
func (Assertions) AssertFalseRelationships ¶
func (a Assertions) AssertFalseRelationships() ([]ParsedAssertion, *ErrorWithSource)
AssertFalseRelationships returns the relationships for which to assert non-existence.
func (Assertions) AssertTrueRelationships ¶
func (a Assertions) AssertTrueRelationships() ([]ParsedAssertion, *ErrorWithSource)
AssertTrueRelationships returns the relationships for which to assert existence.
type ErrorWithSource ¶
type ErrorWithSource struct {
// Source is the source text for the error.
Source string
// LineNumber is the (1-indexed) line number of the error, or 0 if unknown.
LineNumber uint32
// ColumnPosition is the (1-indexed) column position of the error, or 0 if
// unknown.
ColumnPosition uint32
// contains filtered or unexported fields
}
ErrorWithSource is an error that includes the source text and position information.
type FullyParsedValidationFile ¶
type FullyParsedValidationFile struct {
// NamespaceDefinitions are the namespaces defined in the validation file, in either
// direct or compiled from schema form.
NamespaceDefinitions []*v0.NamespaceDefinition
// Tuples are the relation tuples defined in the validation file, either directly
// or in the relationships block.
Tuples []*v0.RelationTuple
// ParsedFiles are the underlying parsed validation files.
ParsedFiles []ValidationFile
}
FullyParsedValidationFile contains the fully parsed information from a validation file.
func PopulateFromFiles ¶
func PopulateFromFiles(ds datastore.Datastore, filePaths []string) (*FullyParsedValidationFile, decimal.Decimal, error)
PopulateFromFiles populates the given datastore with the namespaces and tuples found in the validation file(s) specified.
type ObjectRelationString ¶
type ObjectRelationString string
ObjectRelationString represents an ONR defined as a string in the key for the ValidationMap.
func (ObjectRelationString) ONR ¶
func (ors ObjectRelationString) ONR() (*v0.ObjectAndRelation, *ErrorWithSource)
ONR returns the ObjectAndRelation parsed from this string, if valid, or an error on failure to parse.
type ParsedAssertion ¶
type ParsedAssertion struct {
// Relationship is the parsed relationship on which the assertion is being
// run.
Relationship *v0.RelationTuple
// LineNumber is the (1-indexed) line number of the assertion in the parent
// YAML.
LineNumber uint32
// ColumnPosition is the (1-indexed) column position of the assertion in the
// parent YAML.
ColumnPosition uint32
}
ParsedAssertion contains information about a parsed assertion relationship.
type SimpleAssertions ¶ added in v1.3.0
type SimpleAssertions struct {
// AssertTrue is the set of relationships to assert true.
AssertTrue []string `yaml:"assertTrue"`
// AssertFalse is the set of relationships to assert false.
AssertFalse []string `yaml:"assertFalse"`
}
SimpleAssertions is a parsed assertions block.
type SubjectWithExceptions ¶ added in v1.4.0
type SubjectWithExceptions struct {
// Subject is the subject found.
Subject *v0.ObjectAndRelation
// Exceptions are those subjects removed from the subject, if it is a wildcard.
Exceptions []*v0.ObjectAndRelation
}
SubjectWithExceptions returns the subject found in a validation string, along with any exceptions.
type ValidationFile ¶
type ValidationFile struct {
// Schema is the defined schema, in DSL format. Optional if at least one
// NamespaceConfig is specified.
Schema string `yaml:"schema"`
// Relationships are the validation relationships, as a single string of
// newline separated tuple string syntax.
// Optional if ValidationTuples is specified.
Relationships string `yaml:"relationships"`
// NamespaceConfigs are the namespace configuration protos, in text format.
// Optional if Schema is specified.
NamespaceConfigs []string `yaml:"namespace_configs"`
// ValidationTuples are the validation tuples, in tuple string syntax.
// Optional if Relationships are specified.
ValidationTuples []string `yaml:"validation_tuples"`
// Assertions are the (optional) assertions for the validation file.
Assertions SimpleAssertions `yaml:"assertions"`
}
ValidationFile represents the contents of a YAML validation file, as exported by the playground.
NOTE: This struct does not contain the `validation` block produced by the playground, as it is currently unused in Go-side code.
Parsing for those blocks' *contents* can be found in this module, since they are parsed by the developer API.
func ParseValidationFile ¶
func ParseValidationFile(contents []byte) (ValidationFile, error)
ParseValidationFile attempts to parse the given contents as a YAML validation file.
type ValidationMap ¶
type ValidationMap map[ObjectRelationString][]ValidationString
ValidationMap is a map from an Object Relation (as a Relationship) to the validation strings containing the Subjects for that Object Relation.
func ParseValidationBlock ¶
func ParseValidationBlock(contents []byte) (ValidationMap, error)
ParseValidationBlock attempts to parse the given contents as a YAML validation block.
func (ValidationMap) AsYAML ¶
func (vm ValidationMap) AsYAML() (string, error)
AsYAML returns the ValidationMap in its YAML form.
type ValidationString ¶
type ValidationString string
ValidationString holds a validation string containing a Subject and one or more Relations to the parent Object. Example: `[tenant/user:someuser#...] is <tenant/document:example#viewer>`
func (ValidationString) ONRS ¶
func (vs ValidationString) ONRS() ([]*v0.ObjectAndRelation, *ErrorWithSource)
ONRS returns the subject ONRs in the ValidationString, if any.
func (ValidationString) ONRStrings ¶
func (vs ValidationString) ONRStrings() []string
ONRStrings returns the ONRs contained in the ValidationString, if any.
func (ValidationString) Subject ¶
func (vs ValidationString) Subject() (*SubjectWithExceptions, *ErrorWithSource)
Subject returns the subject contained in the ValidationString, if any. If none, returns nil.
func (ValidationString) SubjectString ¶
func (vs ValidationString) SubjectString() (string, bool)
SubjectString returns the subject contained in the ValidationString, if any.