resource

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2017 License: GPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Added changeType = iota
	Removed
	ChangedType
	ChangedValue
)

Variables

View Source
var CollectionTypes = []string{
	"Pair",
	"Triplet",
	"Set",
	"OrderedSet",
}
View Source
var ColumnTypes = []string{
	"id",
	"alias",
	"date",
	"time",
	"day",
	"month",
	"year",
	"minute",
	"hour",
	"datetime",
	"email",
	"name",
	"value",
	"truefalse",
	"timestamp",
	"location.latitude",
	"location.longitude",
	"location.altitude",
	"color",
	"measurement",
	"label",
	"content",
	"file",
	"url",
	"image",
}
View Source
var ConfigTableStructure = TableInfo{
	TableName: settingsTableName,
	Columns: []api2go.ColumnInfo{
		{
			Name:            "id",
			ColumnName:      "id",
			ColumnType:      "id",
			DataType:        "INTEGER",
			IsPrimaryKey:    true,
			IsAutoIncrement: true,
		},
		{
			Name:       "name",
			ColumnName: "name",
			ColumnType: "string",
			DataType:   "varchar(100)",
			IsNullable: false,
			IsIndexed:  true,
		},
		{
			Name:       "ConfigType",
			ColumnName: "configtype",
			ColumnType: "string",
			DataType:   "varchar(100)",
			IsNullable: false,
			IsIndexed:  true,
		},
		{
			Name:       "ConfigState",
			ColumnName: "configstate",
			ColumnType: "string",
			DataType:   "varchar(100)",
			IsNullable: false,
			IsIndexed:  true,
		},
		{
			Name:       "ConfigEnv",
			ColumnName: "configenv",
			ColumnType: "string",
			DataType:   "varchar(100)",
			IsNullable: false,
			IsIndexed:  true,
		},
		{
			Name:       "Value",
			ColumnName: "value",
			ColumnType: "string",
			DataType:   "varchar(100)",
			IsNullable: true,
			IsIndexed:  true,
		},
		{
			Name:       "ValueType",
			ColumnName: "valuetype",
			ColumnType: "string",
			DataType:   "varchar(100)",
			IsNullable: true,
			IsIndexed:  true,
		},
		{
			Name:       "PreviousValue",
			ColumnName: "previousvalue",
			ColumnType: "string",
			DataType:   "varchar(100)",
			IsNullable: true,
			IsIndexed:  true,
		},
		{
			Name:         "CreatedAt",
			ColumnName:   "created_at",
			ColumnType:   "datetime",
			DataType:     "timestamp",
			DefaultValue: "current_timestamp",
			IsNullable:   false,
			IsIndexed:    true,
		},
		{
			Name:       "UpdatedAt",
			ColumnName: "updated_at",
			ColumnType: "datetime",
			DataType:   "timestamp",
			IsNullable: true,
			IsIndexed:  true,
		},
	},
}
View Source
var (
	ERR_UNAUTHORIZED = errors.New("Unauthorized")
)
View Source
var StandardColumns = []api2go.ColumnInfo{
	{
		Name:            "id",
		ColumnName:      "id",
		DataType:        "INTEGER",
		IsPrimaryKey:    true,
		IsAutoIncrement: true,
		ExcludeFromApi:  true,
		ColumnType:      "id",
	},
	{
		Name:         "created_at",
		ColumnName:   "created_at",
		DataType:     "timestamp",
		DefaultValue: "current_timestamp",
		ColumnType:   "datetime",
		IsIndexed:    true,
	},
	{
		Name:       "updated_at",
		ColumnName: "updated_at",
		DataType:   "timestamp",
		IsIndexed:  true,
		IsNullable: true,
		ColumnType: "datetime",
	},
	{
		Name:           "deleted_at",
		ColumnName:     "deleted_at",
		DataType:       "timestamp",
		ExcludeFromApi: true,
		IsIndexed:      true,
		IsNullable:     true,
		ColumnType:     "datetime",
	},
	{
		Name:       "reference_id",
		ColumnName: "reference_id",
		DataType:   "varchar(40)",
		IsIndexed:  true,
		ColumnType: "alias",
	},
	{
		Name:       "permission",
		ColumnName: "permission",
		DataType:   "int(11)",
		IsIndexed:  false,
		ColumnType: "value",
	},
	{
		Name:         "status",
		ColumnName:   "status",
		DataType:     "varchar(20)",
		DefaultValue: "'pending'",
		IsIndexed:    true,
		ColumnType:   "state",
	},
}
View Source
var StandardRelations = []api2go.TableRelation{
	api2go.NewTableRelation("world_column", "belongs_to", "world"),
	api2go.NewTableRelation("action", "belongs_to", "world"),
	api2go.NewTableRelation("world", "has_many", "smd"),
	api2go.NewTableRelation("oauth_token", "has_one", "oauth_connect"),
	api2go.NewTableRelation("data_exchange", "has_one", "oauth_token"),
}
View Source
var StandardTables = []TableInfo{
	{
		TableName: "world",
		IsHidden:  true,
		Columns: []api2go.ColumnInfo{
			{
				Name:       "table_name",
				ColumnName: "table_name",
				IsNullable: false,
				IsUnique:   true,
				DataType:   "varchar(200)",
				ColumnType: "name",
			},
			{
				Name:       "schema_json",
				ColumnName: "schema_json",
				DataType:   "text",
				IsNullable: false,
				ColumnType: "json",
			},
			{
				Name:         "default_permission",
				ColumnName:   "default_permission",
				DataType:     "int(4)",
				IsNullable:   false,
				DefaultValue: "644",
				ColumnType:   "value",
			},

			{
				Name:         "is_top_level",
				ColumnName:   "is_top_level",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "true",
				ColumnType:   "truefalse",
			},
			{
				Name:         "is_hidden",
				ColumnName:   "is_hidden",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "false",
				ColumnType:   "truefalse",
			},
			{
				Name:         "is_join_table",
				ColumnName:   "is_join_table",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "false",
				ColumnType:   "truefalse",
			},
			{
				Name:         "is_state_tracking_enabled",
				ColumnName:   "is_state_tracking_enabled",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "false",
				ColumnType:   "truefalse",
			},
		},
	},
	{
		TableName: "world_column",
		IsHidden:  true,
		Columns: []api2go.ColumnInfo{
			{
				Name:       "name",
				ColumnName: "name",
				DataType:   "varchar(100)",
				IsIndexed:  true,
				IsNullable: false,
				ColumnType: "name",
			},
			{
				Name:       "column_name",
				ColumnName: "column_name",
				DataType:   "varchar(100)",
				IsIndexed:  true,
				IsNullable: false,
				ColumnType: "name",
			},
			{
				Name:       "column_type",
				ColumnName: "column_type",
				DataType:   "varchar(100)",
				IsNullable: false,
				ColumnType: "label",
			},
			{
				Name:         "is_primary_key",
				ColumnName:   "is_primary_key",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "false",
				ColumnType:   "truefalse",
			},
			{
				Name:         "is_auto_increment",
				ColumnName:   "is_auto_increment",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "false",
				ColumnType:   "truefalse",
			},
			{
				Name:         "is_indexed",
				ColumnName:   "is_indexed",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "false",
				ColumnType:   "truefalse",
			},
			{
				Name:         "is_unique",
				ColumnName:   "is_unique",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "false",
				ColumnType:   "truefalse",
			},
			{
				Name:         "is_nullable",
				ColumnName:   "is_nullable",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "false",
				ColumnType:   "truefalse",
			},
			{
				Name:         "is_foreign_key",
				ColumnName:   "is_foreign_key",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "false",
				ColumnType:   "truefalse",
			},
			{
				Name:         "include_in_api",
				ColumnName:   "include_in_api",
				DataType:     "bool",
				IsNullable:   false,
				DefaultValue: "true",
				ColumnType:   "truefalse",
			},
			{
				Name:       "foreign_key_data",
				ColumnName: "foreign_key_data",
				DataType:   "varchar(100)",
				IsNullable: true,
				ColumnType: "content",
			},
			{
				Name:       "default_value",
				ColumnName: "default_value",
				DataType:   "varchar(100)",
				IsNullable: true,
				ColumnType: "content",
			},
			{
				Name:       "data_type",
				ColumnName: "data_type",
				DataType:   "varchar(50)",
				IsNullable: true,
				ColumnType: "label",
			},
		},
	},
	{
		TableName: "user",
		Columns: []api2go.ColumnInfo{
			{
				Name:       "name",
				ColumnName: "name",
				IsIndexed:  true,
				DataType:   "varchar(80)",
				ColumnType: "name",
			},
			{
				Name:       "email",
				ColumnName: "email",
				DataType:   "varchar(80)",
				IsIndexed:  true,
				IsUnique:   true,
				ColumnType: "email",
			},

			{
				Name:       "password",
				ColumnName: "password",
				DataType:   "varchar(100)",
				ColumnType: "password",
				IsNullable: true,
			},
			{
				Name:         "confirmed",
				ColumnName:   "confirmed",
				DataType:     "boolean",
				ColumnType:   "truefalse",
				IsNullable:   false,
				DefaultValue: "false",
			},
		},
	},
	{
		TableName: "usergroup",
		Columns: []api2go.ColumnInfo{
			{
				Name:       "name",
				ColumnName: "name",
				IsIndexed:  true,
				DataType:   "varchar(80)",
				ColumnType: "name",
			},
		},
	},
	{
		TableName: "action",
		Columns: []api2go.ColumnInfo{
			{
				Name:       "action_name",
				IsIndexed:  true,
				ColumnName: "action_name",
				DataType:   "varchar(100)",
				ColumnType: "name",
			},
			{
				Name:       "label",
				ColumnName: "label",
				IsIndexed:  true,
				DataType:   "varchar(100)",
				ColumnType: "label",
			},
			{
				Name:       "in_fields",
				ColumnName: "in_fields",
				DataType:   "text",
				ColumnType: "json",
			},
			{
				Name:       "out_fields",
				ColumnName: "out_fields",
				DataType:   "text",
				ColumnType: "json",
			},
		},
	},
	{
		TableName: "smd",
		IsHidden:  true,
		Columns: []api2go.ColumnInfo{
			{
				Name:       "name",
				ColumnName: "name",
				IsIndexed:  true,
				DataType:   "varchar(100)",
				ColumnType: "label",
				IsNullable: false,
			},
			{
				Name:       "label",
				ColumnName: "label",
				DataType:   "varchar(100)",
				ColumnType: "label",
				IsNullable: false,
			},
			{
				Name:       "initial_state",
				ColumnName: "initial_state",
				DataType:   "varchar(100)",
				ColumnType: "label",
				IsNullable: false,
			},
			{
				Name:       "events",
				ColumnName: "events",
				DataType:   "text",
				ColumnType: "json",
				IsNullable: false,
			},
		},
	},
	{
		TableName: "oauth_connect",
		IsHidden:  true,
		Columns: []api2go.ColumnInfo{
			{
				Name:       "name",
				ColumnName: "name",
				IsUnique:   true,
				IsIndexed:  true,
				DataType:   "varchar(80)",
				ColumnType: "name",
			},
			{
				Name:       "client_id",
				ColumnName: "client_id",
				DataType:   "varchar(80)",
				ColumnType: "name",
			},
			{
				Name:       "client_secret",
				ColumnName: "client_secret",
				DataType:   "varchar(80)",
				ColumnType: "encrypted",
			},
			{
				Name:         "scope",
				ColumnName:   "scope",
				DataType:     "varchar(1000)",
				ColumnType:   "content",
				DefaultValue: "'https://www.googleapis.com/auth/spreadsheets'",
			},
			{
				Name:         "response_type",
				ColumnName:   "response_type",
				DataType:     "varchar(80)",
				ColumnType:   "name",
				DefaultValue: "'code'",
			},
			{
				Name:       "redirect_uri",
				ColumnName: "redirect_uri",
				DataType:   "varchar(80)",
				ColumnType: "name",
			},
			{
				Name:         "auth_url",
				ColumnName:   "auth_url",
				DataType:     "varchar(200)",
				DefaultValue: "'https://accounts.google.com/o/oauth2/auth'",
				ColumnType:   "url",
			},
			{
				Name:         "token_url",
				ColumnName:   "token_url",
				DataType:     "varchar(200)",
				DefaultValue: "'https://accounts.google.com/o/oauth2/token'",
				ColumnType:   "url",
			},
		},
	},
	{
		TableName: "data_exchange",
		IsHidden:  true,
		Columns: []api2go.ColumnInfo{
			{
				Name:       "name",
				ColumnName: "name",
				ColumnType: "name",
				DataType:   "varchar(200)",
				IsIndexed:  true,
			},
			{
				Name:       "source_attributes",
				ColumnName: "source_attributes",
				ColumnType: "name",
				DataType:   "text",
			},
			{
				Name:       "source_type",
				ColumnName: "source_type",
				ColumnType: "name",
				DataType:   "varchar(100)",
			},
			{
				Name:       "target_attributes",
				ColumnName: "target_attributes",
				ColumnType: "name",
				DataType:   "text",
			},
			{
				Name:       "target_type",
				ColumnName: "target_type",
				ColumnType: "name",
				DataType:   "varchar(100)",
			},
			{
				Name:       "attributes",
				ColumnName: "attributes",
				ColumnType: "json",
				DataType:   "text",
			},
			{
				Name:       "options",
				ColumnName: "options",
				ColumnType: "json",
				DataType:   "text",
			},
		},
	},
	{
		TableName: "oauth_token",
		IsHidden:  true,
		Columns: []api2go.ColumnInfo{
			{
				Name:       "access_token",
				ColumnName: "access_token",
				ColumnType: "encrypted",
				DataType:   "varchar(1000)",
			},
			{
				Name:       "expires_in",
				ColumnName: "expires_in",
				ColumnType: "minutes",
				DataType:   "int(11)",
			},
			{
				Name:       "refresh_token",
				ColumnName: "refresh_token",
				ColumnType: "encrypted",
				DataType:   "varchar(1000)",
			},
			{
				Name:       "token_type",
				ColumnName: "token_type",
				ColumnType: "label",
				DataType:   "varchar(20)",
			},
		},
	},
}
View Source
var SystemActions = []Action{
	{
		Name:   "upload_system_schema",
		Label:  "Upload features",
		OnType: "world",
		InFields: []api2go.ColumnInfo{
			{
				Name:       "Schema JSON file",
				ColumnName: "schema_json_file",
				ColumnType: "file.json",
				IsNullable: false,
			},
		},
		OutFields: []Outcome{
			{
				Type:   "system_json_schema_update",
				Method: "EXECUTE",
				Attributes: map[string]interface{}{
					"json_schema": "$schema_json_file",
				},
			},
		},
	},
	{
		Name:     "download_system_schema",
		Label:    "Download system schema",
		OnType:   "world",
		InFields: []api2go.ColumnInfo{},
		OutFields: []Outcome{
			{
				Type:       "system_json_schema_download",
				Method:     "EXECUTE",
				Attributes: map[string]interface{}{},
			},
		},
	},
	{
		Name:     "invoke_become_admin",
		Label:    "Become GoMS admin",
		OnType:   "world",
		InFields: []api2go.ColumnInfo{},
		OutFields: []Outcome{
			{
				Type:   "become_admin",
				Method: "EXECUTE",
				Attributes: map[string]interface{}{
					"user_id": "$user.id",
				},
			},
		},
	},
	{
		Name:   "signup",
		Label:  "Sign up on Goms",
		OnType: "user",
		InFields: []api2go.ColumnInfo{
			{
				Name:       "name",
				ColumnName: "name",
				ColumnType: "label",
				IsNullable: false,
			},
			{
				Name:       "email",
				ColumnName: "email",
				ColumnType: "email",
				IsNullable: false,
			},
			{
				Name:       "password",
				ColumnName: "password",
				ColumnType: "password",
				IsNullable: false,
			},
			{
				Name:       "Password Confirm",
				ColumnName: "passwordConfirm",
				ColumnType: "password",
				IsNullable: false,
			},
		},
		OutFields: []Outcome{
			{
				Type:      "user",
				Method:    "POST",
				Reference: "user",
				Attributes: map[string]interface{}{
					"name":     "$name",
					"email":    "$email",
					"password": "$password",
				},
			},
			{
				Type:      "usergroup",
				Method:    "POST",
				Reference: "usergroup",
				Attributes: map[string]interface{}{
					"name": "!'Home group for ' + user.name",
				},
			},
			{
				Type:      "user_user_id_has_usergroup_usergroup_id",
				Method:    "POST",
				Reference: "user_usergroup",
				Attributes: map[string]interface{}{
					"user_id":      "$user.reference_id",
					"usergroup_id": "$usergroup.reference_id",
				},
			},
		},
	},
	{
		Name:   "signin",
		Label:  "Sign in to Goms",
		OnType: "user",
		InFields: []api2go.ColumnInfo{
			{
				Name:       "email",
				ColumnName: "email",
				ColumnType: "email",
				IsNullable: false,
			},
			{
				Name:       "password",
				ColumnName: "password",
				ColumnType: "password",
				IsNullable: false,
			},
		},
		OutFields: []Outcome{
			{
				Type:   "jwt.token",
				Method: "EXECUTE",
				Attributes: map[string]interface{}{
					"email":    "$email",
					"password": "$password",
				},
			},
		},
	},
	{
		Name:     "oauth.login.begin",
		Label:    "Authenticate via OAuth",
		OnType:   "oauth_connect",
		InFields: []api2go.ColumnInfo{},
		OutFields: []Outcome{
			{
				Type:   "oauth.client.redirect",
				Method: "EXECUTE",
				Attributes: map[string]interface{}{
					"authenticator": "$.name",
					"scope":         "$.scope",
				},
			},
		},
	},
	{
		Name:   "oauth.login.response",
		Label:  "",
		OnType: "oauth_token",
		InFields: []api2go.ColumnInfo{
			{
				Name:       "code",
				ColumnName: "code",
				ColumnType: "hidden",
				IsNullable: false,
			},
			{
				Name:       "state",
				ColumnName: "state",
				ColumnType: "hidden",
				IsNullable: false,
			},
			{
				Name:       "authenticator",
				ColumnName: "authenticator",
				ColumnType: "hidden",
				IsNullable: false,
			},
		},
		OutFields: []Outcome{
			{
				Type:   "oauth.login.response",
				Method: "EXECUTE",
				Attributes: map[string]interface{}{
					"authenticator": "$authenticator",
				},
			},
		},
	},
	{
		Name:   "add.exchange",
		Label:  "Add new data exchange",
		OnType: "oauth_token",
		InFields: []api2go.ColumnInfo{
			{
				Name:       "name",
				ColumnName: "name",
				ColumnType: "name",
				IsNullable: false,
			},
			{
				Name:           "sheet_id",
				ColumnName:     "sheet_id",
				ColumnType:     "alias",
				IsForeignKey:   true,
				ForeignKeyData: api2go.ForeignKeyData{},
			},
		},
	},
}
View Source
var SystemExchanges = []ExchangeContract{}
View Source
var SystemSmds = []LoopbookFsmDescription{}

Functions

func BcryptCheckStringHash

func BcryptCheckStringHash(newString, hash string) bool

func BcryptHashString

func BcryptHashString(password string) (string, error)

func BuildOutcome

func BuildOutcome(inFieldMap map[string]interface{}, outcome Outcome) (*api2go.Api2GoModel, api2go.Request, error)

func CheckAllTableStatus

func CheckAllTableStatus(initConfig *CmsConfig, db *sqlx.DB)

func CheckErr

func CheckErr(err error, message string)

func CheckError

func CheckError(err error, msg string)

func CheckRelations

func CheckRelations(config *CmsConfig, db *sqlx.DB)

func CheckTable

func CheckTable(tableInfo *TableInfo, db *sqlx.DB)

func CreateAMapOfColumnsWeWantInTheFinalTable

func CreateAMapOfColumnsWeWantInTheFinalTable(tableInfo *TableInfo) (map[string]bool, map[string]api2go.ColumnInfo)

func CreateGetActionHandler

func CreateGetActionHandler(initConfig *CmsConfig, configStore *ConfigStore, cruds map[string]*DbResource) func(*gin.Context)

func CreateGuestActionListHandler

func CreateGuestActionListHandler(initConfig *CmsConfig, cruds map[string]*DbResource) func(*gin.Context)

func CreateIndexes

func CreateIndexes(initConfig *CmsConfig, db *sqlx.DB)

func CreatePostActionHandler

func CreatePostActionHandler(initConfig *CmsConfig, configStore *ConfigStore, cruds map[string]*DbResource, actionPerformers []ActionPerformerInterface) func(*gin.Context)

func CreateRelations

func CreateRelations(initConfig *CmsConfig, db *sqlx.DB)

func CreateTable

func CreateTable(tableInfo *TableInfo, db *sqlx.DB)

func CreateUniqueConstraints

func CreateUniqueConstraints(initConfig *CmsConfig, db *sqlx.DB)

func Decrypt

func Decrypt(key []byte, cryptoText string) (string, error)

Decrypt from base64 to decrypted string

func Encrypt

func Encrypt(key []byte, text string) (string, error)

Encrypt string to base64 crypto using AES

func GetActionMapByTypeName

func GetActionMapByTypeName(db *sqlx.DB) (map[string]map[string]interface{}, error)

func GetAdminUserIdAndUserGroupId

func GetAdminUserIdAndUserGroupId(db *sqlx.DB) (int64, int64)

func GetMD5Hash

func GetMD5Hash(text string) string

func GetOauthConnectionById

func GetOauthConnectionById(authenticatorId int64, dbResource *DbResource) (*oauth2.Config, string, error)

func GetOauthConnectionDescription

func GetOauthConnectionDescription(authenticator string, dbResource *DbResource) (*oauth2.Config, string, error)

func GetObjectByWhereClause

func GetObjectByWhereClause(objType string, db *sqlx.DB, queries ...squirrel.Eq) ([]map[string]interface{}, error)

func GetValidatedInFields

func GetValidatedInFields(actionRequest ActionRequest, action Action) (map[string]interface{}, error)

func GetWorldTableMapBy

func GetWorldTableMapBy(col string, db *sqlx.DB) (map[string]map[string]interface{}, error)

func MakeCreateTableQuery

func MakeCreateTableQuery(tableInfo *TableInfo, sqlDriverName string) string

func NewClientNotification

func NewClientNotification(notificationType string, message string, title string) map[string]interface{}

func NewMapStringScan

func NewMapStringScan(columnNames []string) *mapStringScan

func NewResponse

func NewResponse(metadata map[string]interface{}, result interface{}, statusCode int, pagination *api2go.Pagination) api2go.Responder

func ReferenceIdToIntegerId

func ReferenceIdToIntegerId(typeName string, referenceId string, db *sqlx.DB) (int64, error)

func RowsToMap

func RowsToMap(rows *sqlx.Rows, typeName string) ([]map[string]interface{}, error)

func UpdateActionTable

func UpdateActionTable(initConfig *CmsConfig, db *sqlx.DB) error

func UpdateExchanges

func UpdateExchanges(initConfig *CmsConfig, db *sqlx.DB)

func UpdateStateMachineDescriptions

func UpdateStateMachineDescriptions(initConfig *CmsConfig, db *sqlx.DB)

func UpdateWorldColumnTable

func UpdateWorldColumnTable(initConfig *CmsConfig, db *sqlx.DB)

func UpdateWorldTable

func UpdateWorldTable(initConfig *CmsConfig, db *sqlx.DB)

func ValueOf

func ValueOf(x interface{}) interface{}

Types

type Action

type Action struct {
	Name        string              `json:"name"`
	Label       string              `json:"label"`
	OnType      string              `json:"onType"`
	ReferenceId string              `json:"reference_id"`
	InFields    []api2go.ColumnInfo `json:"fields"`
	OutFields   []Outcome           `json:"outcomes"`
}

type ActionPerformerInterface

type ActionPerformerInterface interface {
	DoAction(request ActionRequest, inFields map[string]interface{}) ([]ActionResponse, []error)
	Name() string
}

func NewBecomeAdminPerformer

func NewBecomeAdminPerformer(initConfig *CmsConfig, cruds map[string]*DbResource) (ActionPerformerInterface, error)

func NewDownloadCmsConfigPerformer

func NewDownloadCmsConfigPerformer(initConfig *CmsConfig) (ActionPerformerInterface, error)

func NewGenerateJwtTokenPerformer

func NewGenerateJwtTokenPerformer(configStore *ConfigStore, cruds map[string]*DbResource) (ActionPerformerInterface, error)

func NewOauthLoginBeginActionPerformer

func NewOauthLoginBeginActionPerformer(initConfig *CmsConfig, cruds map[string]*DbResource, configStore *ConfigStore) (ActionPerformerInterface, error)

func NewOauthLoginResponseActionPerformer

func NewOauthLoginResponseActionPerformer(initConfig *CmsConfig, cruds map[string]*DbResource, configStore *ConfigStore) (ActionPerformerInterface, error)

func NewRestarSystemPerformer

func NewRestarSystemPerformer(initConfig *CmsConfig) (ActionPerformerInterface, error)

type ActionRequest

type ActionRequest struct {
	Type       string
	Action     string
	Attributes map[string]interface{}
}

type ActionResponse

type ActionResponse struct {
	ResponseType string
	Attributes   interface{}
}

func NewActionResponse

func NewActionResponse(responseType string, attrs interface{}) ActionResponse

type ActionRow

type ActionRow struct {
	Name        string `json:"name"`
	Label       string `json:"label"`
	OnType      string `json:"onType"`
	ReferenceId string `json:"reference_id"`
	InFields    string `json:"fields"`
	OutFields   string `json:"outcomes"`
}

type AuthBossUser

type AuthBossUser struct {
	ID   int
	Name string

	// Auth
	Email    string
	Password string

	// OAuth2
	Oauth2Uid      string
	Oauth2Provider string
	Oauth2Token    string
	Oauth2Refresh  string
	Oauth2Expiry   time.Time

	// Confirm
	ConfirmToken string
	Confirmed    bool

	// Lock
	AttemptNumber int64
	AttemptTime   time.Time
	Locked        time.Time

	// Recover
	RecoverToken       string
	RecoverTokenExpiry time.Time
}

type BecomeAdminActionPerformer

type BecomeAdminActionPerformer struct {
	// contains filtered or unexported fields
}

func (*BecomeAdminActionPerformer) DoAction

func (d *BecomeAdminActionPerformer) DoAction(request ActionRequest, inFieldMap map[string]interface{}) ([]ActionResponse, []error)

func (*BecomeAdminActionPerformer) Name

type Change

type Change struct {
	ChangeType changeType
	OldValue   interface{}
	NewValue   interface{}
}

func Diff

func Diff(a, b interface{}) (desc []Change)

Diff returns a slice where each element describes a difference between a and b.

func Fdiff

func Fdiff(a, b interface{}) []Change

Fdiff writes to w a description of the differences between a and b.

type CmsConfig

type CmsConfig struct {
	Tables                   []TableInfo
	StateMachineDescriptions []LoopbookFsmDescription `json:"state_machine_descriptions"`
	Relations                []api2go.TableRelation
	Actions                  []Action           `json:"actions"`
	ExchangeContracts        []ExchangeContract `json:"exchanges"`
}

type ColumnMap

type ColumnMap struct {
	SourceColumn     string
	SourceColumnType string
	TargetColumn     string
	TargetColumnType string
}

type ColumnMapping

type ColumnMapping []ColumnMap

func (*ColumnMapping) UnmarshalJSON

func (c *ColumnMapping) UnmarshalJSON(payload []byte) error

type Config

type Config struct {
	Name          string
	ConfigType    string // web/backend/mobile
	ConfigState   string // enabled/disabled
	ConfigEnv     string // debug/test/release
	Value         string
	ValueType     string // number/string/byteslice
	PreviousValue string
	UpdatedAt     time.Time
}

type ConfigStore

type ConfigStore struct {
	// contains filtered or unexported fields
}

func NewConfigStore

func NewConfigStore(db *sqlx.DB) (*ConfigStore, error)

func (*ConfigStore) GetConfigValueFor

func (c *ConfigStore) GetConfigValueFor(key string, configtype string) (string, error)

func (*ConfigStore) GetWebConfig

func (c *ConfigStore) GetWebConfig() map[string]string

func (*ConfigStore) SetConfigValueFor

func (c *ConfigStore) SetConfigValueFor(key string, val string, configtype string) error

func (*ConfigStore) SetDefaultEnv

func (c *ConfigStore) SetDefaultEnv(env string)

type DatabaseRequestInterceptor

type DatabaseRequestInterceptor interface {
	InterceptBefore(*DbResource, *api2go.Request) (api2go.Responder, error)
	InterceptAfter(*DbResource, *api2go.Request, []map[string]interface{}) ([]map[string]interface{}, error)
	fmt.Stringer
}

func NewCreateEventHandler

func NewCreateEventHandler() DatabaseRequestInterceptor

func NewDeleteEventHandler

func NewDeleteEventHandler() DatabaseRequestInterceptor

func NewExchangeMiddleware

func NewExchangeMiddleware(cmsConfig *CmsConfig, cruds *map[string]*DbResource) DatabaseRequestInterceptor

func NewFindOneEventHandler

func NewFindOneEventHandler() DatabaseRequestInterceptor

func NewUpdateEventHandler

func NewUpdateEventHandler() DatabaseRequestInterceptor

type DbResource

type DbResource struct {
	// contains filtered or unexported fields
}

func NewDbResource

func NewDbResource(model *api2go.Api2GoModel, db *sqlx.DB, ms *MiddlewareSet, cruds map[string]*DbResource, configStore *ConfigStore) *DbResource

func (*DbResource) BecomeAdmin

func (dbResource *DbResource) BecomeAdmin(userId int64) bool

func (*DbResource) CanBecomeAdmin

func (dbResource *DbResource) CanBecomeAdmin() bool

func (*DbResource) Create

func (dr *DbResource) Create(obj interface{}, req api2go.Request) (api2go.Responder, error)

func (*DbResource) Delete

func (dr *DbResource) Delete(id string, req api2go.Request) (api2go.Responder, error)

func (*DbResource) FindOne

func (dr *DbResource) FindOne(referenceId string, req api2go.Request) (api2go.Responder, error)

FindOne returns an object by its ID Possible Responder success status code 200

func (*DbResource) GetActionByName

func (dr *DbResource) GetActionByName(typeName string, actionName string) (Action, error)

func (*DbResource) GetActionPermissionByName

func (dr *DbResource) GetActionPermissionByName(worldId int64, actionName string) (Permission, error)

func (*DbResource) GetActionsByType

func (dr *DbResource) GetActionsByType(typeName string) ([]Action, error)

func (*DbResource) GetContext

func (dr *DbResource) GetContext(key string) interface{}

func (*DbResource) GetIdByWhereClause

func (dr *DbResource) GetIdByWhereClause(typeName string, queries ...squirrel.Eq) ([]int64, error)

func (*DbResource) GetIdToObject

func (dr *DbResource) GetIdToObject(typeName string, id int64) (map[string]interface{}, error)

func (*DbResource) GetIdToReferenceId

func (dr *DbResource) GetIdToReferenceId(typeName string, id int64) (string, error)

func (*DbResource) GetOauthDescriptionByTokenId

func (resource *DbResource) GetOauthDescriptionByTokenId(id *int64) (*oauth2.Config, error)

func (*DbResource) GetObjectGroupsByObjectId

func (dr *DbResource) GetObjectGroupsByObjectId(objType string, objectId int64) []auth.GroupPermission

func (*DbResource) GetObjectPermission

func (dr *DbResource) GetObjectPermission(objectType string, referenceId string) Permission

func (*DbResource) GetObjectPermissionByWhereClause

func (dr *DbResource) GetObjectPermissionByWhereClause(objectType string, colName string, colValue string) Permission

func (*DbResource) GetObjectUserGroupsByWhere

func (dr *DbResource) GetObjectUserGroupsByWhere(objType string, colName string, colvalue string) []auth.GroupPermission

func (*DbResource) GetReferenceIdByWhereClause

func (dr *DbResource) GetReferenceIdByWhereClause(typeName string, queries ...squirrel.Eq) ([]string, error)

func (*DbResource) GetReferenceIdToId

func (dr *DbResource) GetReferenceIdToId(typeName string, referenceId string) (uint64, error)

func (*DbResource) GetReferenceIdToObject

func (dr *DbResource) GetReferenceIdToObject(typeName string, referenceId string) (map[string]interface{}, error)

func (*DbResource) GetRowPermission

func (dr *DbResource) GetRowPermission(row map[string]interface{}) Permission

func (*DbResource) GetRowsByWhereClause

func (dr *DbResource) GetRowsByWhereClause(typeName string, where squirrel.Eq) ([]map[string]interface{}, [][]map[string]interface{}, error)

func (*DbResource) GetSingleColumnValueByReferenceId

func (dr *DbResource) GetSingleColumnValueByReferenceId(typeName string, selectColumn, matchColumn string, values []string) ([]interface{}, error)

func (*DbResource) GetSingleRowByReferenceId

func (dr *DbResource) GetSingleRowByReferenceId(typeName string, referenceId string) (map[string]interface{}, []map[string]interface{}, error)

func (*DbResource) GetTokenForExchangeByTokenId

func (resource *DbResource) GetTokenForExchangeByTokenId(id *int64) (*oauth2.Token, error)

func (*DbResource) GetTotalCount

func (dr *DbResource) GetTotalCount() uint64

func (*DbResource) GetUserGroupIdByUserId

func (dr *DbResource) GetUserGroupIdByUserId(userId uint64) uint64

func (*DbResource) IsUserActionAllowed

func (dr *DbResource) IsUserActionAllowed(userReferenceId string, userGroups []auth.GroupPermission, typeName string, actionName string) bool

func (*DbResource) PaginatedFindAll

func (dr *DbResource) PaginatedFindAll(req api2go.Request) (totalCount uint, response api2go.Responder, err error)

PaginatedFindAll(req Request) (totalCount uint, response Responder, err error)

func (*DbResource) PutContext

func (dr *DbResource) PutContext(key string, val interface{})

func (*DbResource) ResultToArrayOfMap

func (dr *DbResource) ResultToArrayOfMap(rows *sqlx.Rows, columnMap map[string]api2go.ColumnInfo, includeNextLevel bool) ([]map[string]interface{}, [][]map[string]interface{}, error)

func (*DbResource) Update

func (dr *DbResource) Update(obj interface{}, req api2go.Request) (api2go.Responder, error)

Update an object Possible Responder status codes are: - 200 OK: Update successful, however some field(s) were changed, returns updates source - 202 Accepted: Processing is delayed, return nothing - 204 No Content: Update was successful, no fields were changed by the server, return nothing

func (*DbResource) UpdateAccessToken

func (resource *DbResource) UpdateAccessToken(id *int64, accessToken string, expiresIn int64) error

type DownloadCmsConfigActionPerformer

type DownloadCmsConfigActionPerformer struct {
	// contains filtered or unexported fields
}

func (*DownloadCmsConfigActionPerformer) DoAction

func (d *DownloadCmsConfigActionPerformer) DoAction(request ActionRequest, inFields map[string]interface{}) ([]ActionResponse, []error)

func (*DownloadCmsConfigActionPerformer) Name

type ExchangeContract

type ExchangeContract struct {
	Name             string
	SourceAttributes map[string]interface{} `db:"source_name",json:"source_name"`
	SourceType       string                 `db:"source_type",json:"source_type"`
	TargetAttributes map[string]interface{} `db:"target_name",json:"target_name"`
	TargetType       string                 `db:"target_type",json:"target_type"`
	Attributes       []ColumnMap            `db:"attributes",json:"attributes"`
	Options          map[string]interface{}
	ReferenceId      string `db:"reference_id",json:"reference_id"`
	OauthTokenId     *int64 `db:"oauth_token_id",json:"oauth_token_id"`
}

type ExchangeExecution

type ExchangeExecution struct {
	ExchangeContract ExchangeContract
	// contains filtered or unexported fields
}

func NewExchangeExecution

func NewExchangeExecution(exchange ExchangeContract, oauthToken *oauth2.Token, oauthConfig *oauth2.Config) *ExchangeExecution

func (*ExchangeExecution) Execute

func (ec *ExchangeExecution) Execute(inFields map[string]interface{}, data []map[string]interface{}) (err error)

type ExchangeInterface

type ExchangeInterface interface {
	Update(target string, data []map[string]interface{}) error
}

type ExchangeMiddleware

type ExchangeMiddleware struct {
	// contains filtered or unexported fields
}

func (*ExchangeMiddleware) InterceptAfter

func (em *ExchangeMiddleware) InterceptAfter(dr *DbResource, req *api2go.Request, results []map[string]interface{}) ([]map[string]interface{}, error)

func (*ExchangeMiddleware) InterceptBefore

func (em *ExchangeMiddleware) InterceptBefore(dr *DbResource, req *api2go.Request) (api2go.Responder, error)

func (*ExchangeMiddleware) String

func (em *ExchangeMiddleware) String() string

type ExternalExchange

type ExternalExchange interface {
	ExecuteTarget(row map[string]interface{}, inFieldMap map[string]interface{}) error
}

func NewRestExchangeHandler

func NewRestExchangeHandler(exchangeContext ExchangeContract, oauthToken *oauth2.Token, oauthConfig *oauth2.Config) (ExternalExchange, error)

type FsmManager

type FsmManager interface {
	ApplyEvent(subject map[string]interface{}, stateMachineEvent StateMachineEvent) (string, error)
}

func NewFsmManager

func NewFsmManager(db *sqlx.DB, cruds map[string]*DbResource) FsmManager

type GenerateJwtTokenActionPerformer

type GenerateJwtTokenActionPerformer struct {
	// contains filtered or unexported fields
}

func (*GenerateJwtTokenActionPerformer) DoAction

func (d *GenerateJwtTokenActionPerformer) DoAction(request ActionRequest, inFieldMap map[string]interface{}) ([]ActionResponse, []error)

func (*GenerateJwtTokenActionPerformer) Name

type LoopbackEventDesc

type LoopbackEventDesc struct {
	// Name is the event name used when calling for a transition.
	Name  string
	Label string
	Color string

	// Src is a slice of source states that the FSM must be in to perform a
	// state transition.
	Src []string

	// Dst is the destination state that the FSM will be in if the transition
	// succeds.
	Dst string
}

type LoopbookFsmDescription

type LoopbookFsmDescription struct {
	InitialState string `json:"initial_state"`
	Name         string
	Label        string
	Events       []LoopbackEventDesc `json:"events"`
}

type MemStorer

type MemStorer struct {
	Users  map[string]AuthBossUser
	Tokens map[string][]string
	// contains filtered or unexported fields
}

func NewMemStorer

func NewMemStorer(userCrud *DbResource) *MemStorer

func (MemStorer) AddToken

func (s MemStorer) AddToken(key, token string) error

func (MemStorer) ConfirmUser

func (s MemStorer) ConfirmUser(tok string) (result interface{}, err error)

func (MemStorer) Create

func (s MemStorer) Create(key string, attr authboss.Attributes) error

func (MemStorer) DelTokens

func (s MemStorer) DelTokens(key string) error

func (MemStorer) Get

func (s MemStorer) Get(key string) (result interface{}, err error)

func (MemStorer) GetOAuth

func (s MemStorer) GetOAuth(uid, provider string) (result interface{}, err error)

func (MemStorer) Put

func (s MemStorer) Put(key string, attr authboss.Attributes) error

func (MemStorer) PutOAuth

func (s MemStorer) PutOAuth(uid, provider string, attr authboss.Attributes) error

func (MemStorer) RecoverUser

func (s MemStorer) RecoverUser(rec string) (result interface{}, err error)

func (MemStorer) UseToken

func (s MemStorer) UseToken(givenKey, token string) error

type MiddlewareSet

type MiddlewareSet struct {
	BeforeCreate  []DatabaseRequestInterceptor
	BeforeFindAll []DatabaseRequestInterceptor
	BeforeFindOne []DatabaseRequestInterceptor
	BeforeUpdate  []DatabaseRequestInterceptor
	BeforeDelete  []DatabaseRequestInterceptor

	AfterCreate  []DatabaseRequestInterceptor
	AfterFindAll []DatabaseRequestInterceptor
	AfterFindOne []DatabaseRequestInterceptor
	AfterUpdate  []DatabaseRequestInterceptor
	AfterDelete  []DatabaseRequestInterceptor
}

type OauthLoginBeginActionPerformer

type OauthLoginBeginActionPerformer struct {
	// contains filtered or unexported fields
}

func (*OauthLoginBeginActionPerformer) DoAction

func (d *OauthLoginBeginActionPerformer) DoAction(request ActionRequest, inFieldMap map[string]interface{}) ([]ActionResponse, []error)

func (*OauthLoginBeginActionPerformer) Name

type OauthLoginResponseActionPerformer

type OauthLoginResponseActionPerformer struct {
	// contains filtered or unexported fields
}

func (*OauthLoginResponseActionPerformer) DoAction

func (d *OauthLoginResponseActionPerformer) DoAction(request ActionRequest, inFieldMap map[string]interface{}) ([]ActionResponse, []error)

func (*OauthLoginResponseActionPerformer) Name

type Outcome

type Outcome struct {
	Type       string `json:"type"`
	Method     string `json:"method"`
	Reference  string
	Attributes map[string]interface{} `json:"attributes"`
}

type Permission

type Permission struct {
	UserId      string                 `json:"user_id"`
	UserGroupId []auth.GroupPermission `json:"usergroup_id"`
	Permission  int64                  `json:"permission"`
}

func (Permission) CanExecute

func (p Permission) CanExecute(userId string, usergroupId []auth.GroupPermission) bool

func (Permission) CanRead

func (p Permission) CanRead(userId string, usergroupId []auth.GroupPermission) bool

func (Permission) CanWrite

func (p Permission) CanWrite(userId string, usergroupId []auth.GroupPermission) bool

func (Permission) CheckBit

func (p1 Permission) CheckBit(userId string, usergroupId []auth.GroupPermission, bit int64) bool

type RestExchange

type RestExchange struct {
	Name        string
	Method      string
	Url         string
	Headers     map[string]interface{}
	Body        map[string]interface{}
	QueryParams map[string]interface{}
}

type RestExternalExchange

type RestExternalExchange struct {
	// contains filtered or unexported fields
}

func (*RestExternalExchange) ExecuteTarget

func (g *RestExternalExchange) ExecuteTarget(row map[string]interface{}, inFieldMap map[string]interface{}) error

type RestartSystemActionPerformer

type RestartSystemActionPerformer struct {
	// contains filtered or unexported fields
}

func (*RestartSystemActionPerformer) DoAction

func (d *RestartSystemActionPerformer) DoAction(request ActionRequest, inFields map[string]interface{}) ([]ActionResponse, []error)

func (*RestartSystemActionPerformer) Name

type StateMachineEvent

type StateMachineEvent interface {
	GetStateMachineInstanceId() string
	GetEventName() string
}

type StateMachineInstance

type StateMachineInstance struct {
	CurrestState   string
	StateMachineId int64
	ObjectId       int64
}

type StatusResponse

type StatusResponse struct {
	Message string
}

type TableAccessPermissionChecker

type TableAccessPermissionChecker struct {
}

func (*TableAccessPermissionChecker) InterceptAfter

func (pc *TableAccessPermissionChecker) InterceptAfter(dr *DbResource, req *api2go.Request, results []map[string]interface{}) ([]map[string]interface{}, error)

func (*TableAccessPermissionChecker) InterceptBefore

func (pc *TableAccessPermissionChecker) InterceptBefore(dr *DbResource, req *api2go.Request) (api2go.Responder, error)

func (*TableAccessPermissionChecker) String

func (pc *TableAccessPermissionChecker) String() string

type TableInfo

type TableInfo struct {
	TableName              string `db:"table_name"`
	TableId                int
	DefaultPermission      int64 `db:"default_permission"`
	Columns                []api2go.ColumnInfo
	StateMachines          []LoopbookFsmDescription
	Relations              []api2go.TableRelation
	IsTopLevel             bool `db:"is_top_level"`
	Permission             int64
	UserId                 uint64 `db:"user_id"`
	IsHidden               bool   `db:"is_hidden"`
	IsJoinTable            bool   `db:"is_join_table"`
	IsStateTrackingEnabled bool   `db:"is_state_tracking_enabled"`
}

type User

type User struct {
	Name       string
	Email      string
	Password   string
	Id         uint64
	CreatedAt  time.Time
	UpdatedAt  time.Time
	Permission int
	Status     string
	DeletedAt  *time.Time `sql:"index"`
}

Jump to

Keyboard shortcuts

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