datasource

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

This module contains a very simple cache for auth info (like refresh token) which is persisted for plugin process lifetime. This is required because when plugin settings are updated, new plugin instance is created and previously cached data is not available anymore.

Index

Constants

View Source
const MaxTasks = 4
View Source
const StravaAPITokenUrl = "https://www.strava.com/api/v3/oauth/token"
View Source
const StravaAPIUrl = "https://www.strava.com/api/v3"
View Source
const StravaApiQueryType = "stravaAPI"
View Source
const StravaAuthQueryType = "stravaAuth"

Variables

View Source
var ErrAlertingNotSupported = errors.New("alerting not supported")

Functions

func HashByte added in v1.5.0

func HashByte(data []byte) string

HashByte converts the given bytes to hash string

func HashDatasourceInfo

func HashDatasourceInfo(dsInfo *backend.DataSourceInstanceSettings) string

HashDatasourceInfo converts the given datasource info to hash string

func HashString

func HashString(text string) string

HashString converts the given text string to hash string

Types

type ActivityDTO added in v1.5.0

type ActivityDTO = struct {
	Id int64 `json:"id"`
}

type AuthCache added in v1.5.1

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

func GetAuthCache added in v1.5.1

func GetAuthCache() *AuthCache

type DSAuthCache added in v1.5.1

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

func GetDSAuthCache added in v1.5.1

func GetDSAuthCache(dsId int64) *DSAuthCache

func (*DSAuthCache) GetRefreshToken added in v1.5.1

func (d *DSAuthCache) GetRefreshToken() string

func (*DSAuthCache) SetRefreshToken added in v1.5.1

func (d *DSAuthCache) SetRefreshToken(t string)

type DSCache

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

DSCache is a abstraction over go-cache.

func NewDSCache

func NewDSCache(dsInfo *backend.DataSourceInstanceSettings, ttl time.Duration, cleanupInterval time.Duration, dataDir string) *DSCache

NewDSCache creates a go-cache with expiration(ttl) time and cleanupInterval.

func (*DSCache) Delete added in v1.4.0

func (c *DSCache) Delete(request string)

Remove item from cache

func (*DSCache) Flush added in v1.5.0

func (c *DSCache) Flush()

Delete all items from the cache.

func (*DSCache) Get

func (c *DSCache) Get(request string) (interface{}, bool)

Get the value associated with request from the cache

func (*DSCache) Load

func (c *DSCache) Load(request string) (string, error)

Load value from disk

func (*DSCache) Save

func (c *DSCache) Save(request string, response interface{}) error

Save value to disk

func (*DSCache) Set

func (c *DSCache) Set(request string, response interface{})

Add an item to the cache with default expiration time, replacing any existing item.

func (*DSCache) SetDefault

func (c *DSCache) SetDefault(request string, response interface{})

Set the value of the key "request" to "response" with default expiration time.

func (*DSCache) SetWithExpiration added in v1.5.0

func (c *DSCache) SetWithExpiration(request string, response interface{}, d time.Duration)

Save item to the cache with provided expiration time

func (*DSCache) SetWithNoExpiration added in v1.5.0

func (c *DSCache) SetWithNoExpiration(request string, response interface{}, d time.Duration)

Save item to the cache with no expiration

type PrefetchStreamTask added in v1.5.0

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

type QueryModel

type QueryModel struct {
	QueryType    string `json:"queryType"`
	ActivityStat string `json:"activityStat"`
	ActivityType string `json:"activityType"`
	Format       string `json:"format"`
	Interval     string `json:"interval"`

	// Direct from the gRPC interfaces
	TimeRange backend.TimeRange `json:"-"`
}

QueryModel model

func ReadQuery

func ReadQuery(query backend.DataQuery) (QueryModel, error)

ReadQuery will read and validate Settings from the DataSourceConfig

type StravaAPIRequest

type StravaAPIRequest struct {
	Endpoint    string                     `json:"endpoint"`
	Params      map[string]json.RawMessage `json:"params,omitempty"`
	AccessToken string
}

type StravaApiResourceResponse

type StravaApiResourceResponse struct {
	Result interface{} `json:"result,omitempty"`
}

func BuildAPIResponse

func BuildAPIResponse(apiResponse []byte) (*StravaApiResourceResponse, error)

type StravaAuthRequest

type StravaAuthRequest struct {
	AuthCode string `json:"authCode"`
}

type StravaAuthResourceResponse

type StravaAuthResourceResponse struct {
	Result interface{} `json:"result,omitempty"`
}

type StravaDatasource

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

func NewStravaDatasource

func NewStravaDatasource(dataDir string) *StravaDatasource

func (*StravaDatasource) CheckHealth

CheckHealth checks if the plugin is running properly

func (*StravaDatasource) QueryData

func (*StravaDatasource) ResetAccessTokenHandler added in v1.4.0

func (ds *StravaDatasource) ResetAccessTokenHandler(rw http.ResponseWriter, req *http.Request)

func (*StravaDatasource) ResetCacheHandler added in v1.5.1

func (ds *StravaDatasource) ResetCacheHandler(rw http.ResponseWriter, req *http.Request)

func (*StravaDatasource) RootHandler

func (ds *StravaDatasource) RootHandler(rw http.ResponseWriter, req *http.Request)

func (*StravaDatasource) StravaAPIHandler

func (ds *StravaDatasource) StravaAPIHandler(rw http.ResponseWriter, req *http.Request)

func (*StravaDatasource) StravaAuthHandler

func (ds *StravaDatasource) StravaAuthHandler(rw http.ResponseWriter, req *http.Request)

type StravaDatasourceInstance

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

StravaDatasourceInstance stores state about a specific datasource and provides methods to make requests to the Strava API

func (*StravaDatasourceInstance) ExchangeToken

func (ds *StravaDatasourceInstance) ExchangeToken(authCode string) (*TokenExchangeResponse, error)

ExchangeToken invokes first time when authentication required and exchange authorization code for the access and refresh tokens https://developers.strava.com/docs/authentication/#tokenexchange

func (*StravaDatasourceInstance) GetAccessToken

func (ds *StravaDatasourceInstance) GetAccessToken() (string, error)

func (*StravaDatasourceInstance) GetRefreshToken added in v1.5.1

func (ds *StravaDatasourceInstance) GetRefreshToken() (string, error)

func (*StravaDatasourceInstance) RefreshAccessToken

func (ds *StravaDatasourceInstance) RefreshAccessToken(refreshToken string) (*TokenExchangeResponse, error)

RefreshAccessToken refreshes expired Access token using refresh token https://developers.strava.com/docs/authentication/#refreshingexpiredaccesstokens

func (*StravaDatasourceInstance) ResetAccessToken added in v1.4.0

func (ds *StravaDatasourceInstance) ResetAccessToken() error

func (*StravaDatasourceInstance) ResetCache added in v1.5.0

func (ds *StravaDatasourceInstance) ResetCache()

func (*StravaDatasourceInstance) StravaAPIQuery

func (*StravaDatasourceInstance) StravaAPIQueryWithCache added in v1.5.0

func (ds *StravaDatasourceInstance) StravaAPIQueryWithCache(requestHash string) func(context.Context, *StravaAPIRequest) (*StravaApiResourceResponse, error)

func (*StravaDatasourceInstance) StravaAuthQuery

type StravaDatasourceSettingsDTO added in v1.5.0

type StravaDatasourceSettingsDTO struct {
	StravaAuthType string `json:"stravaAuthType"`
	ClientID       string `json:"clientID"`
	CacheTTL       string `json:"cacheTTL"`
}

type StravaPrefetcher added in v1.5.0

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

func NewStravaPrefetcher added in v1.5.0

func NewStravaPrefetcher(depth int, ds *StravaDatasourceInstance) *StravaPrefetcher

func (*StravaPrefetcher) GetActivities added in v1.5.0

func (p *StravaPrefetcher) GetActivities() ([]string, error)

func (*StravaPrefetcher) PrefetchActivities added in v1.5.0

func (p *StravaPrefetcher) PrefetchActivities(activities []string)

func (*StravaPrefetcher) PrefetchActivitiesVariable added in v1.5.0

func (p *StravaPrefetcher) PrefetchActivitiesVariable(limit int)

func (*StravaPrefetcher) PrefetchActivity added in v1.5.0

func (p *StravaPrefetcher) PrefetchActivity(activityId string)

func (*StravaPrefetcher) PrefetchActivityStreams added in v1.5.0

func (p *StravaPrefetcher) PrefetchActivityStreams(activityId string)

func (*StravaPrefetcher) Run added in v1.5.0

func (p *StravaPrefetcher) Run()

Run starts background prefetcher task

type TokenExchangeResponse

type TokenExchangeResponse struct {
	AccessToken      string `json:"access_token"`
	AccessTokenExpAt int64  `json:"expires_at"`
	RefreshToken     string `json:"refresh_token"`
}

Jump to

Keyboard shortcuts

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