schema

package
v0.0.0-...-5e604c0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: Apache-2.0 Imports: 14 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorTemplateFunc = map[string]interface{}{
	"error_prefix": func(field string) string {
		formatter := newErrorFormatter(field)
		return formatter.FormatErrorPrefix()
	},
	"invalid_property_name": func(field string) string {
		formatter := newErrorFormatter(field)
		return formatter.FormatInvalidProperty()
	},
	"one_of": func(field string) string {
		formatter := newErrorFormatter(field)
		return formatter.FormatNumberOneOf()
	},
	"pretty_print_pattern": func(pattern *regexp.Regexp) string {
		return PrettyPrintPattern(pattern)
	},
}

Used as function map that can be used when templating the error messages

Functions

func ApplicationJsonSchema

func ApplicationJsonSchema() *jsonschema.Schema

func ApplicationJsonSchemaString

func ApplicationJsonSchemaString() string

func ExpandActions

func ExpandActions(actions []string, resourceType ResourceType) []string

ExpandActions expands 'all' in an actions array whilst maintaining deduplication

func FormatValidationErrors

func FormatValidationErrors(errs []ValidationError) string
Formats the error messages like this:

---> Error Message

|
| YAML Context
|

func GenerateYamlContext

func GenerateYamlContext(err gojsonschema.ResultError, updatedDescription string) string

GenerateYamlContext generates the YAML context for validation errors

func GetValidActions

func GetValidActions(resourceType ResourceType) []string

func PrettyPrintPattern

func PrettyPrintPattern(pattern *regexp.Regexp) string

func SaveToYaml

func SaveToYaml(fs afero.Fs, path string, appSpec *Application) error

func ValidateActions

func ValidateActions(actions []string, resourceType ResourceType) ([]string, bool)

ValidateActions ensures that all the actions are valid

Types

type Application

type Application struct {
	// Targets sets platforms this application should be expected to work on
	// This gives us room to move away from LCD expectations around how platforms are built
	Targets     []string `json:"targets" yaml:"targets" jsonschema:"required,pattern=^(([a-z]+)/([a-z]+)@(\\d+)|file:([^\\s]+))$"`
	Name        string   `json:"name" yaml:"name" jsonschema:"required"`
	Description string   `json:"description" yaml:"description"`

	ServiceIntents    map[string]*ServiceIntent    `json:"services,omitempty" yaml:"services,omitempty"`
	BucketIntents     map[string]*BucketIntent     `json:"buckets,omitempty" yaml:"buckets,omitempty"`
	EntrypointIntents map[string]*EntrypointIntent `json:"entrypoints,omitempty" yaml:"entrypoints,omitempty"`
	DatabaseIntents   map[string]*DatabaseIntent   `json:"databases,omitempty" yaml:"databases,omitempty"`
	WebsiteIntents    map[string]*WebsiteIntent    `json:"websites,omitempty" yaml:"websites,omitempty"`
}

func ApplicationFromJson

func ApplicationFromJson(jsonString string) (*Application, *gojsonschema.Result, error)

func ApplicationFromYaml

func ApplicationFromYaml(yamlString string) (*Application, *gojsonschema.Result, error)

func LoadFromFile

func LoadFromFile(fs afero.Fs, path string, validate bool) (*Application, error)

func (*Application) GetResourceIntent

func (a *Application) GetResourceIntent(name string) (interface{}, bool)

func (*Application) GetResourceIntents

func (a *Application) GetResourceIntents() map[string]IResource

func (*Application) GetTypeForIntent

func (a *Application) GetTypeForIntent(intent interface{}) (string, error)

func (*Application) IsValid

func (a *Application) IsValid() []gojsonschema.ResultError

Perform additional validation checks on the application

type BucketIntent

type BucketIntent struct {
	Resource `json:",inline" yaml:",inline"`

	ContentPath string `json:"content_path,omitempty" yaml:"content_path,omitempty"`

	Access map[string][]string `json:"access,omitempty" yaml:"access,omitempty"`
}

func (*BucketIntent) GetAccess

func (b *BucketIntent) GetAccess() (map[string][]string, bool)

func (*BucketIntent) GetType

func (b *BucketIntent) GetType() string

type Container

type Container struct {
	Docker *Docker      `json:"docker,omitempty" yaml:"docker,omitempty" jsonschema:"oneof_required=docker"`
	Image  *DockerImage `json:"image,omitempty" yaml:"image,omitempty" jsonschema:"oneof_required=image"`
}

Runtime represents a union of all possible runtime types

type DatabaseIntent

type DatabaseIntent struct {
	Resource `json:",inline" yaml:",inline"`

	Access map[string][]string `json:"access,omitempty" yaml:"access,omitempty"`
	// The key that this database will export to services that depend on it.
	EnvVarKey string `json:"env_var_key" yaml:"env_var_key"`
}

func (*DatabaseIntent) GetAccess

func (d *DatabaseIntent) GetAccess() (map[string][]string, bool)

func (*DatabaseIntent) GetType

func (d *DatabaseIntent) GetType() string

type Dev

type Dev struct {
	// The script the start the service (because running it locally is orders of magnitude faster than building the containers)
	Script string `json:"script" yaml:"script"`
}

type Docker

type Docker struct {
	Dockerfile string            `json:"dockerfile,omitempty" yaml:"dockerfile,omitempty"`
	Context    string            `json:"context,omitempty" yaml:"context,omitempty"`
	Args       map[string]string `json:"args,omitempty" yaml:"args,omitempty"`
}

DockerFileRuntime represents a runtime that uses a Dockerfile

type DockerImage

type DockerImage struct {
	ID string `json:"id,omitempty" yaml:"id,omitempty" jsonschema:"required"`
}

type EntrypointIntent

type EntrypointIntent struct {
	Resource `json:",inline" yaml:",inline"`
	Routes   map[string]Route `json:"routes" yaml:"routes"`
}

func (*EntrypointIntent) GetType

func (e *EntrypointIntent) GetType() string

func (EntrypointIntent) JSONSchemaExtend

func (e EntrypointIntent) JSONSchemaExtend(schema *jsonschema.Schema)

type IResource

type IResource interface {
	GetType() string
	GetSubType() string
	GetAccess() (map[string][]string, bool)
}

type NitricErrorTemplate

type NitricErrorTemplate struct {
	gojsonschema.DefaultLocale
}

func (*NitricErrorTemplate) DoesNotMatchPattern

func (t *NitricErrorTemplate) DoesNotMatchPattern() string

func (*NitricErrorTemplate) ErrorFormat

func (t *NitricErrorTemplate) ErrorFormat() string

These are used to format the error messages in the gojsonschema Locale Unused here, but used when gojsonschema validates the schema

func (*NitricErrorTemplate) InvalidPropertyName

func (t *NitricErrorTemplate) InvalidPropertyName() string

func (*NitricErrorTemplate) NumberOneOf

func (t *NitricErrorTemplate) NumberOneOf() string

func (*NitricErrorTemplate) Required

func (t *NitricErrorTemplate) Required() string

type Resource

type Resource struct {
	SubType string `json:"subtype,omitempty" yaml:"subtype,omitempty"`
}

func (*Resource) GetAccess

func (r *Resource) GetAccess() (map[string][]string, bool)

func (*Resource) GetSubType

func (r *Resource) GetSubType() string

type ResourceType

type ResourceType string
const (
	Database ResourceType = "database"
	Bucket   ResourceType = "bucket"
)

type Route

type Route struct {
	TargetName string `json:"name" yaml:"name"`
	BasePath   string `json:"base_path,omitempty" yaml:"base_path,omitempty"`
}

type Schedule

type Schedule struct {
	CronExpression string `json:"cron_expression,omitempty" yaml:"cron_expression,omitempty" jsonschema:"oneof_required=cron_expression"`
}

type ServiceIntent

type ServiceIntent struct {
	Resource  `json:",inline" yaml:",inline"`
	Env       map[string]string `json:"env,omitempty" yaml:"env,omitempty"`
	Container Container         `json:"container" yaml:"container" jsonschema:"oneof_required=container"`

	Dev *Dev `json:"dev,omitempty" yaml:"dev,omitempty"`

	Triggers map[string]*ServiceTrigger `json:"triggers,omitempty" yaml:"triggers,omitempty"`
}

func (*ServiceIntent) GetType

func (s *ServiceIntent) GetType() string

type ServiceTrigger

type ServiceTrigger struct {
	Schedule *Schedule `json:"schedule,omitempty" yaml:"schedule,omitempty" jsonschema:"oneof_required=schedule"`

	Path string `json:"path" yaml:"path" jsonschema:"required"`
}

type TargetType

type TargetType string
const (
	TargetType_Service TargetType = "service"
	TargetType_Website TargetType = "website"
)

type ValidationError

type ValidationError struct {
	Path        string `json:"path"`
	Message     string `json:"message"`
	ErrorType   string `json:"errorType"`
	YamlContext string `json:"yamlContext"`
}

func GetSchemaValidationErrors

func GetSchemaValidationErrors(errs []gojsonschema.ResultError) []ValidationError

type WebsiteDev

type WebsiteDev struct {
	Url     string `json:"url" yaml:"url"`
	Command string `json:"command" yaml:"command"`
}

type WebsiteIntent

type WebsiteIntent struct {
	Resource     `json:",inline" yaml:",inline"`
	BaseDir      string      `json:"base_dir" yaml:"base_dir"`
	AssetDir     string      `json:"asset_dir" yaml:"asset_dir"`
	ErrorPage    string      `json:"error_page" yaml:"error_page"`
	BuildCommand *string     `json:"build,omitempty" yaml:"build,omitempty"`
	Dev          *WebsiteDev `json:"dev,omitempty" yaml:"dev,omitempty"`
}

func (*WebsiteIntent) GetType

func (w *WebsiteIntent) GetType() string

type YamlContextBuilder

type YamlContextBuilder struct {
	strings.Builder
}

func (*YamlContextBuilder) String

func (b *YamlContextBuilder) String() string

func (*YamlContextBuilder) WriteError

func (b *YamlContextBuilder) WriteError(s string) (int, error)

func (*YamlContextBuilder) WriteYamlKey

func (b *YamlContextBuilder) WriteYamlKey(s interface{}, indent int) (int, error)

Jump to

Keyboard shortcuts

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