portal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TempKeyDefaultExpires = 60
	TempKeyDefaultPrefix  = "terraform-provider-grafanacloud-tmp"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID         int
	Name       string
	Role       string
	Token      string
	Expiration string
}

type Client

type Client struct {

	// This client can generate temporary Grafana API admin tokens for the purpose
	// of reading resources from the Grafana API. Define a time after which these
	// tokens automatically expire. Note that we'll also try to delete them automatically
	// after use, but if that fails, this serves as a fallback mechanism to invalidate them.
	TempKeyExpires time.Duration

	// Temporarily created Grafana API admin tokens have a prefix so you can identify them
	// easily, which defaults to the value of constant constant `TempKeyPrefix`.
	TempKeyPrefix string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(baseURL, apiKey string, opts ...ClientOpt) (*Client, error)

func (*Client) AuthTest

func (c *Client) AuthTest(ctx context.Context, org string) error

func (*Client) CreateAPIKey

func (c *Client) CreateAPIKey(ctx context.Context, r *CreateAPIKeyInput) (*APIKey, error)

func (*Client) CreateGrafanaAPIKey

func (c *Client) CreateGrafanaAPIKey(ctx context.Context, r *CreateGrafanaAPIKeyInput) (*CreateGrafanaAPIKeyOutput, error)

This function creates a API key inside the Grafana instance running in stack `stack`. It's used in order to provision API keys inside Grafana while just having access to a Grafana Cloud API key.

Plese note that this is a beta feature and might change in the future.

See https://grafana.com/docs/grafana-cloud/api/#create-grafana-api-keys for more information.

func (*Client) CreateStack

func (c *Client) CreateStack(ctx context.Context, r *CreateStackInput) (*Stack, error)

func (*Client) DeleteAPIKey

func (c *Client) DeleteAPIKey(ctx context.Context, org string, keyName string) error

func (*Client) DeleteStack

func (c *Client) DeleteStack(ctx context.Context, stackSlug string) error

func (*Client) GetAuthedGrafanaClient

func (c *Client) GetAuthedGrafanaClient(ctx context.Context, orgName, stackName string) (*grafana.Client, func() error, error)

The Grafana Cloud API is disconnected from the Grafana API on the stacks unfortunately. That's why we can't use the Grafana Cloud API key to fully manage API keys on the Grafana API. The only thing we can do is to create a temporary Admin key, and create a Grafana API client with that.

func (*Client) GetStack

func (c *Client) GetStack(ctx context.Context, org, stackSlug string) (*Stack, error)

func (*Client) ListAPIKeys

func (c *Client) ListAPIKeys(ctx context.Context, org string) (*ListAPIKeysOutput, error)

func (*Client) ListDatasources

func (c *Client) ListDatasources(ctx context.Context, stack string) (*ListDatasourcesOutput, error)

func (*Client) ListStacks

func (c *Client) ListStacks(ctx context.Context, org string) (*ListStacksOutput, error)

type ClientOpt

type ClientOpt func(*Client)

func WithTempKeyExpires

func WithTempKeyExpires(d time.Duration) ClientOpt

func WithTempKeyPrefix

func WithTempKeyPrefix(prefix string) ClientOpt

func WithUserAgent

func WithUserAgent(userAgent string) ClientOpt

type CreateAPIKeyInput

type CreateAPIKeyInput struct {
	Name         string `json:"name"`
	Role         string `json:"role"`
	Organisation string `json:"-"`
}

type CreateGrafanaAPIKeyInput

type CreateGrafanaAPIKeyInput struct {
	Name          string `json:"name"`
	Role          string `json:"role"`
	SecondsToLive int    `json:"secondsToLive"`
	Stack         string `json:"-"`
}

type CreateGrafanaAPIKeyOutput

type CreateGrafanaAPIKeyOutput grafana.APIKey

type CreateStackInput

type CreateStackInput struct {
	Name string `json:"name"`
	Slug string `json:"slug"`
	URL  string `json:"url"`
}

type Datasource

type Datasource struct {
	ID            int
	InstanceID    int
	InstanceSlug  string
	Name          string
	Type          string
	URL           string
	BasicAuth     int
	BasicAuthUser string
}

func (*Datasource) IsAlertmanager

func (ds *Datasource) IsAlertmanager() bool

type ListAPIKeysOutput

type ListAPIKeysOutput struct {
	Items []*APIKey
}

func (*ListAPIKeysOutput) AddKey

func (l *ListAPIKeysOutput) AddKey(k *APIKey)

func (*ListAPIKeysOutput) DeleteByName

func (l *ListAPIKeysOutput) DeleteByName(name string)

func (*ListAPIKeysOutput) FindByName

func (l *ListAPIKeysOutput) FindByName(name string) *APIKey

type ListDatasourcesOutput

type ListDatasourcesOutput struct {
	Items []*Datasource
}

type ListStacksOutput

type ListStacksOutput struct {
	Items []*Stack
}

func (*ListStacksOutput) AddStack

func (l *ListStacksOutput) AddStack(s *Stack)

func (*ListStacksOutput) DeleteBySlug

func (l *ListStacksOutput) DeleteBySlug(slug string)

func (*ListStacksOutput) FindBySlug

func (l *ListStacksOutput) FindBySlug(slug string) *Stack

type Stack

type Stack struct {
	ID                   int
	OrgID                int
	OrgSlug              string
	OrgName              string
	Name                 string
	URL                  string
	Status               string
	Slug                 string
	HmInstancePromID     int
	HmInstancePromURL    string
	HmInstancePromStatus string
	AmInstanceID         int
	AmInstanceURL        string
}

Jump to

Keyboard shortcuts

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