testvault

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: MIT Imports: 27 Imported by: 1

README

testvault

This folder contains an API which provides 'vaults'. These vaults represent resources we can grant access to, similar to Okta groups or AWS SSO Permission Sets. This API is used with the testvault provider for Granted and is used for end-to-end tests of Granted.

For more information refer to the API documentation in openapi.yml.

Development

Create a DynamoDB table for testing as follows:

go run cmd/devcli/main.go db create -n testvault -e TESTVAULT_TABLE_NAME

Note: the above command will fail if the table has already been created. That is fine, you can use the same table.

Add the following entry to your .env file in the root of this repo:

TESTVAULT_TABLE_NAME=testvault

Documentation

Overview

Package testvault provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version v1.10.1 DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSwagger

func GetSwagger() (swagger *openapi3.T, err error)

GetSwagger returns the Swagger specification corresponding to the generated code in this file. The external references of Swagger specification are resolved. The logic of resolving external references is tightly connected to "import-mapping" feature. Externally referenced files must be embedded in the corresponding golang packages. Urls can be supported but this task was out of the scope.

func Handler

func Handler(si ServerInterface) http.Handler

Handler creates http.Handler with routing matching OpenAPI spec.

func HandlerFromMux

func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler

HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.

func HandlerFromMuxWithBaseURL

func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler

func HandlerWithOptions

func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler

HandlerWithOptions creates http.Handler with additional options

func NewAddMemberToVaultRequest

func NewAddMemberToVaultRequest(server string, vaultId string, body AddMemberToVaultJSONRequestBody) (*http.Request, error)

NewAddMemberToVaultRequest calls the generic AddMemberToVault builder with application/json body

func NewAddMemberToVaultRequestWithBody

func NewAddMemberToVaultRequestWithBody(server string, vaultId string, contentType string, body io.Reader) (*http.Request, error)

NewAddMemberToVaultRequestWithBody generates requests for AddMemberToVault with any type of body

func NewCheckVaultMembershipRequest

func NewCheckVaultMembershipRequest(server string, vaultId string, memberId string) (*http.Request, error)

NewCheckVaultMembershipRequest generates requests for CheckVaultMembership

func NewRemoveMemberFromVaultRequest

func NewRemoveMemberFromVaultRequest(server string, vaultId string, memberId string) (*http.Request, error)

NewRemoveMemberFromVaultRequest generates requests for RemoveMemberFromVault

func PathToRawSpec

func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error)

Constructs a synthetic filesystem for resolving external references when loading openapi specifications.

Types

type API

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

API holds the HTTP routes for the testvault service.

func NewAPI

func NewAPI(opts APIOpts) (*API, error)

NewAPI creates a new API.

func (*API) AddMemberToVault

func (a *API) AddMemberToVault(w http.ResponseWriter, r *http.Request, vaultId string)

Add member to vault (POST /vaults/{vaultId}/members)

func (*API) CheckVaultMembership

func (a *API) CheckVaultMembership(w http.ResponseWriter, r *http.Request, vaultId string, memberId string)

Check vault membership (GET /vaults/{vaultId}/members/{memberId})

func (*API) RemoveMemberFromVault

func (a *API) RemoveMemberFromVault(w http.ResponseWriter, r *http.Request, vaultId string, memberId string)

Remove a member from a vault (POST /vaults/{vaultId}/members/{memberId}/remove)

func (*API) Server

func (a *API) Server() http.Handler

type APIOpts

type APIOpts struct {
	DB  ddb.Storage
	Log *zap.SugaredLogger
}

type AddMember

type AddMember struct {
	// The user ID or email to add to the vault. This can be any string.
	User string `json:"user"`
}

AddMember defines model for AddMember.

type AddMemberToVaultJSONRequestBody

type AddMemberToVaultJSONRequestBody AddMember

AddMemberToVaultJSONRequestBody defines body for AddMemberToVault for application/json ContentType.

type AddMemberToVaultResponse

type AddMemberToVaultResponse struct {
	Body         []byte
	HTTPResponse *http.Response
}

func ParseAddMemberToVaultResponse

func ParseAddMemberToVaultResponse(rsp *http.Response) (*AddMemberToVaultResponse, error)

ParseAddMemberToVaultResponse parses an HTTP response from a AddMemberToVaultWithResponse call

func (AddMemberToVaultResponse) Status

func (r AddMemberToVaultResponse) Status() string

Status returns HTTPResponse.Status

func (AddMemberToVaultResponse) StatusCode

func (r AddMemberToVaultResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type CheckVaultMembershipResponse

type CheckVaultMembershipResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *struct {
		// A diagnostic message about the vault membership.
		Message string `json:"message"`
	}
	JSON404 *struct {
		Error string `json:"error"`
	}
}

func ParseCheckVaultMembershipResponse

func ParseCheckVaultMembershipResponse(rsp *http.Response) (*CheckVaultMembershipResponse, error)

ParseCheckVaultMembershipResponse parses an HTTP response from a CheckVaultMembershipWithResponse call

func (CheckVaultMembershipResponse) Status

Status returns HTTPResponse.Status

func (CheckVaultMembershipResponse) StatusCode

func (r CheckVaultMembershipResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type ChiServerOptions

type ChiServerOptions struct {
	BaseURL          string
	BaseRouter       chi.Router
	Middlewares      []MiddlewareFunc
	ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func (*Client) AddMemberToVault

func (c *Client) AddMemberToVault(ctx context.Context, vaultId string, body AddMemberToVaultJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) AddMemberToVaultWithBody

func (c *Client) AddMemberToVaultWithBody(ctx context.Context, vaultId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) CheckVaultMembership

func (c *Client) CheckVaultMembership(ctx context.Context, vaultId string, memberId string, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) RemoveMemberFromVault

func (c *Client) RemoveMemberFromVault(ctx context.Context, vaultId string, memberId string, reqEditors ...RequestEditorFn) (*http.Response, error)

type ClientInterface

type ClientInterface interface {
	// AddMemberToVault request with any body
	AddMemberToVaultWithBody(ctx context.Context, vaultId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)

	AddMemberToVault(ctx context.Context, vaultId string, body AddMemberToVaultJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)

	// CheckVaultMembership request
	CheckVaultMembership(ctx context.Context, vaultId string, memberId string, reqEditors ...RequestEditorFn) (*http.Response, error)

	// RemoveMemberFromVault request
	RemoveMemberFromVault(ctx context.Context, vaultId string, memberId string, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func (*ClientWithResponses) AddMemberToVaultWithBodyWithResponse

func (c *ClientWithResponses) AddMemberToVaultWithBodyWithResponse(ctx context.Context, vaultId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AddMemberToVaultResponse, error)

AddMemberToVaultWithBodyWithResponse request with arbitrary body returning *AddMemberToVaultResponse

func (*ClientWithResponses) AddMemberToVaultWithResponse

func (c *ClientWithResponses) AddMemberToVaultWithResponse(ctx context.Context, vaultId string, body AddMemberToVaultJSONRequestBody, reqEditors ...RequestEditorFn) (*AddMemberToVaultResponse, error)

func (*ClientWithResponses) CheckVaultMembershipWithResponse

func (c *ClientWithResponses) CheckVaultMembershipWithResponse(ctx context.Context, vaultId string, memberId string, reqEditors ...RequestEditorFn) (*CheckVaultMembershipResponse, error)

CheckVaultMembershipWithResponse request returning *CheckVaultMembershipResponse

func (*ClientWithResponses) RemoveMemberFromVaultWithResponse

func (c *ClientWithResponses) RemoveMemberFromVaultWithResponse(ctx context.Context, vaultId string, memberId string, reqEditors ...RequestEditorFn) (*RemoveMemberFromVaultResponse, error)

RemoveMemberFromVaultWithResponse request returning *RemoveMemberFromVaultResponse

type ClientWithResponsesInterface

type ClientWithResponsesInterface interface {
	// AddMemberToVault request with any body
	AddMemberToVaultWithBodyWithResponse(ctx context.Context, vaultId string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AddMemberToVaultResponse, error)

	AddMemberToVaultWithResponse(ctx context.Context, vaultId string, body AddMemberToVaultJSONRequestBody, reqEditors ...RequestEditorFn) (*AddMemberToVaultResponse, error)

	// CheckVaultMembership request
	CheckVaultMembershipWithResponse(ctx context.Context, vaultId string, memberId string, reqEditors ...RequestEditorFn) (*CheckVaultMembershipResponse, error)

	// RemoveMemberFromVault request
	RemoveMemberFromVaultWithResponse(ctx context.Context, vaultId string, memberId string, reqEditors ...RequestEditorFn) (*RemoveMemberFromVaultResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse defines model for ErrorResponse.

type GetMembership

type GetMembership struct {
	Vault  string
	User   string
	Result *Membership
}

GetMembership is the access pattern to fetch a vault membership from DynamoDB.

It returns ddb.ErrNoItems if the vault membership doesn't exist.

func (*GetMembership) BuildQuery

func (g *GetMembership) BuildQuery() (*dynamodb.QueryInput, error)

func (*GetMembership) UnmarshalQueryOutput

func (g *GetMembership) UnmarshalQueryOutput(out *dynamodb.QueryOutput) error

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type InvalidParamFormatError

type InvalidParamFormatError struct {
	ParamName string
	Err       error
}

func (*InvalidParamFormatError) Error

func (e *InvalidParamFormatError) Error() string

func (*InvalidParamFormatError) Unwrap

func (e *InvalidParamFormatError) Unwrap() error

type Membership

type Membership struct {
	Vault  string `json:"vault" dynamodbav:"vault"`
	User   string `json:"user" dynamodbav:"user"`
	Active bool   `json:"active"`
}

func (*Membership) DDBKeys

func (m *Membership) DDBKeys() (ddb.Keys, error)

type MembershipResponse

type MembershipResponse struct {
	// A diagnostic message about the vault membership.
	Message string `json:"message"`
}

MembershipResponse defines model for MembershipResponse.

type MiddlewareFunc

type MiddlewareFunc func(http.HandlerFunc) http.HandlerFunc

type RemoveMemberFromVaultResponse

type RemoveMemberFromVaultResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON404      *struct {
		Error string `json:"error"`
	}
}

func ParseRemoveMemberFromVaultResponse

func ParseRemoveMemberFromVaultResponse(rsp *http.Response) (*RemoveMemberFromVaultResponse, error)

ParseRemoveMemberFromVaultResponse parses an HTTP response from a RemoveMemberFromVaultWithResponse call

func (RemoveMemberFromVaultResponse) Status

Status returns HTTPResponse.Status

func (RemoveMemberFromVaultResponse) StatusCode

func (r RemoveMemberFromVaultResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function

type RequiredHeaderError

type RequiredHeaderError struct {
	ParamName string
	Err       error
}

func (*RequiredHeaderError) Error

func (e *RequiredHeaderError) Error() string

func (*RequiredHeaderError) Unwrap

func (e *RequiredHeaderError) Unwrap() error

type RequiredParamError

type RequiredParamError struct {
	ParamName string
}

func (*RequiredParamError) Error

func (e *RequiredParamError) Error() string

type ServerInterface

type ServerInterface interface {
	// Add member to vault
	// (POST /vaults/{vaultId}/members)
	AddMemberToVault(w http.ResponseWriter, r *http.Request, vaultId string)
	// Check vault membership
	// (GET /vaults/{vaultId}/members/{memberId})
	CheckVaultMembership(w http.ResponseWriter, r *http.Request, vaultId string, memberId string)
	// Remove a member from a vault
	// (POST /vaults/{vaultId}/members/{memberId}/remove)
	RemoveMemberFromVault(w http.ResponseWriter, r *http.Request, vaultId string, memberId string)
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler            ServerInterface
	HandlerMiddlewares []MiddlewareFunc
	ErrorHandlerFunc   func(w http.ResponseWriter, r *http.Request, err error)
}

ServerInterfaceWrapper converts contexts to parameters.

func (*ServerInterfaceWrapper) AddMemberToVault

func (siw *ServerInterfaceWrapper) AddMemberToVault(w http.ResponseWriter, r *http.Request)

AddMemberToVault operation middleware

func (*ServerInterfaceWrapper) CheckVaultMembership

func (siw *ServerInterfaceWrapper) CheckVaultMembership(w http.ResponseWriter, r *http.Request)

CheckVaultMembership operation middleware

func (*ServerInterfaceWrapper) RemoveMemberFromVault

func (siw *ServerInterfaceWrapper) RemoveMemberFromVault(w http.ResponseWriter, r *http.Request)

RemoveMemberFromVault operation middleware

type TooManyValuesForParamError

type TooManyValuesForParamError struct {
	ParamName string
	Count     int
}

func (*TooManyValuesForParamError) Error

type UnescapedCookieParamError

type UnescapedCookieParamError struct {
	ParamName string
	Err       error
}

func (*UnescapedCookieParamError) Error

func (e *UnescapedCookieParamError) Error() string

func (*UnescapedCookieParamError) Unwrap

func (e *UnescapedCookieParamError) Unwrap() error

type UnmarshalingParamError

type UnmarshalingParamError struct {
	ParamName string
	Err       error
}

func (*UnmarshalingParamError) Error

func (e *UnmarshalingParamError) Error() string

func (*UnmarshalingParamError) Unwrap

func (e *UnmarshalingParamError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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