validationfile

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: Apache-2.0 Imports: 15 Imported by: 1

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-existance.

func (Assertions) AssertTrueRelationships

func (a Assertions) AssertTrueRelationships() ([]ParsedAssertion, *ErrorWithSource)

AssertTrueRelationships returns the relationships for which to assert existance.

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
}

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

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 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"`
}

ValidationFile represents the contents of a YAML validation file, as exported by the playground.

NOTE: This struct does not contain the `assertions` or `validation` blocks produced by the playground, as they are 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

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

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.

Jump to

Keyboard shortcuts

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