models

package
v0.0.0-...-cbce884 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EndpointResource string = "resource"
	EndpointJSON     string = "json"
)
View Source
const (
	// CreatorUser constant
	CreatorUser = "user"
	// CreatorAPIKey constant
	CreatorAPIKey = "apikey"
)

Variables

This section is empty.

Functions

func FieldAsTypedInterface

func FieldAsTypedInterface(field string, val string) (interface{}, error)

FieldAsTypedInterface returns the field value as an interface with the proper type

func IsValidLogField

func IsValidLogField(field string) bool

IsValidLogField verifies that a field exists for the `Log` object

Types

type Collection

type Collection struct {
	ID            string    `json:"id"`
	Name          string    `json:"name"`
	ParallelRead  bool      `json:"parallel_read"`
	ParallelWrite bool      `json:"parallel_write"`
	Create        bool      `json:"create"`
	Read          bool      `json:"read"`
	Update        bool      `json:"update"`
	Delete        bool      `json:"delete"`
	Created       time.Time `json:"created"`
	Items         int64     `json:"items"`
}

Collection is a mongo collection containing whatever data a user wants to save

func (*Collection) Validate

func (c *Collection) Validate() error

Validate validates the collection fields

type Filters

type Filters map[string]Value

Filters is the map of query filters

func (*Filters) AddFilter

func (f *Filters) AddFilter(field string, value Value)

AddFilter adds a filter

type HookResult

type HookResult struct {
	WebHookID    string    `json:"webhook_id"`
	ProjectID    string    `json:"project_id"`
	StatusCode   int       `json:"status_code"`
	ResponseTime int64     `json:"response_time"`
	ErrorMessage string    `json:"error_message"`
	Created      time.Time `json:"created"`
}

HookResult contains relevant information regarding the http response of a web hook

type JSONSchemaObject

type JSONSchemaObject struct {
	Type       string                            `json:"type"`
	Properties map[string]map[string]interface{} `json:"properties"`
	Required   []string                          `json:"required"`
}

JSONSchemaObject is a simplified representation of the root schema

type Log

type Log struct {
	ID             string `json:"id"`
	ProjectID      string `json:"project_id"`
	EndpointType   string `json:"endpoint_type"`
	Verb           string `json:"verb"`
	Path           string `json:"path"`
	StatusCode     int    `json:"status_code"`
	Created        int64  `json:"created"`
	AlignedCreated int64  `json:"aligned"`
	ResponseTime   int64  `json:"response_time"`
	Initiator      string `json:"initiator"`
	InitiatorType  string `json:"initiator_type"`
	InitiatorID    string `json:"initiator_id"`
	TargetID       string `json:"target_id"`
}

Log is any user/api key initiated event that should be recorded

type MetaData

type MetaData struct {
	Creator     string `json:"creator"`
	CreatorType string `json:"creator_type"`
	Created     int64  `json:"created"`
}

MetaData contains internal data about a collection/resource object.

func NewMetaData

func NewMetaData(creator, creatorType string) *MetaData

NewMetaData returns a pointer to a new MetaData object with the `Created` field set to now.

func (*MetaData) Map

func (md *MetaData) Map() map[string]interface{}

Map returns the metadata object as a map[string]interface{}

type Op

type Op string

Op represents the operation to filter with.

const (
	GTE Op = "$gte"
	GT  Op = "$gt"
	LTE Op = "$lte"
	LT  Op = "$lt"
	EQ  Op = "$eq"
)

Filters is a custom struct which contains query filters with the following structure:

<field>: {
   <operator>: <value>
}

This provides a datastore agnostic way to communicate filtering

type Project

type Project struct {
	ID               string    `json:"id"`
	UserID           string    `json:"user_id"`
	Slug             string    `json:"slug"`
	Name             string    `json:"name"`
	Description      string    `json:"description"`
	Icon             string    `json:"icon"`
	Created          time.Time `json:"created"`
	Authn            bool      `json:"authn"`
	UserRegistration bool      `json:"user_registration"`
}

Project is an application project created and managed by a `User`

type ProjectAPIKey

type ProjectAPIKey struct {
	ID          string    `json:"id"`
	ProjectID   string    `json:"project_id"`
	KeyHash     string    `json:"-"`
	Created     time.Time `json:"created"`
	Description string    `json:"description"`
	Read        bool      `json:"read"`
	Write       bool      `json:"write"`
	Role        string    `json:"role"`
}

ProjectAPIKey is a static key used to access resources and collections of the project

type ProjectDetail

type ProjectDetail struct {
	ID               string     `json:"id"`
	UserID           string     `json:"user_id"`
	Slug             string     `json:"slug"`
	Name             string     `json:"name"`
	Description      string     `json:"description"`
	Icon             string     `json:"icon"`
	Created          time.Time  `json:"created"`
	Authn            bool       `json:"authn"`
	UserRegistration bool       `json:"user_registration"`
	Requests         int        `json:"requests"`
	Hooks            []*WebHook `json:"hooks"`
}

ProjectDetail is read from the app_project_limits view and contains app tier values based on the currently active account tier

type ProjectUser

type ProjectUser struct {
	ID           string    `json:"id"`
	ProjectID    string    `json:"project_id"`
	Username     string    `json:"username"`
	Email        string    `json:"email"`
	PasswordHash string    `json:"-"`
	Created      time.Time `json:"created"`
	Read         bool      `json:"read"`
	Write        bool      `json:"write"`
	Role         string    `json:"role"`
}

ProjectUser is a user of a project. A user can access resources and collections of the project.

type ResourceDefinition

type ResourceDefinition struct {
	ID            string    `json:"id"` // ID is the unique identifier for this resource definition
	ProjectID     string    `json:"project_id"`
	Title         string    `json:"title"`     // Title of this resource
	PathName      string    `json:"path_name"` // PathName is the name that will appear in the URL path
	ParallelRead  bool      `json:"parallel_read"`
	ParallelWrite bool      `json:"parallel_write"`
	Create        bool      `json:"create"`
	Read          bool      `json:"read"`
	Update        bool      `json:"update"`
	Delete        bool      `json:"delete"`
	Created       time.Time `json:"created"` // Created is the timestamp the resource was created
	Schema        string    `json:"schema"`  // Properties is the string representation of the JSON schema properties
}

ResourceDefinition defines an API resource

func (*ResourceDefinition) GetSchema

func (def *ResourceDefinition) GetSchema() (*JSONSchemaObject, error)

GetSchema returns the schema as a `Schema` object

func (*ResourceDefinition) GetSchemaMap

func (def *ResourceDefinition) GetSchemaMap() (map[string]interface{}, error)

GetSchemaMap returns the schema as a `map[string]interface{}`

func (*ResourceDefinition) MarshalJSON

func (def *ResourceDefinition) MarshalJSON() ([]byte, error)

MarshalJSON custom marshaller to marshall properties to json

func (*ResourceDefinition) UnmarshalJSON

func (def *ResourceDefinition) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom unmarshaller

func (*ResourceDefinition) Validate

func (def *ResourceDefinition) Validate() error

Validate validates the fields of a resource definition.

type ResourceObject

type ResourceObject map[string]interface{}

ResourceObject is a custom type which wraps a map[string]interface

func (*ResourceObject) Validate

func (obj *ResourceObject) Validate(definition *ResourceDefinition) error

Validate validates that the object matches the schema

type RootKey

type RootKey struct {
	ID        string `json:"id"`
	Key       string `json:"key"`
	ProjectID string `json:"project_id"`
	Create    bool   `json:"create"`
	Read      bool   `json:"read"`
	Update    bool   `json:"update"`
	Delete    bool   `json:"delete"`
}

RootKey defines the metadata of a project root JSON key

type Session

type Session struct {
	ID           string    `json:"id"`
	ProjectID    string    `json:"project_id"`
	UserID       string    `json:"user_id"`
	Location     string    `json:"location"`
	Mobile       bool      `json:"mobile"`
	IP           string    `json:"ip"`
	LastAccessed time.Time `json:"last_accessed"`
	Browser      string    `json:"browser"`
	OS           string    `json:"os"`
}

Session is a user session model for either the mgmt application or a project

type Stats

type Stats struct {
	Size  int64 `json:"size"`
	Count int64 `json:"count"`
}

Stats is a struct that contains the size and count of objects in a Resource or Collection

type Tier

type Tier struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Cost     string `json:"cost"`
	Requests int    `json:"requests"`
	Projects int    `json:"projects"`
	Storage  int    `json:"storage"`
}

Tier is an application tier, describing the limitations of an application subscribed to a certain tier

type TranslatedError

type TranslatedError struct {
	Code int
	Err  error
}

TranslatedError is a database error translated with HTTP Status code

func NewTranslatedError

func NewTranslatedError(code int, err error) *TranslatedError

NewTranslatedError returns a pointer to a new `TranslatedError`

func (*TranslatedError) Error

func (t *TranslatedError) Error() string

type User

type User struct {
	ID           string    `json:"id"`
	Username     string    `json:"username"`
	Email        string    `json:"email"`
	PasswordHash string    `json:"-"`
	Created      time.Time `json:"created"`
	Tier         string    `json:"app_tier"`
	Active       bool      `json:"active"`
	Admin        bool      `json:"-"`
}

User is a user of the application

type Value

type Value map[Op]interface{}

Value is a map of `Op` to a value interface

type WebHook

type WebHook struct {
	ID        string `json:"id"`
	ProjectID string `json:"project_id"`
	Label     string `json:"label"`
	IsEnabled bool   `json:"is_enabled"`
	Entity    string `json:"entity"`
	EntityID  string `json:"entity_id"`
	HookEvent string `json:"event"`
	Headers   []byte `json:"headers"`
	HookURL   string `json:"hook_url"`
}

WebHook defines the structure of a project web hook

func (*WebHook) MarshalJSON

func (w *WebHook) MarshalJSON() ([]byte, error)

MarshalJSON custom marshaller to marshall properties to json

func (*WebHook) UnmarshalJSON

func (w *WebHook) UnmarshalJSON(b []byte) error

UnmarshalJSON is a custom unmarshaller, specificall for the `headers`

func (*WebHook) Validate

func (w *WebHook) Validate() error

Validate performs validation on the WebHook struct, returning an error if it is invalid

Jump to

Keyboard shortcuts

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