metabase

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2020 License: MIT Imports: 19 Imported by: 0

README

Metabase

Authentication

To query the Metabase API you need to retrieve a bearer token. You can do this with the following cURL command which is also implemented in the AuthRequest function:

curl -v -H "Content-Type: application/json" \
  -d '{"username":"myusername","password":"mypassword"}' \
  -XPOST 'http://example.com/api/session'

You will receive a response like:

{"id":"11112222-3333-4444-5555-666677778888"}

You can then use the id in the X-Metabase-Session header for subsequent API calls. Here's an example:

curl -XGET 'https://example.com/api/database' \
  -H 'X-Metabase-Session: 11112222-3333-4444-5555-666677778888'

Documentation

Index

Constants

View Source
const (
	MetabaseSessionHeader = "X-Metabase-Session"
	RelPathApiDatabase    = "api/database"
	RelPathApiSession     = "api/session"
	RelPathApiUserCurrent = "api/user/current"

	// Example environment variables
	EnvMetabaseBaseUrl       = "METABASE_BASE_URL"
	EnvMetabaseUsername      = "METABASE_USERNAME"
	EnvMetabasePassword      = "METABASE_PASSWORD"
	EnvMetabaseSessionId     = "METABASE_SESSION_ID"
	EnvMetabaseTlsSkipVerify = "METABASE_TLS_SKIP_VERIFY"
)
View Source
const (
	CurrentUserURLPath = "/api/user/current"
)

Variables

View Source
var (
	TLSInsecureSkipVerify = false
)

Functions

func AuthRequest

func AuthRequest(authUrl, username, password string, tlsSkipVerify bool) (*http.Response, error)

AuthRequest creates an authentiation request that returns a id that is used in Metabase API requests. It follows the following curl command: curl -v -H "Content-Type: application/json" -d '{"username":"myusername","password":"mypassword"}' -XPOST 'http://example.com/api/session'

func NewClientSessionId

func NewClientSessionId(sessionId string, tlsSkipVerify bool) *http.Client

func RetrieveQuestions

func RetrieveQuestions(cu ClientUtil, q2s QuestionsToSlug, dir string) (map[string][]byte, error)

Types

type AuthResponse

type AuthResponse struct {
	Id string `json:"id,omitempty"`
}

func NewClient

func NewClient(cfg Config) (*http.Client, *AuthResponse, error)

func NewClientEnv

func NewClientEnv(initCfg InitConfig) (*http.Client, *AuthResponse, error)

func NewClientPassword

func NewClientPassword(baseUrl, username, password string, tlsSkipVerify bool) (*http.Client, *AuthResponse, error)

NewClient returns a *http.Client that will add the Metabase Session header to each request.

func NewClientPasswordWithSessionId

func NewClientPasswordWithSessionId(baseUrl, username, password, sessionId string, tlsSkipVerify bool) (*http.Client, *AuthResponse, error)

NewClientPasswordWithSessionId returns a *http.Client first attempting to use the supplied `sessionId` with a fallback to `username` and `password`.

type ClientUtil

type ClientUtil struct {
	HTTPClient *http.Client
	BaseURL    string
}

func NewClientUtil

func NewClientUtil(baseUrl, username, password string, tlsSkipVerify bool) (*ClientUtil, error)

func (*ClientUtil) BuildMetabaseCardAPI

func (cu *ClientUtil) BuildMetabaseCardAPI(cardId int, format string) string

func (*ClientUtil) GetCurrentUser

func (apiutil *ClientUtil) GetCurrentUser() (User, *http.Response, error)

func (*ClientUtil) GetQuestionData

func (cu *ClientUtil) GetQuestionData(cardId int) ([]byte, error)

func (*ClientUtil) GetSCIMUser

func (apiutil *ClientUtil) GetSCIMUser() (scim.User, error)

func (*ClientUtil) GetStoreQuestionData

func (cu *ClientUtil) GetStoreQuestionData(cardId int, filename string, perm os.FileMode) ([]byte, error)

type Config

type Config struct {
	BaseUrl       string
	SessionId     string
	Username      string
	Password      string
	TlsSkipVerify bool
}

Config is a basic struct to hold API access information for Metabase.

func NewConfigEnv added in v0.3.1

func NewConfigEnv() Config

NewConfigEnv returns a new Config instance populated from default environment variables.

type InitConfig added in v0.3.0

type InitConfig struct {
	LoadEnv              bool
	EnvPath              string
	EnvMetabaseBaseUrl   string
	EnvMetabaseSessionId string
	EnvMetabaseUsername  string
	EnvMetabasePassword  string
	TlsSkipVerify        bool
}

func (*InitConfig) Defaultify added in v0.3.1

func (ic *InitConfig) Defaultify()

type QuestionsToSlug

type QuestionsToSlug struct {
	QuestionMap map[string]int
}

type User

type User struct {
	Email       string    `json:"email,omitempty"`
	LdapAuth    bool      `json:"ldap_auth,omitempty"`
	FirstName   string    `json:"first_name,omitempty"`
	LastLogin   time.Time `json:"last_login,omitempty"`
	IsActive    bool      `json:"is_active,omitempty"`
	IsQbnewb    bool      `json:"is_qbnewb,omitempty"`
	IsSuperuser bool      `json:"is_superuser,omitempty"`
	ID          int       `json:"id,omitempty"`
	LastName    string    `json:"last_name,omitempty"`
	DateJoined  time.Time `json:"date_joined,omitempty"`
	CommonName  string    `json:"common_name,omitempty"`
	GoogleAuth  bool      `json:"google_auth,omitempty"`
}

Directories

Path Synopsis
examples
get_token command
query_card command

Jump to

Keyboard shortcuts

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