gatewayapi

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: AGPL-3.0 Imports: 9 Imported by: 0

README

gatewayapi (deprecated)

This pkg used to provide the handler for Lambda functions which served as a Lambda-proxy backend to API gateway.

Those internal gateways have all been removed, so this pkg now just contains a Client that makes it easy to talk to those old Lambda handlers directly:

  • panther-analysis-api
  • panther-compliance-api
  • panther-remediation-api
  • panther-resources-api
package main

import (
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/lambda"

    "github.com/panther-labs/panther/api/lambda/analysis/models"
	"github.com/panther-labs/panther/pkg/gatewayapi"
)

// Example usage
func main() {
    awsSession := session.Must(session.NewSession())
    client := gatewayapi.NewClient(lambda.New(awsSession), "panther-analysis-api")

    input := models.LambdaInput{ListRules: &models.ListRulesInput{}}
    var output models.ListRulesOutput
    statusCode, err := client.Invoke(&input, &output)
}

Once the internal API has been consolidated, this package will no longer be necessary.

Do not use this pkg for any new code.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalResponse

func MarshalResponse(response interface{}, statusCode int) *events.APIGatewayProxyResponse

MarshalResponse replaces nil maps + slices and serializes a response model.

response is a pointer to a struct and statusCode is the http status to return

Types

type API added in v1.12.0

type API interface {
	Invoke(input, output interface{}) (int, error)
}

type Client added in v1.12.0

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

func NewClient added in v1.12.0

func NewClient(lambda lambdaiface.LambdaAPI, functionName string) *Client

Create a new client for invoking a lambda gateway API proxy directly.

func (*Client) Invoke added in v1.12.0

func (client *Client) Invoke(input, output interface{}) (int, error)

Invoke a former API gateway proxy Lambda directly.

Unmarshals the response body into output and returns (http status code, error). A non-nil error could be caused by:

  • failure to marshal request / unmarshal response
  • lambda function failed to invoke (does not exist, insufficient permissions)
  • lambda function runtime exception (panic, OOM, timeout)
  • status code is not 2XX

This is similar to genericapi.Invoke and will be obsolete once we consolidate the internal API.

type MockClient added in v1.12.0

type MockClient struct {
	API
	mock.Mock
}

func (*MockClient) Invoke added in v1.12.0

func (m *MockClient) Invoke(input, output interface{}) (int, error)

Jump to

Keyboard shortcuts

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