connector

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: BSD-3-Clause Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCallbackAlreadyResolved = errors.New("Callback Already Resolved")

ErrCallbackAlreadyResolved represents an error which occurs if the callback has already been resolved

View Source
var ErrCallbackNotFound = errors.New("Callback Not Found")

ErrCallbackNotFound represents an error which occurs if a callback does not exist

View Source
var ErrResourceNotFound = errors.New("Resource Not Found")

ErrResourceNotFound represents an error which occurrs if the resource does not exist

Functions

func ErrorHandler

func ErrorHandler(c *FakeConnector) *bone.Mux

ErrorHandler is a set of endpoints that just returns errors. This is to test how the providers handle errors from our end.

func ValidHandler

func ValidHandler(c *FakeConnector) *bone.Mux

ValidHandler returns a set of endpoints that are valid and in use by the production connector.

Types

type AccessToken

type AccessToken struct {
	ID          manifold.ID `json:"-"`
	AccessToken string      `json:"access_token"`
	ExpiresIn   int         `json:"expires_in"`
	TokenType   string      `json:"token_type"`
	GrantType   GrantType   `json:"-"`
}

AccessToken represents an access token granted by the fake connector for kicking off the oauth flow

type AuthorizationCode

type AuthorizationCode struct {
	Code      string
	ExpiresAt time.Time
}

AuthorizationCode represents a code granted by the fake connector for kicking off the oauth flow

type Callback

type Callback struct {
	ID          manifold.ID       `json:"id"`
	Mutex       *sync.Mutex       `json:"-"`
	Type        CallbackType      `json:"type"`
	State       CallbackState     `json:"state"`
	Message     string            `json:"message"`
	Credentials map[string]string `json:"-"`
}

Callback represents a callback that is either pending or has been received from a provider

type CallbackRequest

type CallbackRequest struct {
	State       CallbackState     `json:"state"`
	Message     string            `json:"message"`
	Credentials map[string]string `json:"credentials"`
}

CallbackRequest represents a received callback from a provider

type CallbackState

type CallbackState string

CallbackState represents a state reported by the provider regarding an operation

var (
	PendingCallbackState CallbackState = "pending"
	DoneCallbackState    CallbackState = "done"
	ErrorCallbackState   CallbackState = "error"
)

PendingCallbackState represents a callback which is pending (not resolved)

type CallbackType

type CallbackType string

CallbackType represents a type of callback

var (
	ResourceProvisionCallback     CallbackType = "resource:provision"
	CredentialProvisionCallback   CallbackType = "credential:provision"
	ResourceDeprovisionCallback   CallbackType = "resource:deprovision"
	CredentialDeprovisionCallback CallbackType = "credential:deprovision"
	ResourceResizeCallback        CallbackType = "resource:resize"
)

ResourceProvisionCallback represents a callback related to a resource provision

type CreateAccessTokenJSON added in v0.14.7

type CreateAccessTokenJSON struct {
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Code         string `json:"code"`
}

CreateAccessTokenJSON creates an access token as json

type FakeConnector

type FakeConnector struct {
	Config     *FakeConnectorConfig
	DB         *db.DB
	OnCallback chan *Callback

	Server *http.Server
	// contains filtered or unexported fields
}

FakeConnector represents a fake connector api server run by Grafton for use by providers to integrate with Manifold.

func New

func New(port uint, clientID string, clientSecret string, product string) (*FakeConnector, error)

New creates and configures a FakeConnector

func (*FakeConnector) AddCallback

func (c *FakeConnector) AddCallback(t CallbackType) (*Callback, error)

AddCallback stores the callback inside the FakeConnector

func (*FakeConnector) AddResource

func (c *FakeConnector) AddResource(r *db.Resource)

AddResource stores a resource inside the connector

func (*FakeConnector) CreateCode

func (c *FakeConnector) CreateCode() (*AuthorizationCode, error)

CreateCode returns an AuthorizationCode method

func (*FakeConnector) GetCallback

func (c *FakeConnector) GetCallback(ID manifold.ID) *Callback

GetCallback returns a callback for the given id if it exists

func (*FakeConnector) GetCapturer

func (c *FakeConnector) GetCapturer(route string) (*RequestCapturer, error)

GetCapturer returns a RequestCapturer for the given route, if no capturer exists, an error is returned.

func (*FakeConnector) GetResource

func (c *FakeConnector) GetResource(id manifold.ID) *db.Resource

GetResource returns a Resource for the ID or nil

func (*FakeConnector) RemoveResource added in v0.6.4

func (c *FakeConnector) RemoveResource(ID manifold.ID) error

RemoveResource deletes a resource stored inside the connector

func (*FakeConnector) Start

func (c *FakeConnector) Start()

Start the server or return an error if it couldn't be started

func (*FakeConnector) StartSync added in v0.14.0

func (c *FakeConnector) StartSync() error

StartSync starts the server or returns an error if it couldn't be started

func (*FakeConnector) Stop

func (c *FakeConnector) Stop() error

Stop the server or return an error if it couldn't be stopped

func (*FakeConnector) TriggerCallback

func (c *FakeConnector) TriggerCallback(ID manifold.ID, state CallbackState, msg string, creds map[string]string) error

TriggerCallback updates the callback if it's still pending, and notifies any listeners

type FakeConnectorConfig

type FakeConnectorConfig struct {
	Product      string
	Port         uint
	ClientID     string
	ClientSecret string
	SigningKey   string
}

FakeConnectorConfig represents the values used to Configure a FakeConnector

type GrantType

type GrantType string

GrantType represents a type of access token grant

var (
	AuthorizationCodeGrantType GrantType = "authorization_code"
	ClientCredentialsGrantType GrantType = "client_credentials"
)

AuthorizationCodeGrantType represents an OAuth Authorization Code

type ProductProfile

type ProductProfile struct {
	Type   string         `json:"type"`
	Target *ProductTarget `json:"target"`
}

ProductProfile represents the data returned on GET /v1/self when the target type is a product

type ProductTarget

type ProductTarget struct {
	Name  string `json:"name"`
	Label string `json:"label"`
}

ProductTarget represents the data returned on GET /v1/vself when the target type is product

type RequestCapturer

type RequestCapturer struct {
	Route string
	// contains filtered or unexported fields
}

RequestCapturer represents functionality for capturing and storing requests for a specific route

func (*RequestCapturer) Get

func (r *RequestCapturer) Get() []interface{}

Get returns the requests captured by this Capturer

type ResourceMeasure added in v0.14.0

type ResourceMeasure struct {
	Feature      ResourceMeasureFeature      `json:"feature"`
	FeatureValue ResourceMeasureFeatureValue `json:"feature_value"`
	Usage        int64                       `json:"usage"`
	Max          *int64                      `json:"max"`
	Suffix       *string                     `json:"suffix"`
}

ResourceMeasure holds a specific measure and information relating to its feature

type ResourceMeasureFeature added in v0.14.0

type ResourceMeasureFeature struct {
	Name  manifold.Name  `json:"name"`
	Label manifold.Label `json:"label"`
}

ResourceMeasureFeature holds information about a measure's feature

type ResourceMeasureFeatureValue added in v0.14.0

type ResourceMeasureFeatureValue struct {
	Name  manifold.Name              `json:"name"`
	Label manifold.FeatureValueLabel `json:"label"`
}

ResourceMeasureFeatureValue holds information about a measure's feature value

type ResourceMeasures added in v0.14.0

type ResourceMeasures struct {
	UpdatedAt   time.Time         `json:"updated_at"`
	PeriodStart time.Time         `json:"period_start"`
	PeriodEnd   time.Time         `json:"period_end"`
	Measures    []ResourceMeasure `json:"measures"`
}

ResourceMeasures is a struct that provides resource measures information

in addition to hoisted information about the measured features

type TokenRequest

type TokenRequest struct {
	ContentType  string
	Code         string
	AuthHeader   bool
	ClientID     string
	ClientSecret string
	GrantType    GrantType
	ExpiresAt    time.Time
}

TokenRequest represents all of the important values from a request by a provider to create an OAuth Token

type UserProfile

type UserProfile struct {
	Type   string      `json:"type"`
	Target *UserTarget `json:"target"`
}

UserProfile represents the data returned on GET /v1/self when the target type is a user

type UserTarget

type UserTarget struct {
	ID    manifold.ID    `json:"id"`
	Name  string         `json:"name"`
	Email string         `json:"email"`
	Role  UserTargetRole `json:"role"`
}

UserTarget represents the contents of a response on GET /v1/self when the target is a user

type UserTargetRole added in v0.14.0

type UserTargetRole string

UserTargetRole defines an enum type of valid roles

const (
	// UserTargetRoleOwner defines the "owner" role
	UserTargetRoleOwner UserTargetRole = "owner"
	// UserTargetRoleMember defines the "member" role
	UserTargetRoleMember UserTargetRole = "member"
	// UserTargetRoleAdmin defines the "admin" role
	UserTargetRoleAdmin UserTargetRole = "admin"
)

Jump to

Keyboard shortcuts

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