api

package
v0.0.0-...-040c84b Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2017 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

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

func LogEvent(ctx context.Context, e events.Event)

LogEvent an event observer that logs events with some contextual information like the user and request id.

func NewCommandHandler

func NewCommandHandler(rules authz.Rules) http.Handler

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

GetProduct returns fake product

type MockRepository

type MockRepository struct {
	sync.RWMutex
}

MockRepository fake cart repository

func (*MockRepository) GetCart

func (m *MockRepository) GetCart(cartID string) (c cart.Cart, err error)

GetCart gets cart from global fixture

func (*MockRepository) NewCart

func (m *MockRepository) NewCart(owner string) (cart.Cart, error)

NewCart finds a new id instantiates a cart and returns it

func (*MockRepository) SaveCart

func (m *MockRepository) SaveCart(ctx context.Context, cart cart.Cart) error

SaveCart saves cart to 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

Jump to

Keyboard shortcuts

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