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
- Variables
- func HashByte(data []byte) string
- func HashDatasourceInfo(dsInfo *backend.DataSourceInstanceSettings) string
- func HashString(text string) string
- type ActivityDTO
- type AuthCache
- type DSAuthCache
- type DSCache
- func (c *DSCache) Delete(request string)
- func (c *DSCache) Flush()
- func (c *DSCache) Get(request string) (interface{}, bool)
- func (c *DSCache) Load(request string) (string, error)
- func (c *DSCache) Save(request string, response interface{}) error
- func (c *DSCache) Set(request string, response interface{})
- func (c *DSCache) SetDefault(request string, response interface{})
- func (c *DSCache) SetWithExpiration(request string, response interface{}, d time.Duration)
- func (c *DSCache) SetWithNoExpiration(request string, response interface{}, d time.Duration)
- type PrefetchStreamTask
- type QueryModel
- type StravaAPIRequest
- type StravaApiResourceResponse
- type StravaAuthRequest
- type StravaAuthResourceResponse
- type StravaDatasource
- func (ds *StravaDatasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
- func (ds *StravaDatasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
- func (ds *StravaDatasource) ResetAccessTokenHandler(rw http.ResponseWriter, req *http.Request)
- func (ds *StravaDatasource) ResetCacheHandler(rw http.ResponseWriter, req *http.Request)
- func (ds *StravaDatasource) RootHandler(rw http.ResponseWriter, req *http.Request)
- func (ds *StravaDatasource) StravaAPIHandler(rw http.ResponseWriter, req *http.Request)
- func (ds *StravaDatasource) StravaAuthHandler(rw http.ResponseWriter, req *http.Request)
- type StravaDatasourceInstance
- func (ds *StravaDatasourceInstance) ExchangeToken(authCode string) (*TokenExchangeResponse, error)
- func (ds *StravaDatasourceInstance) GetAccessToken() (string, error)
- func (ds *StravaDatasourceInstance) GetRefreshToken() (string, error)
- func (ds *StravaDatasourceInstance) RefreshAccessToken(refreshToken string) (*TokenExchangeResponse, error)
- func (ds *StravaDatasourceInstance) ResetAccessToken() error
- func (ds *StravaDatasourceInstance) ResetCache()
- func (ds *StravaDatasourceInstance) StravaAPIQuery(ctx context.Context, query *StravaAPIRequest) (*StravaApiResourceResponse, error)
- func (ds *StravaDatasourceInstance) StravaAPIQueryWithCache(requestHash string) func(context.Context, *StravaAPIRequest) (*StravaApiResourceResponse, error)
- func (ds *StravaDatasourceInstance) StravaAuthQuery(ctx context.Context, req *StravaAuthRequest) (*StravaAuthResourceResponse, error)
- type StravaDatasourceSettingsDTO
- type StravaPrefetcher
- func (p *StravaPrefetcher) GetActivities() ([]string, error)
- func (p *StravaPrefetcher) PrefetchActivities(activities []string)
- func (p *StravaPrefetcher) PrefetchActivitiesVariable(limit int)
- func (p *StravaPrefetcher) PrefetchActivity(activityId string)
- func (p *StravaPrefetcher) PrefetchActivityStreams(activityId string)
- func (p *StravaPrefetcher) Run()
- type TokenExchangeResponse
Constants ¶
const MaxTasks = 4
const StravaAPITokenUrl = "https://www.strava.com/api/v3/oauth/token"
const StravaAPIUrl = "https://www.strava.com/api/v3"
const StravaApiQueryType = "stravaAPI"
const StravaAuthQueryType = "stravaAuth"
Variables ¶
var ErrAlertingNotSupported = errors.New("alerting not supported")
Functions ¶
func HashDatasourceInfo ¶
func HashDatasourceInfo(dsInfo *backend.DataSourceInstanceSettings) string
HashDatasourceInfo converts the given datasource info to hash string
func HashString ¶
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) Set ¶
Add an item to the cache with default expiration time, replacing any existing item.
func (*DSCache) SetDefault ¶
Set the value of the key "request" to "response" with default expiration time.
func (*DSCache) SetWithExpiration ¶ added in v1.5.0
Save item to the cache with provided expiration time
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
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 ¶
func (ds *StravaDatasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error)
CheckHealth checks if the plugin is running properly
func (*StravaDatasource) QueryData ¶
func (ds *StravaDatasource) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error)
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 (ds *StravaDatasourceInstance) StravaAPIQuery(ctx context.Context, query *StravaAPIRequest) (*StravaApiResourceResponse, error)
func (*StravaDatasourceInstance) StravaAPIQueryWithCache ¶ added in v1.5.0
func (ds *StravaDatasourceInstance) StravaAPIQueryWithCache(requestHash string) func(context.Context, *StravaAPIRequest) (*StravaApiResourceResponse, error)
func (*StravaDatasourceInstance) StravaAuthQuery ¶
func (ds *StravaDatasourceInstance) StravaAuthQuery(ctx context.Context, req *StravaAuthRequest) (*StravaAuthResourceResponse, error)
type StravaDatasourceSettingsDTO ¶ added in v1.5.0
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