grafana

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidURL           = errors.New("url is nil")
	ErrRoleNotValid         = errors.New("role is not valid")
	ErrUserNotFound         = errors.New("user not found")
	ErrOrgUserAlreadyMember = errors.New("user is already member of this organization")
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(baseURL *url.URL, cfg gapi.Config) (*Client, error)

func NewMockClient

func NewMockClient(user gapi.User, orgRoleMap map[int64]RoleType) *Client

MockClient returns a Client using a mocked GAPIClient underneat

func (*Client) AddOrgUser

func (c *Client) AddOrgUser(OrgID int64, login string, role string) error

AddOrgUser adds a user, with a role, to an Organization specified by OrgID

func (*Client) CreateUser

func (c *Client) CreateUser(user gapi.User) (int64, error)

CreateUser adds a new global user to Grafana

func (*Client) GetOrCreateUser

func (c *Client) GetOrCreateUser(login, name, email string) (gapi.User, error)

func (*Client) LookupUser

func (c *Client) LookupUser(loginOrEmail string) (gapi.User, error)

LookupUser search for a user by Login or Email and returns it

func (*Client) UpdateOrgUserAuthz

func (c *Client) UpdateOrgUserAuthz(user gapi.User, groups config.Groups) (userOrgsRoleMap, error)

UpdateOrgUserAuthz updates both roles and global admin status for a user taking into account group configuration. It outputs a mapping of role-in-org it will return an error when there's an issue updating the GrafanaAdmin permissions

func (*Client) UpdateUserPermissions

func (c *Client) UpdateUserPermissions(id int64, isAdmin bool) error

func (*Client) UpsertOrgUser

func (c *Client) UpsertOrgUser(orgID int64, user gapi.User, role string) error

UpsertOrgUser adds a user to an Organization if not present or updates the user role if already a member.

type GAPIClient

type GAPIClient interface {
	UserByEmail(email string) (user gapi.User, err error)
	CreateUser(user gapi.User) (int64, error)
	AddOrgUser(orgID int64, user, role string) error
	UpdateOrgUser(orgID, userID int64, role string) error
	UpdateUserPermissions(id int64, isAdmin bool) error
}

type RoleType

type RoleType string
const (
	ROLE_VIEWER RoleType = "Viewer"
	ROLE_EDITOR RoleType = "Editor"
	ROLE_ADMIN  RoleType = "Admin"
)

Grafana pkgs cannot be safely imported as dependencies.

Jump to

Keyboard shortcuts

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