mock

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2019 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessKeyID     = "ASIAIOSFODNN7EXAMPLE"
	SecretAccessKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY"
)

Mock STS credentials.

Variables

View Source
var Ctx = arn.Ctx{Partition: "aws", Region: "us-east-1", Account: "000000000000"}

Ctx is a mock ARN context.

Functions

func AccountID

func AccountID(id string) string

AccountID validates account id and pads it with leading zeros, if required.

func RouteMethod

func RouteMethod(r interface{}, q *Request) bool

RouteMethod uses reflection to find a method of r that matches the API name. If such method is found, it handles the request. The method type must be:

func(q *mock.Request, in *svc.XyzInput)

func WriteJSON

func WriteJSON(w http.ResponseWriter, v interface{})

WriteJSON writes JSON encoding of v to w.

Types

type AWS

type AWS struct {
	CtxRouter
	Ctx arn.Ctx
	Cfg aws.Config
	// contains filtered or unexported fields
}

AWS is a mock AWS cloud that uses routers to handle requests.

func NewAWS

func NewAWS(ctx arn.Ctx, r ...Router) *AWS

NewAWS returns a mock AWS cloud configured with the specified context and custom routers. The STS router is added to the root context automatically.

func (*AWS) SessionToken

func (w *AWS) SessionToken(account, role, sessName string) string

SessionToken returns the session token for the specified account/role.

func (*AWS) UserCreds

func (w *AWS) UserCreds(account, user string) aws.StaticCredentialsProvider

UserCreds returns a mock credentials provider for the specified account/user.

type ChainRouter

type ChainRouter []Router

ChainRouter maintains a router chain, passing requests to each router, starting with the last one, until the request is handled.

func (*ChainRouter) Add

func (r *ChainRouter) Add(t ...Router)

Add appends new routers to the chain, giving them highest priority.

func (*ChainRouter) DataTypeRouter

func (r *ChainRouter) DataTypeRouter() (t DataTypeRouter)

DataTypeRouter returns the highest priority DataTypeRouter in the chain. A new router is created if one does not exist.

func (ChainRouter) Find

func (r ChainRouter) Find(v interface{}) bool

Find assigns v, which must be a Router pointer, the highest priority router of the matching type.

func (ChainRouter) OrgRouter

func (r ChainRouter) OrgRouter() (t *OrgRouter)

OrgRouter returns the highest priority OrgRouter in the chain.

func (*ChainRouter) RoleRouter

func (r *ChainRouter) RoleRouter() (t RoleRouter)

RoleRouter returns the highest priority RoleRouter in the chain. A new router is created if one does not exist.

func (ChainRouter) Route

func (r ChainRouter) Route(q *Request) bool

Route implements the Router interface.

func (*ChainRouter) STSRouter

func (r *ChainRouter) STSRouter() (t STSRouter)

STSRouter returns the highest priority STSRouter in the chain. A new router is created if one does not exist.

func (*ChainRouter) UserRouter

func (r *ChainRouter) UserRouter() (t UserRouter)

UserRouter returns the highest priority UserRouter in the chain. A new router is created if one does not exist.

type CtxRouter

type CtxRouter map[arn.Ctx]*ChainRouter

CtxRouter redirects requests to other routers using the ARN context. More specific context keys take priority over less specific ones. The zero value context matches all requests.

func (CtxRouter) Account

func (r CtxRouter) Account(id string) *ChainRouter

Account returns the router for the specified account ID.

func (CtxRouter) Get

func (r CtxRouter) Get(ctx arn.Ctx) *ChainRouter

Get returns the router for the specified context. A new router is created if one does not exist.

func (CtxRouter) Root

func (r CtxRouter) Root() *ChainRouter

Root returns the router that matches all contexts.

func (CtxRouter) Route

func (r CtxRouter) Route(q *Request) bool

Route implements the Router interface.

type DataTypeRouter

type DataTypeRouter map[reflect.Type]Response

DataTypeRouter handles requests based on the Data field type.

func NewDataTypeRouter

func NewDataTypeRouter(out ...interface{}) DataTypeRouter

NewDataTypeRouter returns a router that will serve 'out' values to all requests with a matching data output type. All out values should be pointers to AWS SDK XyzOutput structs.

func (DataTypeRouter) Get

func (r DataTypeRouter) Get(out interface{}) error

Get copies a response value of the matching type into out and returns the associated error, if any.

func (DataTypeRouter) Route

func (r DataTypeRouter) Route(q *Request) bool

Route implements the Router interface.

func (DataTypeRouter) Set

func (r DataTypeRouter) Set(out interface{}, err error)

Set allows the router to handle API requests with the given output type. If err is not nil, it will be used to set the request's Error field.

type OrgRouter

type OrgRouter struct {
	orgs.Organization
	Accounts map[string]*orgs.Account
	Next     uint64
}

OrgRouter handles Organizations API calls.

func NewOrg

func NewOrg(ctx arn.Ctx, master string, names ...string) *OrgRouter

NewOrg creates a new AWS organization router consisting of a master account and any number of additional non-master accounts. Account IDs are assigned sequentially starting from ctx.Account.

func (*OrgRouter) All

func (r *OrgRouter) All() []*orgs.Account

All returns all accounts sorted by account id.

func (*OrgRouter) CreateAccount

func (r *OrgRouter) CreateAccount(q *Request, in *orgs.CreateAccountInput)

func (*OrgRouter) DescribeAccount

func (r *OrgRouter) DescribeAccount(q *Request, in *orgs.DescribeAccountInput)

func (*OrgRouter) DescribeCreateAccountStatus

func (r *OrgRouter) DescribeCreateAccountStatus(q *Request, in *orgs.DescribeCreateAccountStatusInput)

func (*OrgRouter) DescribeOrganization

func (r *OrgRouter) DescribeOrganization(q *Request, _ *orgs.DescribeOrganizationInput)

func (*OrgRouter) Get

func (r *OrgRouter) Get(id string) *orgs.Account

Get returns the account with the given id.

func (*OrgRouter) ListAccounts

func (r *OrgRouter) ListAccounts(q *Request, _ *orgs.ListAccountsInput)

func (*OrgRouter) NewAccount

func (r *OrgRouter) NewAccount(name string) *orgs.Account

NewAccount adds a new account to the organization.

func (*OrgRouter) Route

func (r *OrgRouter) Route(q *Request) bool

Route implements the Router interface.

type Request

type Request struct {
	*aws.Request
	AWS *AWS
	Ctx arn.Ctx
}

Request wraps aws.Request to provide additional information.

func (*Request) Name

func (q *Request) Name() string

Name returns the service-qualified API name.

type Response

type Response struct {
	Out interface{}
	Err error
}

Response contains values that are assigned to request Data and Error fields.

type Role

type Role struct {
	iam.Role
	AttachedPolicies map[arn.ARN]string
	InlinePolicies   map[string]string
}

Role is a mock IAM role.

type RoleRouter

type RoleRouter map[string]*Role

RoleRouter handles IAM role API calls.

func (RoleRouter) AttachRolePolicy

func (r RoleRouter) AttachRolePolicy(q *Request, in *iam.AttachRolePolicyInput)

func (RoleRouter) CreateRole

func (r RoleRouter) CreateRole(q *Request, in *iam.CreateRoleInput)

func (RoleRouter) DeleteRole

func (r RoleRouter) DeleteRole(q *Request, in *iam.DeleteRoleInput)

func (RoleRouter) DeleteRolePolicy

func (r RoleRouter) DeleteRolePolicy(q *Request, in *iam.DeleteRolePolicyInput)

func (RoleRouter) DetachRolePolicy

func (r RoleRouter) DetachRolePolicy(q *Request, in *iam.DetachRolePolicyInput)

func (RoleRouter) GetRole

func (r RoleRouter) GetRole(q *Request, in *iam.GetRoleInput)

func (RoleRouter) ListAttachedRolePolicies

func (r RoleRouter) ListAttachedRolePolicies(q *Request, in *iam.ListAttachedRolePoliciesInput)

func (RoleRouter) ListRolePolicies

func (r RoleRouter) ListRolePolicies(q *Request, in *iam.ListRolePoliciesInput)

func (RoleRouter) ListRoles

func (r RoleRouter) ListRoles(q *Request, in *iam.ListRolesInput)

func (RoleRouter) PutRolePolicy

func (r RoleRouter) PutRolePolicy(q *Request, in *iam.PutRolePolicyInput)

func (RoleRouter) Route

func (r RoleRouter) Route(q *Request) bool

Route implements the Router interface.

func (RoleRouter) UpdateAssumeRolePolicy

func (r RoleRouter) UpdateAssumeRolePolicy(q *Request, in *iam.UpdateAssumeRolePolicyInput)

func (RoleRouter) UpdateRoleDescription

func (r RoleRouter) UpdateRoleDescription(q *Request, in *iam.UpdateRoleDescriptionInput)

type Router

type Router interface {
	Route(q *Request) bool
}

Router simulates AWS responses by populating request Data and Error fields. Route returns true if the request was handled or false if it should be passed to the next router.

type RouterFunc

type RouterFunc func(q *Request) bool

RouterFunc allows using a regular function as a router.

func (RouterFunc) Route

func (f RouterFunc) Route(q *Request) bool

Route implements the Router interface.

type STSRouter

type STSRouter map[arn.ARN]*sts.GetCallerIdentityOutput

STSRouter handles STS API calls. Key is SessionToken, which is the assumed role ARN, as returned by GetCallerIdentity.

func (STSRouter) AssumeRole

func (r STSRouter) AssumeRole(q *Request, in *sts.AssumeRoleInput)

func (STSRouter) GetCallerIdentity

func (r STSRouter) GetCallerIdentity(q *Request, _ *sts.GetCallerIdentityInput)

func (STSRouter) Route

func (r STSRouter) Route(q *Request) bool

Route implements the Router interface.

type Server

type Server struct {
	Response map[string]interface{}
	Handler  http.Handler
}

Server is a mock HTTP server.

func ClientServer

func ClientServer() (*http.Client, *Server)

ClientServer returns an HTTP client connected to a mock server.

func (*Server) RoundTrip

func (s *Server) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type User

type User struct {
	iam.User
	AccessKeys       []*iam.AccessKeyMetadata
	AttachedPolicies map[arn.ARN]string
}

User is a mock IAM user.

type UserRouter

type UserRouter map[string]*User

UserRouter handles IAM user API calls.

func (UserRouter) AttachUserPolicy

func (r UserRouter) AttachUserPolicy(q *Request, in *iam.AttachUserPolicyInput)

func (UserRouter) CreateAccessKey

func (r UserRouter) CreateAccessKey(q *Request, in *iam.CreateAccessKeyInput)

func (UserRouter) CreateUser

func (r UserRouter) CreateUser(q *Request, in *iam.CreateUserInput)

func (UserRouter) DeleteAccessKey

func (r UserRouter) DeleteAccessKey(q *Request, in *iam.DeleteAccessKeyInput)

func (UserRouter) DeleteUser

func (r UserRouter) DeleteUser(q *Request, in *iam.DeleteUserInput)

func (UserRouter) DetachUserPolicy

func (r UserRouter) DetachUserPolicy(q *Request, in *iam.DetachUserPolicyInput)

func (UserRouter) GetUser

func (r UserRouter) GetUser(q *Request, in *iam.GetUserInput)

func (UserRouter) ListAccessKeys

func (r UserRouter) ListAccessKeys(q *Request, in *iam.ListAccessKeysInput)

func (UserRouter) ListAttachedUserPolicies

func (r UserRouter) ListAttachedUserPolicies(q *Request, in *iam.ListAttachedUserPoliciesInput)

func (UserRouter) ListUsers

func (r UserRouter) ListUsers(q *Request, in *iam.ListUsersInput)

func (UserRouter) Route

func (r UserRouter) Route(q *Request) bool

Route implements the Router interface.

Jump to

Keyboard shortcuts

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