api

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NotAllowed

func NotAllowed(c *gin.Context)

NotAllowed returns a JSON 405 response for the API.

func NotFound

func NotFound(c *gin.Context)

NotFound returns a JSON 404 response for the API. NOTE: we know it's weird to put server-side handlers like NotFound and NotAllowed here in the client/api side package but it unifies where we keep our error handling mechanisms.

Types

type APIAuthentication

type APIAuthentication struct {
	ClientID     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
}

type APIKey

type APIKey struct {
	ID           int      `json:"id,omitempty"`
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret,omitempty"`
	Name         string   `json:"name"`
	ProjectID    string   `json:"project_id"`
	Owner        string   `json:"owner,omitempty"`
	Permissions  []string `json:"permissions,omitempty"`
	Created      string   `json:"created,omitempty"`
	Modified     string   `json:"modified,omitempty"`
}

type APIKeyList

type APIKeyList struct {
	APIKeys       []*APIKey `json:"apikeys"`
	NextPageToken string    `json:"next_page_token,omitempty"`
}

type APIv1

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

APIv1 implements the QuarterdeckClient interface

func (*APIv1) APIKeyCreate

func (s *APIv1) APIKeyCreate(ctx context.Context, in *APIKey) (out *APIKey, err error)

func (*APIv1) APIKeyDelete

func (s *APIv1) APIKeyDelete(ctx context.Context, id string) (err error)

func (*APIv1) APIKeyDetail

func (s *APIv1) APIKeyDetail(ctx context.Context, id string) (out *APIKey, err error)

func (*APIv1) APIKeyList

func (s *APIv1) APIKeyList(ctx context.Context, in *PageQuery) (out *APIKeyList, err error)

func (*APIv1) APIKeyUpdate

func (s *APIv1) APIKeyUpdate(ctx context.Context, in *APIKey) (out *APIKey, err error)

func (*APIv1) Authenticate

func (s *APIv1) Authenticate(ctx context.Context, in *APIAuthentication) (out *LoginReply, err error)

func (*APIv1) Do

func (s *APIv1) Do(req *http.Request, data interface{}, checkStatus bool) (rep *http.Response, err error)

Do executes an http request against the server, performs error checking, and deserializes the response data into the specified struct.

func (*APIv1) Login

func (s *APIv1) Login(ctx context.Context, in *LoginRequest) (out *LoginReply, err error)

func (*APIv1) NewRequest

func (s *APIv1) NewRequest(ctx context.Context, method, path string, data interface{}, params *url.Values) (req *http.Request, err error)

func (*APIv1) Refresh

func (s *APIv1) Refresh(ctx context.Context) (out *LoginReply, err error)

func (*APIv1) Register

func (s *APIv1) Register(ctx context.Context, in *RegisterRequest) (out *RegisterReply, err error)

func (*APIv1) Status

func (s *APIv1) Status(ctx context.Context) (out *StatusReply, err error)

type ClientOption

type ClientOption func(c *APIv1) error

ClientOption allows us to configure the APIv1 client when it is created.

func WithClient

func WithClient(client *http.Client) ClientOption

type LoginReply

type LoginReply struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type OpenIDConfiguration added in v0.1.1

type OpenIDConfiguration struct {
	Issuer                        string   `json:"issuer"`
	AuthorizationEP               string   `json:"authorization_endpoint"`
	TokenEP                       string   `json:"token_endpoint"`
	DeviceAuthorizationEP         string   `json:"device_authorization_endpoint"`
	UserInfoEP                    string   `json:"userinfo_endpoint"`
	MFAChallengeEP                string   `json:"mfa_challenge_endpoint"`
	JWKSURI                       string   `json:"jwks_uri"`
	RegistrationEP                string   `json:"registration_endpoint"`
	RevocationEP                  string   `json:"revocation_endpoint"`
	ScopesSupported               []string `json:"scopes_supported"`
	ResponseTypesSupported        []string `json:"response_types_supported"`
	CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported"`
	ResponseModesSupported        []string `json:"response_modes_supported"`
	SubjectTypesSupported         []string `json:"subject_types_supported"`
	IDTokenSigningAlgValues       []string `json:"id_token_signing_alg_values_supported"`
	TokenEndpointAuthMethods      []string `json:"token_endpoint_auth_methods_supported"`
	ClaimsSupported               []string `json:"claims_supported"`
	RequestURIParameterSupported  bool     `json:"request_uri_parameter_supported"`
}

type PageQuery

type PageQuery struct {
	PageSize      int    `json:"page_size" url:"page_size,omitempty" form:"page_size"`
	NextPageToken string `json:"next_page_token" url:"next_page_token,omitempty" form:"next_page_token"`
}

PageQuery manages paginated list requests.

type QuarterdeckClient

type QuarterdeckClient interface {
	// Unauthenticated endpoints
	Status(context.Context) (*StatusReply, error)
	Register(context.Context, *RegisterRequest) (*RegisterReply, error)
	Login(context.Context, *LoginRequest) (*LoginReply, error)
	Authenticate(context.Context, *APIAuthentication) (*LoginReply, error)

	// Authenticated endpoints
	Refresh(context.Context) (*LoginReply, error)

	// API Keys Resource
	APIKeyList(context.Context, *PageQuery) (*APIKeyList, error)
	APIKeyCreate(context.Context, *APIKey) (*APIKey, error)
	APIKeyDetail(context.Context, string) (*APIKey, error)
	APIKeyUpdate(context.Context, *APIKey) (*APIKey, error)
	APIKeyDelete(context.Context, string) error
}

func New

func New(endpoint string, opts ...ClientOption) (_ QuarterdeckClient, err error)

New creates a new API v1 client that implements the Quarterdeck Client interface.

type RegisterReply

type RegisterReply struct {
	ID      int    `json:"user_id"`
	Email   string `json:"email"`
	Message string `json:"message"`
	Role    string `json:"role"`
	Created string `json:"created"`
}

type RegisterRequest

type RegisterRequest struct {
	Name     string `json:"name"`
	Email    string `json:"email"`
	Password string `json:"password"`
	PwCheck  string `json:"pwcheck"`
}

type Reply

type Reply struct {
	Success bool   `json:"success"`
	Error   string `json:"error,omitempty"`
}

Reply contains standard fields that are used for generic API responses and errors.

func ErrorResponse

func ErrorResponse(err interface{}) Reply

Construct a new response for an error or simply return unsuccessful.

type StatusReply

type StatusReply struct {
	Status  string `json:"status"`
	Uptime  string `json:"uptime,omitempty"`
	Version string `json:"version,omitempty"`
}

Returned on status requests.

Jump to

Keyboard shortcuts

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