state

package
v0.0.70 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: GPL-3.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AllowAllRoleMap = RoleMap{
		"*": Role{
			"*": Grant{
				AllowRead:  []string{"*"},
				AllowWrite: []string{"*"},
				AllowSQL:   AllowSQLAny,
			},
		},
	}
)
View Source
var DefaultProjectID = "default"
View Source
var Projects = map[string]*Project{}
View Source
var (

	// set a build time.
	RudderstackURL = ""
)
View Source
var Version = "dev"

Version is the version number

Functions

func ClearOldQueries added in v0.0.36

func ClearOldQueries()

func CloseConnections

func CloseConnections()

GetConnInstance gets the connection instance

Types

type AllowSQLValue

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

type Connection

type Connection struct {
	Conn   connection.Connection
	Source string
	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(conn connection.Connection) (tables []database.Table)

func (Grant) GetWritable

func (gt Grant) GetWritable(conn connection.Connection) (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 Project added in v0.0.53

type Project struct {
	ID        string
	Directory string

	Connections map[string]*Connection
	Queries     map[string]*Query
	Tokens      TokenMap
	TokenValues map[string]Token

	Roles         RoleMap
	NoRestriction bool

	EnvFile   string
	TokenFile string
	RolesFile string
	// contains filtered or unexported fields
}

func DefaultProject added in v0.0.53

func DefaultProject() (proj *Project)

func LoadProject added in v0.0.53

func LoadProject(id string) (proj *Project)

func NewProject added in v0.0.53

func NewProject(id, directory string, noRestriction bool) (proj *Project)

func (*Project) GetConnInstance added in v0.0.53

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

func (*Project) GetConnObject added in v0.0.53

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

func (*Project) GetRoleMap added in v0.0.53

func (p *Project) GetRoleMap(roles []string) (rm RoleMap)

func (*Project) LoadConnections added in v0.0.53

func (p *Project) LoadConnections(force bool) (err error)

func (*Project) LoadRoles added in v0.0.53

func (p *Project) LoadRoles(force bool) (err error)

func (*Project) LoadTokens added in v0.0.53

func (p *Project) LoadTokens(force bool) (err error)

func (*Project) NewQuery added in v0.0.53

func (p *Project) NewQuery(ctx context.Context) *Query

func (*Project) ResolveToken added in v0.0.53

func (p *Project) ResolveToken(value string) (token Token, ok bool)

func (*Project) SchemaAll added in v0.0.53

func (p *Project) SchemaAll(connection, schema string) (table database.Table)

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

func (*Project) TokenAdd added in v0.0.53

func (p *Project) TokenAdd(name string, token Token) (err error)

func (*Project) TokenGet added in v0.0.53

func (p *Project) TokenGet(name string, token Token) (err error)

func (*Project) TokenRemove added in v0.0.53

func (p *Project) TokenRemove(name string) (err error)

func (*Project) TokenSave added in v0.0.53

func (p *Project) TokenSave() (err error)

func (*Project) TokenToggle added in v0.0.53

func (p *Project) TokenToggle(name string) (disabled bool, err error)

type Query

type Query struct {
	ID       string `json:"id" query:"id" gorm:"primaryKey"`
	Project  string `json:"project" query:"project" gorm:"index"`
	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"`
	Err     string      `json:"err" query:"err"`
	Headers Headers     `json:"headers" query:"headers" gorm:"headers"`

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

	IsGenerated bool `json:"-" gorm:"-"`
	// contains filtered or unexported fields
}

Query represents a query

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)

func (*Query) Submit added in v0.0.39

func (q *Query) Submit() (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) CanSQL

func (r Role) CanSQL(connection string) 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 (RoleMap) CanSQL added in v0.0.4

func (rm RoleMap) CanSQL(connection string) bool

func (RoleMap) GetPermissions

func (rm RoleMap) GetPermissions(conn connection.Connection) (perms Permissions)

func (RoleMap) HasAccess added in v0.0.27

func (rm RoleMap) HasAccess(connection string) bool

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

type TokenMap added in v0.0.4

type TokenMap map[string]Token

TokenMap is map of string to token

Jump to

Keyboard shortcuts

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