mesh

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HdrRequestContext = "x-request-context"
	InfoRoute         = "/__herokuIntegrationServiceMeshInfo"
)

Constants used across packages

View Source
const (
	HdrClientContext              = "x-client-context"
	HdrSignature                  = "x-signature"
	OrgIdQueryParam               = "orgId"
	ApiNameQueryParam             = "apiName"
	SalesforceExpectedHeaderCount = 2
)
View Source
const (
	HdrNameRequestID = "x-request-id"
)

Variables

This section is empty.

Functions

func AuthenticateRequest

func AuthenticateRequest(
	requestID string,
	config *conf.Config,
	requestHeader *RequestHeader,
	incomingRespWriter http.ResponseWriter,
	incomingReq *http.Request,
	incomingReqBody []byte) bool

AuthenticateRequest Authenticate request based on request type - Salesforce or Data Action Target

func ForwardRequest

func ForwardRequest(
	requestID string,
	forwardApiUrl string,
	incomingRespWriter http.ResponseWriter,
	incomingReq *http.Request,
	incomingReqBody []byte) *http.Response

ForwardRequest Forward request to target API

func ForwardRequestReplyToIncomingRequest

func ForwardRequestReplyToIncomingRequest(
	startTime time.Time,
	requestID string,
	forwardApiUrl string,
	incomingRespWriter http.ResponseWriter,
	incomingReq *http.Request,
	incomingReqBody []byte)

ForwardRequestReplyToIncomingRequest Forward request to target API; send response to incoming request

func GetForwardUrl

func GetForwardUrl(host string, port string, forwardApiPath *http.Request) (string, error)

func InitializeRoutes

func InitializeRoutes(router chi.Router)

func InvokeDataTargetActionAuth

func InvokeDataTargetActionAuth(requestID string, config *conf.Config, dataActionTargetAuthRequestBody DataActionTargetAuthRequestBody) (int, string, error)

InvokeDataTargetActionAuth Authenticate Data Action Target webhook request

func InvokeHerokuIntegrationService

func InvokeHerokuIntegrationService(
	requestID string,
	config *conf.Config,
	operation string,
	apiPath string,
	httpMethod string,
	jsonBody []byte) (int, string, error)

InvokeHerokuIntegrationService Invoke given Heroku Integration API with given request JSON body.

func InvokeSalesforceAuth

func InvokeSalesforceAuth(requestID string, config *conf.Config, sfAuthRequestBody SalesforceAuthRequestBody) (int, string, error)

InvokeSalesforceAuth Authenticate Salesforce request

func LogDebug

func LogDebug(requestID string, msg string)

TODO: Combine w/ LogInfo and dynamically call appropriate log level func

func LogError

func LogError(requestID string, msg string)

TODO: Combine w/ LogInfo and dynamically call appropriate log level func

func LogInfo

func LogInfo(requestID string, msg string)

func LogWarn

func LogWarn(requestID string, msg string)

TODO: Combine w/ LogInfo and dynamically call appropriate log level func

func ReplyToIncomingRequest

func ReplyToIncomingRequest(requestID string, forwardResp *http.Response, incomingRespWriter http.ResponseWriter)

ReplyToIncomingRequest Send API response to incoming response

func ShouldBypassValidationAuthentication

func ShouldBypassValidationAuthentication(requestID string, config *conf.Config, apiPath string) bool

func TimeTrack

func TimeTrack(requestID string, startTime time.Time, name string)

Types

type DataActionTargetAuthRequestBody

type DataActionTargetAuthRequestBody struct {
	ApiName   string `json:"api_name"`
	OrgID     string `json:"org_id"`
	Signature string `json:"signature"`
	Payload   string `json:"payload"`
}

type InvalidRequest

type InvalidRequest struct {
	StatusCode int
	Err        error
}

func NewInvalidRequest

func NewInvalidRequest(message string) *InvalidRequest

NewInvalidRequest Return when request is invalid - 401 Unauthorized

func NewMalformedRequest

func NewMalformedRequest(message string) *InvalidRequest

NewMalformedRequest Return when request is structured correctly - likely a valid Salesforce/Data Cloud request, but headers or header content is incorrect - 400 Bad Request

func (*InvalidRequest) Error

func (e *InvalidRequest) Error() string

func (*InvalidRequest) HttpStatusCode

func (e *InvalidRequest) HttpStatusCode() int

type RequestHeader

type RequestHeader struct {
	XRequestID          string          `json:"x-request-id"`
	XRequestContext     XRequestContext `json:"x-request-context"`
	XClientContext      string          `json:"x-client-context"`
	XSignature          string          `json:"x-signature"`
	IsSalesforceRequest bool            `json:"isDataActionTargetRequest"`
}

func ValidateRequest

func ValidateRequest(requestID string, headers http.Header) (*RequestHeader, error)

ValidateRequest validates the request headers based on type - Salesforce or Data Action Target.

Request Salesforce request headers:

  • x-request-id
  • x-request-context
  • x-client-context

Required Data Action Target request headers:

  • x-request-id
  • x-signature

func ValidateRequestHandler

func ValidateRequestHandler(requestID string, incomingRespWriter http.ResponseWriter, incomingReq *http.Request) (bool, *RequestHeader)

ValidateRequestHandler Validate request headers

type Routes

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

func NewRoutes

func NewRoutes() *Routes

func (*Routes) ServiceMesh

func (routes *Routes) ServiceMesh() http.HandlerFunc

ServiceMesh intercepts Heroku Integration app API requests validating and authenticating each request based on type - Salesforce or Data Action Target.

For validation rules, see ValidateRequest.

Requests are authenticated with the app's associated Heroku Integration add-on resource.

If validation and authentication are successful, the mesh forwards the request to the target app API.

type SalesforceAuthRequestBody

type SalesforceAuthRequestBody struct {
	OrgDomainUrl string `json:"org_domain_url"`
	CoreJWTToken string `json:"core_jwt_token"`
	OrgID        string `json:"org_id"`
}

type XRequestContext

type XRequestContext struct {
	ID           string `json:"id"`
	Auth         string `json:"auth"`
	LoginUrl     string `json:"loginUrl"`
	OrgDomainUrl string `json:"orgDomainUrl"`
	OrgID        string `json:"orgId"`
	Resource     string `json:"resource"`
	Type         string `json:"type"`
}

Jump to

Keyboard shortcuts

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