Documentation ¶
Index ¶
- func AuthenticationRequired(authNegotiator AuthNegotiator, next http.Handler) http.Handler
- func BasicParser(r *http.Request) (authn.Credential, error)
- func HasPermission(rules authz.Rules, action string, subject authz.Subject, next http.Handler) http.Handler
- func HelloWorld(w http.ResponseWriter, r *http.Request)
- func JWTParser(r *http.Request) (authn.Credential, error)
- func LogEvent(ctx context.Context, e events.Event)
- func NewCommandHandler(rules authz.Rules) http.Handler
- func NewTokenHandler(secret []byte, method jwt.SigningMethod) http.Handler
- type AuthNegotiator
- type AuthPair
- type AuthParser
- type CommandHandler
- type JWTGenerator
- type MockProductService
- type MockRepository
- type Request
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthenticationRequired ¶
func AuthenticationRequired(authNegotiator AuthNegotiator, next http.Handler) http.Handler
AuthenticationRequired wraps http requests with authentication step
func BasicParser ¶
func BasicParser(r *http.Request) (authn.Credential, error)
BasicParser parses a *http.Request for a Basic credentials
func HasPermission ¶
func HasPermission(rules authz.Rules, action string, subject authz.Subject, next http.Handler) http.Handler
HasPermission protects an endpoint with some basic rbac
func HelloWorld ¶
func HelloWorld(w http.ResponseWriter, r *http.Request)
HelloWorld simple http handler for testing out auth stuff
func JWTParser ¶
func JWTParser(r *http.Request) (authn.Credential, error)
JWTParser parses a *http.Request for a JWT
func LogEvent ¶
LogEvent an event observer that logs events with some contextual information like the user and request id.
func NewCommandHandler ¶
NewCommandHandler creates a new http handler to serve cart api requests
func NewTokenHandler ¶
func NewTokenHandler(secret []byte, method jwt.SigningMethod) http.Handler
NewTokenHandler creates a new http handler that we swap creds for a token
Types ¶
type AuthNegotiator ¶
type AuthNegotiator func(r *http.Request) (authn.Authenticator, authn.Credential, error)
AuthNegotiator returns an authn.Authenticator as per request parameters
func AuthenticatorNegotiationFactory ¶
func AuthenticatorNegotiationFactory(authPairs map[string]AuthPair) AuthNegotiator
AuthenticatorNegotiationFactory parses a request to instantiate a contextual authenticator populated with its required parameters
type AuthPair ¶
type AuthPair struct { Store authn.CredStore Parser AuthParser }
AuthPair pairs a auth.CredStore with a Parser that can extract credentials from a *http.Request
type AuthParser ¶
type AuthParser func(r *http.Request) (authn.Credential, error)
AuthParser parses a request and returns authn.Credential
type CommandHandler ¶
type CommandHandler struct {
// contains filtered or unexported fields
}
CommandHandler recieves command requests and routes them to the proper service
func (*CommandHandler) ServeHTTP ¶
func (c *CommandHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type JWTGenerator ¶
type JWTGenerator struct {
// contains filtered or unexported fields
}
JWTGenerator http handler that will generate JWT tokens
func (JWTGenerator) ServeHTTP ¶
func (j JWTGenerator) ServeHTTP(w http.ResponseWriter, r *http.Request)
type MockProductService ¶
type MockProductService struct{}
MockProductService fake product service
func (*MockProductService) GetProduct ¶
func (m *MockProductService) GetProduct( ctx context.Context, input *product.GetProductInput, ) (*product.GetProductOutput, error)
GetProduct returns fake product
type MockRepository ¶
MockRepository fake cart repository
func (*MockRepository) GetCart ¶
func (m *MockRepository) GetCart(cartID string) (c cart.Cart, err error)
GetCart gets cart from global fixture
type Request ¶
type Request struct { Command string `json:"command"` RequestID string `json:"request_id,omitempty"` // CreateCart *cart.CreateCartInput `json:"create_cart,omitempty"` AddItems *cart.AddItemsInput `json:"add_items,omitempty"` UpdateItems *cart.UpdateItemsInput `json:"update_items,omitempty"` RemoveItems *cart.RemoveItemsInput `json:"remove_items,omitempty"` AddCouponCode *cart.AddCouponCodeInput `json:"add_coupon_code,omitempty"` RemoveCouponCode *cart.RemoveCouponCodeInput `json:"remove_coupon_code,omitempty"` SetSpecialInstructions *cart.SetSpecialInstructionsInput `json:"set_special_instructions,omitempty"` CalculateShipping *cart.CalculateShippingInput `json:"calculate_shipping,omitempty"` CalculateSalesTax *cart.CalculateSalesTaxInput `json:"calculate_sales_tax,omitempty"` SetShippingAddress *cart.SetShippingAddressInput `json:"set_shipping_address,omitempty"` SetBillingAddress *cart.SetBillingAddressInput `json:"set_billing_address,omitempty"` SetPaymentMethod *cart.SetPaymentMethodInput `json:"set_payment_method,omitempty"` SubmitOrder *cart.SubmitOrderInput `json:"submit_order,omitempty"` }
Request command endpoint request body
type Response ¶
type Response struct { Command string `json:"command"` RequestID string `json:"request_id,omitempty"` CreateCart *cart.CreateCartOutput `json:"create_cart,omitempty"` AddItems *cart.AddItemsOutput `json:"add_items,omitempty"` UpdateItems *cart.UpdateItemsOutput `json:"update_items,omitempty"` RemoveItems *cart.RemoveItemsOutput `json:"remove_items,omitempty"` AddCouponCode *cart.AddCouponCodeOutput `json:"add_coupon_code,omitempty"` RemoveCouponCode *cart.RemoveCouponCodeOutput `json:"remove_coupon_code,omitempty"` SetSpecialInstructions *cart.SetSpecialInstructionsOutput `json:"set_special_instructions,omitempty"` CalculateShipping *cart.CalculateShippingOutput `json:"calculate_shipping,omitempty"` CalculateSalesTax *cart.CalculateSalesTaxOutput `json:"calculate_sales_tax,omitempty"` SetShippingAddress *cart.SetShippingAddressOutput `json:"set_shipping_address,omitempty"` SetBillingAddress *cart.SetBillingAddressOutput `json:"set_billing_address,omitempty"` SetPaymentMethod *cart.SetPaymentMethodOutput `json:"set_payment_method,omitempty"` SubmitOrder *cart.SubmitOrderOutput `json:"submit_order,omitempty"` }
Response command endpoint response body