state

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2023 License: GPL-3.0 Imports: 14 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Connections is all connections
	Connections = map[string]*Connection{}
	Queries     = map[string]*Query{}
	Tokens      = TokenMap{}
	TokenValues = map[string]Token{}
)
View Source
var (
	Roles = RoleMap{}
)
View Source
var Version = "dev"

Version is the version number

Functions

func CloseConnections

func CloseConnections()

GetConnInstance gets the connection instance

func GetConnInstance

func GetConnInstance(connName, databaseName string) (conn database.Connection, err error)

GetConnInstance gets the connection instance

func GetConnObject

func GetConnObject(connName, databaseName string) (connObj connection.Connection, err error)

GetConnInstance gets the connection object

func LoadConnections

func LoadConnections(force bool) (err error)

func LoadRoles added in v0.0.4

func LoadRoles(force bool) (err error)

func LoadTokens added in v0.0.4

func LoadTokens(force bool) (err error)

func SchemaAll

func SchemaAll(connection, schema string) database.Table

SchemaAll returns schema.* notation for all tables in a schema

Types

type AllowSQLValue

type AllowSQLValue string
const (
	AllowSQLDisable AllowSQLValue = "disable"
	AllowSQLAny     AllowSQLValue = "any"
)

type Connection

type Connection struct {
	Conn  connection.Connection
	Props map[string]string // to cache vars
}

Connection is a connection

func (*Connection) DefaultDB

func (c *Connection) DefaultDB() string

DefaultDB returns the default database

type Grant

type Grant struct {
	// AllowRead lists the schema/tables that are allowed to be read from
	AllowRead []string `json:"allow_read" yaml:"allow_read"`
	// AllowWrite lists the schema/tables that are allowed to be written to
	AllowWrite []string `json:"allow_write" yaml:"allow_write"`
	// AllowSQL shows whether a
	AllowSQL AllowSQLValue `json:"allow_sql" yaml:"allow_sql"`
}

func (Grant) GetReadable

func (gt Grant) GetReadable(connection string) (tables []database.Table)

func (Grant) GetWritable

func (gt Grant) GetWritable(connection string) (tables []database.Table)

type Headers

type Headers []string

func (*Headers) Scan

func (h *Headers) Scan(value interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (Headers) Value

func (h Headers) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type Permission

type Permission string
const (
	PermissionNone      Permission = "none"
	PermissionRead      Permission = "read"
	PermissionWrite     Permission = "write"
	PermissionReadWrite Permission = "read_write"
)

func (Permission) CanRead

func (p Permission) CanRead() bool

func (Permission) CanWrite

func (p Permission) CanWrite() bool

type Permissions

type Permissions map[string]Permission

Permissions is a map of all objects for one connection

type Query

type Query struct {
	ID       string `json:"id" query:"id" gorm:"primaryKey"`
	Conn     string `json:"conn" query:"conn" gorm:"index"`
	Database string `json:"database" query:"database" gorm:"index"`
	Text     string `json:"text" query:"text"`
	Limit    int    `json:"limit" query:"limit" gorm:"-"` // -1 is unlimited

	Start   int64       `json:"start" query:"start" gorm:"index:idx_start"`
	End     int64       `json:"end" query:"end"`
	Status  QueryStatus `json:"status" query:"status"`
	Error   string      `json:"error" query:"error"`
	Headers Headers     `json:"headers" query:"headers" gorm:"headers"`

	UpdatedDt time.Time       `json:"-" gorm:"autoUpdateTime"`
	Affected  int64           `json:"affected" gorm:"-"`
	Result    *sqlx.Rows      `json:"-" gorm:"-"`
	Stream    *iop.Datastream `json:"-" gorm:"-"`
	Done      chan struct{}   `json:"-" gorm:"-"`
	Err       error           `json:"-" gorm:"-"`
	Context   g.Context       `json:"-" gorm:"-"`
}

Query represents a query

func NewQuery

func NewQuery(ctx context.Context) *Query

NewQuery creates a Query object

func SubmitOrGetQuery

func SubmitOrGetQuery(q *Query, cont bool) (query *Query, err error)

func (*Query) Cancel

func (q *Query) Cancel() (err error)

func (*Query) Close

func (q *Query) Close(cancel bool) (err error)

Close closes and cancels the query

func (*Query) ProcessResult

func (q *Query) ProcessResult() (err error)

type QueryStatus

type QueryStatus string
const QueryStatusCancelled QueryStatus = "cancelled"
const QueryStatusCompleted QueryStatus = "completed"
const QueryStatusErrored QueryStatus = "errored"
const QueryStatusFetched QueryStatus = "fetched"
const QueryStatusSubmitted QueryStatus = "submitted"

type Role

type Role map[string]Grant

Role is a map of Grants per connection each map key is a connection name each map item is a grant entry for that connection

func (Role) CanRead

func (r Role) CanRead(connection string, table database.Table) bool

func (Role) CanSQL

func (r Role) CanSQL(connection string) bool

func (Role) CanWrite

func (r Role) CanWrite(connection string, table database.Table) bool

type RoleMap

type RoleMap map[string]Role

RoleMap is a map of roles each map key is a role name each map item is a Role entry for that role

func GetRoleMap added in v0.0.4

func GetRoleMap(roles []string) (rm RoleMap)

func (RoleMap) CanSQL added in v0.0.4

func (rm RoleMap) CanSQL(connection string) bool

func (RoleMap) GetPermissions

func (rm RoleMap) GetPermissions(connection string) (perms Permissions)

type Row

type Row []interface{}

func (*Row) Scan

func (r *Row) Scan(value interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (Row) Value

func (r Row) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type Rows

type Rows [][]interface{}

func (*Rows) Scan

func (r *Rows) Scan(value interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (Rows) Value

func (r Rows) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type Token added in v0.0.4

type Token struct {
	Token    string    `json:"token"`
	Roles    []string  `json:"roles"`
	Disabled bool      `json:"disabled"`
	IssuedAt time.Time `json:"issued_at"`
}

func NewToken added in v0.0.4

func NewToken(roles []string) Token

func ResolveToken added in v0.0.4

func ResolveToken(value string) (token Token, ok bool)

type TokenMap added in v0.0.4

type TokenMap map[string]Token

TokenMap is map of string to token

func (TokenMap) Add added in v0.0.4

func (tm TokenMap) Add(name string, token Token) (err error)

func (TokenMap) Get added in v0.0.4

func (tm TokenMap) Get(name string, token Token) (err error)

func (TokenMap) Remove added in v0.0.4

func (tm TokenMap) Remove(name string) (err error)

func (*TokenMap) Save added in v0.0.4

func (tm *TokenMap) Save() (err error)

func (TokenMap) Toggle added in v0.0.4

func (tm TokenMap) Toggle(name string) (disabled bool, err error)

Jump to

Keyboard shortcuts

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