metabase

package
v0.12.7 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DatabaseRoleViewer   = "schemas:all"
	DatabaseRoleEditor   = "native:write"
	CollectionRoleViewer = "read"
	CollectionRoleCurate = "write"
	TableRoleViewer      = "all"

	AccountTypeUser = "user"
)
View Source
const (
	ResourceTypeDatabase   = "database"
	ResourceTypeTable      = "table"
	ResourceTypeCollection = "collection"
	ResourceTypeGroup      = "group"

	GuardianGroupPrefix = "_guardian_"
)

Variables

View Source
var (
	ErrInvalidCredentials            = errors.New("invalid credentials type")
	ErrInvalidPermissionConfig       = errors.New("invalid permission config type")
	ErrUnableToEncryptNilCredentials = errors.New("unable to encrypt nil credentials")
	ErrUnableToDecryptNilCredentials = errors.New("unable to decrypt nil credentials")
	ErrUserNotFound                  = errors.New("metabase user not found")
	ErrInvalidRole                   = errors.New("invalid role")
	ErrInvalidResourceType           = errors.New("invalid resource type")
	ErrPermissionNotFound            = errors.New("permission not found")
	ErrInvalidApiResponse            = errors.New("invalid api response")
	ErrInvalidDatabaseURN            = errors.New("database URN is invalid")
	ErrInvalidTableURN               = errors.New("table URN is invalid")
	ErrInvalidGroupURN               = errors.New("group URN is invalid")
	ErrInvalidCollectionURN          = errors.New("collection URN is invalid")
)

Functions

func NewClient

func NewClient(config *ClientConfig, logger log.Logger) (*client, error)

func NewProvider

func NewProvider(typeName string, crypto domain.Crypto, logger log.Logger) *provider

Types

type ClientConfig

type ClientConfig struct {
	Host       string `validate:"required,url" mapstructure:"host"`
	Username   string `validate:"required" mapstructure:"username"`
	Password   string `validate:"required" mapstructure:"password"`
	HTTPClient HTTPClient
}

type Collection

type Collection struct {
	ID              interface{} `json:"id"`
	Name            string      `json:"name"`
	Slug            string      `json:"slug"`
	Location        string      `json:"location,omitempty"`
	Namespace       string      `json:"namespace,omitempty"`
	PersonalOwnerId interface{} `json:"personal_owner_id,omitempty"`
}

func (*Collection) FromDomain

func (c *Collection) FromDomain(r *domain.Resource) error

func (*Collection) ToDomain

func (c *Collection) ToDomain() *domain.Resource

type Config

type Config struct {
	ProviderConfig *domain.ProviderConfig
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(pc *domain.ProviderConfig, crypto domain.Crypto) *Config

func (*Config) EncryptCredentials

func (c *Config) EncryptCredentials() error

func (*Config) ParseAndValidate

func (c *Config) ParseAndValidate() error

type Credentials

type Credentials struct {
	Host     string `json:"host" mapstructure:"host" validate:"required"`
	Username string `json:"username" mapstructure:"username" validate:"required"`
	Password string `json:"password" mapstructure:"password" validate:"required"`
}

func (*Credentials) Decrypt

func (c *Credentials) Decrypt(decryptor domain.Decryptor) error

func (*Credentials) Encrypt

func (c *Credentials) Encrypt(encryptor domain.Encryptor) error

type Database

type Database struct {
	ID                       int     `json:"id" mapstructure:"id"`
	Name                     string  `json:"name" mapstructure:"name"`
	CacheFieldValuesSchedule string  `json:"cache_field_values_schedule" mapstructure:"cache_field_values_schedule"`
	Timezone                 string  `json:"timezone" mapstructure:"timezone"`
	AutoRunQueries           bool    `json:"auto_run_queries" mapstructure:"auto_run_queries"`
	MetadataSyncSchedule     string  `json:"metadata_sync_schedule" mapstructure:"metadata_sync_schedule"`
	Engine                   string  `json:"engine" mapstructure:"engine"`
	NativePermissions        string  `json:"native_permissions" mapstructure:"native_permissions"`
	Tables                   []Table `json:"tables" mapstructure:"tables"`
}

func (*Database) FromDomain

func (d *Database) FromDomain(r *domain.Resource) error

func (*Database) ToDomain

func (d *Database) ToDomain() *domain.Resource

type Group

type Group struct {
	ID                  int              `json:"id" mapstructure:"id"`
	Name                string           `json:"name" mapstructure:"name"`
	DatabaseResources   []*GroupResource `json:"database" mapstructure:"database"`
	CollectionResources []*GroupResource `json:"collection" mapstructure:"collection"`
}

func (*Group) FromDomain

func (g *Group) FromDomain(r *domain.Resource) error

func (*Group) ToDomain

func (g *Group) ToDomain() *domain.Resource

type GroupResource

type GroupResource struct {
	Name        string   `json:"name" mapstructure:"name"`
	Permissions []string `json:"permission" mapstructure:"permission"`
	Urn         string   `json:"urn" mapstructure:"urn"`
	Type        string   `json:"type" mapstructure:"type"`
}

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

type MetabaseClient

type MetabaseClient interface {
	GetDatabases(ctx context.Context) ([]*Database, error)
	GetCollections(ctx context.Context) ([]*Collection, error)
	GetGroups(ctx context.Context) ([]*Group, ResourceGroupDetails, ResourceGroupDetails, error)
	GrantDatabaseAccess(ctx context.Context, resource *Database, user, role string, groups map[string]*Group) error
	RevokeDatabaseAccess(ctx context.Context, resource *Database, user, role string) error
	GrantCollectionAccess(ctx context.Context, resource *Collection, user, role string) error
	RevokeCollectionAccess(ctx context.Context, resource *Collection, user, role string) error
	GrantTableAccess(ctx context.Context, resource *Table, user, role string, groups map[string]*Group) error
	RevokeTableAccess(ctx context.Context, resource *Table, user, role string) error
	GrantGroupAccess(ctx context.Context, groupID int, email string) error
	RevokeGroupAccess(ctx context.Context, groupID int, email string) error
}

type Permission

type Permission string

type ResourceGroupDetails

type ResourceGroupDetails map[string][]map[string]interface{}

type SessionRequest

type SessionRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type SessionResponse

type SessionResponse struct {
	ID string `json:"id"`
}

type Table

type Table struct {
	ID       int              `json:"id" mapstructure:"id"`
	Name     string           `json:"name" mapstructure:"name"`
	DbId     int              `json:"db_id" mapstructure:"db_id"`
	Database *domain.Resource `json:"database" mapstructure:"database"`
}

func (*Table) FromDomain

func (t *Table) FromDomain(r *domain.Resource) error

func (*Table) ToDomain

func (t *Table) ToDomain() *domain.Resource

Jump to

Keyboard shortcuts

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