routes

package
v5.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const OAUTH_CALLBACK_TIMEOUT = time.Minute
View Source
const TOKEN_EXCHANGE_TIMEOUT = time.Second * 5

Variables

This section is empty.

Functions

func ExchangeAuthCodeForToken

func ExchangeAuthCodeForToken(ctx context.Context, code string, oauthClient OAuthClient) (*oauth2.Token, error)

TODO: push token revocation into the oauthClient - right now this code is Google-specific.

func HealthCheck

func HealthCheck(w http.ResponseWriter, r *http.Request) error

func NewFakeLogger

func NewFakeLogger() (log.Logger, *bytes.Buffer)

func OauthErrorRenderer

func OauthErrorRenderer(next chain.Handler) chain.Handler

Types

type AccessTokens

type AccessTokens struct {
	Callbacks map[string]chan OAuthCallback
	Client    OAuthClient
}

func (AccessTokens) Authenticate

func (a AccessTokens) Authenticate(w http.ResponseWriter, r *http.Request) error

func (AccessTokens) Callback

func (a AccessTokens) Callback(w http.ResponseWriter, r *http.Request) error

func (AccessTokens) Create

Create completes the OAuth flow and returns an access token

The flow for this is a bit tricky, so it's worth going through. When we receive a request to create an access token, we create a channel and store it in the Callbacks map, keyed by the state parameter provided in the request. We then block on the channel, waiting to receive an OAuthCallback through it. The client will send the user through the OAuth flow, providing the same state parameter. When the user finishes the flow, they'll be redirected to the Callback handler, which is also in this route set. The Callback handler will handle the redirect, exchanging the authorisation code for an access token if it was successful, and will send the outcome through the same channel (looking it up by the state). Create will then receive the result through the channel, remove the channel from the map, and serialise a result back to the client.

type CreateImageRequest

type CreateImageRequest struct {
	BackedUpAt time.Time `jsonapi:"attr,backed_up_at,iso8601"`
	Anon       string    `jsonapi:"attr,anonymisation_script"`
}

type CreateInstanceRequest

type CreateInstanceRequest struct {
	ImageID string `jsonapi:"attr,image_id"`
}

type FakeErrorHandler

type FakeErrorHandler struct {
	Error error
}

func (*FakeErrorHandler) Handle

type FakeExecutor

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

func (FakeExecutor) CreateBtrfsSubvolume

func (e FakeExecutor) CreateBtrfsSubvolume(ctx context.Context, id int) error

func (FakeExecutor) CreateInstance

func (e FakeExecutor) CreateInstance(ctx context.Context, imageID int, instanceID int, port int) error

func (FakeExecutor) DestroyImage

func (e FakeExecutor) DestroyImage(ctx context.Context, id int) error

func (FakeExecutor) DestroyInstance

func (e FakeExecutor) DestroyInstance(ctx context.Context, id int) error

func (FakeExecutor) FinaliseImage

func (e FakeExecutor) FinaliseImage(ctx context.Context, image models.Image) error

func (FakeExecutor) RetrieveInstanceCredentials

func (e FakeExecutor) RetrieveInstanceCredentials(ctx context.Context, id int) (map[string][]byte, error)

type FakeImageStore

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

func (FakeImageStore) Create

func (s FakeImageStore) Create(image models.Image) (models.Image, error)

func (FakeImageStore) Destroy

func (s FakeImageStore) Destroy(image models.Image) error

func (FakeImageStore) Get

func (s FakeImageStore) Get(id int) (models.Image, error)

func (FakeImageStore) List

func (s FakeImageStore) List() ([]models.Image, error)

func (FakeImageStore) MarkAsReady

func (s FakeImageStore) MarkAsReady(image models.Image) (models.Image, error)

type FakeInstanceStore

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

func (FakeInstanceStore) Create

func (FakeInstanceStore) Destroy

func (s FakeInstanceStore) Destroy(instance models.Instance) error

func (FakeInstanceStore) Get

func (s FakeInstanceStore) Get(id int) (models.Instance, error)

func (FakeInstanceStore) List

func (s FakeInstanceStore) List() ([]models.Instance, error)

type FakeWhitelistedAddressStore

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

func (FakeWhitelistedAddressStore) Create

func (FakeWhitelistedAddressStore) List

type Images

type Images struct {
	ImageStore    store.ImageStore
	InstanceStore store.InstanceStore
	Executor      exec.Executor
}

func (Images) Create

func (i Images) Create(w http.ResponseWriter, r *http.Request) error

func (Images) Destroy

func (i Images) Destroy(w http.ResponseWriter, r *http.Request) error

func (Images) Done

func (i Images) Done(w http.ResponseWriter, r *http.Request) error

func (Images) Get

func (i Images) Get(w http.ResponseWriter, r *http.Request) error

func (Images) List

func (i Images) List(w http.ResponseWriter, r *http.Request) error

type Instances

type Instances struct {
	InstanceStore           store.InstanceStore
	ImageStore              store.ImageStore
	WhitelistedAddressStore store.WhitelistedAddressStore
	ApplyWhitelist          func(string)
	Executor                exec.Executor
	MinInstancePort         uint16
	MaxInstancePort         uint16
}

func (Instances) Create

func (i Instances) Create(w http.ResponseWriter, r *http.Request) error

func (Instances) Destroy

func (i Instances) Destroy(w http.ResponseWriter, r *http.Request) error

func (Instances) Get

func (Instances) List

type OAuthCallback

type OAuthCallback struct {
	Token oauth2.Token
	Error error
}

type OAuthClient

type OAuthClient interface {
	AuthCodeURL(string, ...oauth2.AuthCodeOption) string
	Exchange(context.Context, string) (*oauth2.Token, error)
}

OAuthClient is the abstract interface for handling OAuth. Both the real OAuth client and our fake for testing will implement this interface

Jump to

Keyboard shortcuts

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