marketplace

package
v0.0.0-...-f47fe49 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetMarketplaceTokenCacher func(*int64) TokenCacher

GetMarketplaceTokenCacher stores a function that returns a TokenCacher

View Source
var GetMarketplaceTokenProvider func(string) TokenProvider

GetMarketplaceTokenProvider stores a function that retunrs a TokenProvider

Functions

func SetMarketplaceTokenAuthExtraField

func SetMarketplaceTokenAuthExtraField(tenantId int64, auth *model.Authentication) error

SetMarketplaceTokenAuthExtraField tries to put the marketplace token as a JSON string in the "auth.Extra" field only if the provided authentication is of the type "marketplace".

Types

type BearerToken

type BearerToken struct {
	Expiration *int64  `json:"expiration"`
	Token      *string `json:"access_token"`
}

BearerToken represents the bearer token sent by the marketplace, and includes the Unix timestamp of the time when it expires.

func DecodeMarketplaceTokenFromResponse

func DecodeMarketplaceTokenFromResponse(response *http.Response) (*BearerToken, error)

DecodeMarketplaceTokenFromResponse decodes the bearer token and the expiration timestamp from the received response.

func (BearerToken) MarshalBinary

func (bt BearerToken) MarshalBinary() (data []byte, err error)

MarshalBinary implements the "BinaryMarshaller" interface to easily marshal the struct when using the Redis client.

func (*BearerToken) String

func (bt *BearerToken) String() string

String pretty prints the struct. Required to avoid printing the actual pointer addresses.

type MarketplaceTokenCacher

type MarketplaceTokenCacher struct {
	TenantID int64
}

MarketplaceTokenCacher is an struct which implements the "TokenCacher" interface. This helps in abstracting away the dependencies and making testing easier.

func (*MarketplaceTokenCacher) CacheToken

func (mtc *MarketplaceTokenCacher) CacheToken(token *BearerToken) error

CacheToken sets the token on the Redis cache.

func (*MarketplaceTokenCacher) FetchToken

func (mtc *MarketplaceTokenCacher) FetchToken() (*BearerToken, error)

FetchToken fetches the token from the Redis cache. It returns the bearer token on a cache hit. It returns (nil, redis.Nil) when the token was not found.

type MarketplaceTokenProvider

type MarketplaceTokenProvider struct {
	ApiKey *string
}

MarketplaceTokenProvider is a type that satisfies the "TokenProvider" interface. The aim is to abstract away the injection of this dependency on other code, which will make testing easier.

func (*MarketplaceTokenProvider) RequestToken

func (mtp *MarketplaceTokenProvider) RequestToken() (*BearerToken, error)

RequestToken sends a request to the marketplace to request a bearer token.

type TokenCacher

type TokenCacher interface {
	// FetchToken fetches a marketplace token from the cache.
	FetchToken() (*BearerToken, error)
	// CacheToken sets a marketplace token on the cache.
	CacheToken(token *BearerToken) error
}

func GetMarketplaceTokenCacherWithTenantId

func GetMarketplaceTokenCacherWithTenantId(tenantId *int64) TokenCacher

GetMarketplaceTokenCacherWithTenantId is the default implementation which returns a default "TokenCacher" instance, which is used in the main application.

type TokenProvider

type TokenProvider interface {
	// RequestToken returns a bearer token using the given API Key.
	RequestToken() (*BearerToken, error)
}

func GetMarketplaceTokenProviderWithApiKey

func GetMarketplaceTokenProviderWithApiKey(apiKey string) TokenProvider

GetMarketplaceTokenProviderWithApiKey is the default implementation which returns a default "TokenProvider" instance, which is used in the main application.

Jump to

Keyboard shortcuts

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