restds

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HeaderKeyAccept        = "Accept"
	HeaderKeyContentType   = "Content-Type"
	HeaderKeyAuthorization = "Authorization"
)

Variables

This section is empty.

Functions

func GetRequest

func GetRequest(config Config, query Query, headersFromGrafana map[string]string) (*http.Request, error)

func NewHTTPClient

func NewHTTPClient(config *Config) *http.Client

func NewPlugin

func NewPlugin(restDriver RestDriver, restDriverOptions RestDriverOptions) datasource.ServeOpts

func QueryData

func QueryData(ctx context.Context, backendQuery backend.DataQuery, instance datasourceInstance, headersFromGrafana map[string]string, pluginContext backend.PluginContext) backend.DataResponse

func QueryDataResponse

func QueryDataResponse(ctx context.Context, instance *datasourceInstance, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)

func SpecFromJson

func SpecFromJson(jsonString string) (openapi3.Spec, error)

Types

type APIKeyType

type APIKeyType string
const (
	ApiKeyTypeHeader APIKeyType = "header"
	ApiKeyTypeQuery  APIKeyType = "query"
)

type AuthType

type AuthType string
const (
	AuthTypeNone         AuthType = "none"
	AuthTypeBasic        AuthType = "basicAuth"
	AuthTypeBearerToken  AuthType = "bearerToken"
	AuthTypeApiKey       AuthType = "apiKey"
	AuthTypeForwardOauth AuthType = "oauthPassThru"
	AuthTypeDigestAuth   AuthType = "digestAuth"
	AuthTypeOAuth2       AuthType = "oauth2"
)

type BodyType

type BodyType string
const (
	BodyTypeNone         BodyType = "none"
	BodyTypeRaw          BodyType = "raw"
	BodyTypeFormData     BodyType = "form-data"
	BodyTypeFormReloaded BodyType = "x-www-form-urlencoded"
	BodyTypeGraphQL      BodyType = "graphql"
)

type Config

type Config struct {
	BaseURL              string
	AuthenticationMethod AuthType
	BasicAuthUser        string
	BasicAuthPassword    string
	ApiKeyType           APIKeyType
	ApiKeyKey            string
	ApiKeyValue          string
	BearerToken          string
	Headers              map[string]string
	QueryParams          map[string]string
	OAuth2Settings       struct {
		Type           OAuth2Type
		TokenURL       string
		ClientID       string
		ClientSecret   string
		Email          string
		PrivateKeyID   string
		PrivateKey     string
		Subject        string
		Scopes         []string
		EndpointParams map[string]string
	}
}

func (*Config) Validate

func (c *Config) Validate() error

type KV

type KV struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type OAuth2Type

type OAuth2Type string
const (
	OAuth2TypeClientCredentials OAuth2Type = "client_credentials"
	OAuth2TypeJWT               OAuth2Type = "jwt"
)

type Query

type Query struct {
	RefID            string         `json:"refId"`
	QueryType        QueryType      `json:"type"`
	URL              string         `json:"url,omitempty"`
	Method           QueryURLMethod `json:"method,omitempty"`
	Headers          []KV           `json:"headers,omitempty"`
	BodyType         BodyType       `json:"bodyType,omitempty"`
	Body             string         `json:"body,omitempty"`
	BodyContentType  string         `json:"bodyContentType,omitempty"`
	BodyForm         []KV           `json:"bodyForm,omitempty"`
	BodyGraphQLQuery string         `json:"bodyGraphQLQuery,omitempty"`
	RootSelector     string         `json:"rootSelector,omitempty"`
}

func LoadQuery

func LoadQuery(backendQuery backend.DataQuery, pluginContext backend.PluginContext) (*Query, error)

type QueryType

type QueryType string
const (
	QueryTypeOpenAPI QueryType = "openApi3"
	QueryTypeAuto    QueryType = "auto"
	QueryTypeJSON    QueryType = "json"
	QueryTypeCSV     QueryType = "csv"
	QueryTypeTSV     QueryType = "tsv"
	QueryTypeXML     QueryType = "xml"
	QueryTypeHTML    QueryType = "html"
)

type QueryURLMethod

type QueryURLMethod string
const (
	QueryURLMethodGet  QueryURLMethod = http.MethodGet
	QueryURLMethodPost QueryURLMethod = http.MethodPost
)

type ResponseMeta

type ResponseMeta struct {
	RawURL     string
	Status     string
	StatusCode int
	Headers    http.Header
}

type RestDS

type RestDS struct {
	Config     Config
	HTTPClient *http.Client
}

func (*RestDS) GetResponse

func (restds *RestDS) GetResponse(query Query) (responseBody string, meta ResponseMeta, err error)

type RestDriver

type RestDriver interface {
	LoadConfig(settings backend.DataSourceInstanceSettings) (*Config, error)
	LoadSpec() openapi3.Spec
}

type RestDriverOptions

type RestDriverOptions struct {
	PluginName                  string
	PluginID                    string
	HealthCheckURL              string
	CustomHealthCheckValidation func(responseString string, meta ResponseMeta) *backend.CheckHealthResult
}

Jump to

Keyboard shortcuts

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