Documentation ¶
Index ¶
- Constants
- func ExchangeAuthCodeForToken(ctx context.Context, code string, oauthClient OAuthClient) (*oauth2.Token, error)
- func HealthCheck(w http.ResponseWriter, r *http.Request) error
- func NewFakeLogger() (log.Logger, *bytes.Buffer)
- func OauthErrorRenderer(next chain.Handler) chain.Handler
- type AccessTokens
- type CreateImageRequest
- type CreateInstanceRequest
- type FakeErrorHandler
- type FakeExecutor
- func (e FakeExecutor) CreateBtrfsSubvolume(ctx context.Context, id int) error
- func (e FakeExecutor) CreateInstance(ctx context.Context, imageID int, instanceID int, port int) error
- func (e FakeExecutor) DestroyImage(ctx context.Context, id int) error
- func (e FakeExecutor) DestroyInstance(ctx context.Context, id int) error
- func (e FakeExecutor) FinaliseImage(ctx context.Context, image models.Image) error
- func (e FakeExecutor) RetrieveInstanceCredentials(ctx context.Context, id int) (map[string][]byte, error)
- type FakeImageStore
- func (s FakeImageStore) Create(image models.Image) (models.Image, error)
- func (s FakeImageStore) Destroy(image models.Image) error
- func (s FakeImageStore) Get(id int) (models.Image, error)
- func (s FakeImageStore) List() ([]models.Image, error)
- func (s FakeImageStore) MarkAsReady(image models.Image) (models.Image, error)
- type FakeInstanceStore
- type FakeWhitelistedAddressStore
- type Images
- func (i Images) Create(w http.ResponseWriter, r *http.Request) error
- func (i Images) Destroy(w http.ResponseWriter, r *http.Request) error
- func (i Images) Done(w http.ResponseWriter, r *http.Request) error
- func (i Images) Get(w http.ResponseWriter, r *http.Request) error
- func (i Images) List(w http.ResponseWriter, r *http.Request) error
- type Instances
- type OAuthCallback
- type OAuthClient
Constants ¶
const OAUTH_CALLBACK_TIMEOUT = time.Minute
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
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 ¶
func (a AccessTokens) Create(w http.ResponseWriter, r *http.Request) error
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 CreateInstanceRequest ¶
type CreateInstanceRequest struct {
ImageID string `jsonapi:"attr,image_id"`
}
type FakeErrorHandler ¶
type FakeErrorHandler struct {
Error error
}
func (*FakeErrorHandler) Handle ¶
func (f *FakeErrorHandler) Handle(h chain.Handler) http.HandlerFunc
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 (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 (FakeExecutor) RetrieveInstanceCredentials ¶
type FakeImageStore ¶
type FakeImageStore struct {
// contains filtered or unexported fields
}
func (FakeImageStore) MarkAsReady ¶
type FakeInstanceStore ¶
type FakeInstanceStore struct {
// contains filtered or unexported fields
}
type FakeWhitelistedAddressStore ¶
type FakeWhitelistedAddressStore struct {
// contains filtered or unexported fields
}
func (FakeWhitelistedAddressStore) Create ¶
func (s FakeWhitelistedAddressStore) Create(image models.WhitelistedAddress) (models.WhitelistedAddress, error)
func (FakeWhitelistedAddressStore) List ¶
func (s FakeWhitelistedAddressStore) List() ([]models.WhitelistedAddress, error)
type Images ¶
type Images struct { ImageStore store.ImageStore InstanceStore store.InstanceStore Executor exec.Executor }
type Instances ¶
type Instances struct { InstanceStore store.InstanceStore ImageStore store.ImageStore WhitelistedAddressStore store.WhitelistedAddressStore ApplyWhitelist func(string) Executor exec.Executor MinInstancePort uint16 MaxInstancePort uint16 }