Skip to content

Commit

Permalink
Merge pull request #18 from twharmon/sfn
Browse files Browse the repository at this point in the history
Add sfn to provided services
  • Loading branch information
twharmon authored Aug 2, 2022
2 parents 7b36e33 + 751fa8c commit 4eb3f44
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- main
name: Test
jobs:
test:
Expand All @@ -7,15 +13,13 @@ jobs:
go-version: [1.18]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Run coverage
run: go test -race -coverprofile=coverage.out -covermode=atomic
- name: Upload coverage to Codecov
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Golamb

![](https://github.com/twharmon/golamb/workflows/Test/badge.svg) [![](https://goreportcard.com/badge/github.com/twharmon/golamb)](https://goreportcard.com/report/github.com/twharmon/golamb) [![codecov](https://codecov.io/gh/twharmon/golamb/branch/main/graph/badge.svg?token=K0P59TPRAL)](https://codecov.io/gh/twharmon/golamb)
[![Go Reference](https://pkg.go.dev/badge/github.com/twharmon/golamb.svg)](https://pkg.go.dev/github.com/twharmon/golamb) ![](https://github.com/twharmon/golamb/workflows/Test/badge.svg) [![](https://goreportcard.com/badge/github.com/twharmon/golamb)](https://goreportcard.com/report/github.com/twharmon/golamb) [![codecov](https://codecov.io/gh/twharmon/golamb/branch/main/graph/badge.svg?token=K0P59TPRAL)](https://codecov.io/gh/twharmon/golamb)

Golamb makes it easier to write AWS Lambda functions in Go that are invoked by API Gateway Http APIs.

Expand Down
13 changes: 13 additions & 0 deletions fakes/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbiface"
"github.com/aws/aws-sdk-go/service/s3/s3iface"
"github.com/aws/aws-sdk-go/service/ses/sesiface"
"github.com/aws/aws-sdk-go/service/sfn/sfniface"
"github.com/aws/aws-sdk-go/service/ssm/ssmiface"
"github.com/aws/aws-sdk-go/service/sts/stsiface"
)
Expand All @@ -15,6 +16,7 @@ type AWS struct {
s3 s3iface.S3API
sts stsiface.STSAPI
ssm ssmiface.SSMAPI
sfn sfniface.SFNAPI
}

// NewAWS creates a value that implements the
Expand Down Expand Up @@ -48,6 +50,11 @@ func (a *AWS) SSM() ssmiface.SSMAPI {
return a.ssm
}

// SFN implements the golamb.AWSServiceProvider interface.
func (a *AWS) SFN() sfniface.SFNAPI {
return a.sfn
}

// WithDynamoDB sets the dynamodb client of the AWSServiceProvider.
func (a *AWS) WithDynamoDB(svc dynamodbiface.DynamoDBAPI) *AWS {
a.dynamodb = svc
Expand Down Expand Up @@ -77,3 +84,9 @@ func (a *AWS) WithSSM(svc ssmiface.SSMAPI) *AWS {
a.ssm = svc
return a
}

// WithSFN sets the sfn client of the AWSServiceProvider.
func (a *AWS) WithSFN(svc sfniface.SFNAPI) *AWS {
a.sfn = svc
return a
}
28 changes: 28 additions & 0 deletions serviceprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/aws/aws-sdk-go/service/s3/s3iface"
"github.com/aws/aws-sdk-go/service/ses"
"github.com/aws/aws-sdk-go/service/ses/sesiface"
"github.com/aws/aws-sdk-go/service/sfn"
"github.com/aws/aws-sdk-go/service/sfn/sfniface"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/aws/aws-sdk-go/service/ssm/ssmiface"
"github.com/aws/aws-sdk-go/service/sts"
Expand All @@ -23,6 +25,7 @@ type awsServiceProvider struct {
s3 *s3.S3
sts *sts.STS
ssm *ssm.SSM
sfn *sfn.SFN
}

// AWSServiceProviderConfig holds config information for the AWS
Expand All @@ -34,6 +37,7 @@ type AWSServiceProviderConfig struct {
S3 *aws.Config
STS *aws.Config
SSM *aws.Config
SFN *aws.Config
}

// AWSServiceProvider provides some common AWS service clients.
Expand All @@ -52,6 +56,9 @@ type AWSServiceProvider interface {

// SSM provides a SSM client
SSM() ssmiface.SSMAPI

// SFN provides a SFN client
SFN() sfniface.SFNAPI
}

func (sp *awsServiceProvider) loadSession() {
Expand Down Expand Up @@ -145,6 +152,22 @@ func (sp *awsServiceProvider) loadSTS() {
sp.sts = sts.New(sp.session)
}

func (sp *awsServiceProvider) loadSFN() {
if sp.sfn != nil {
return
}
sp.loadSession()
if sp.config.SFN != nil {
sp.sfn = sfn.New(sp.session, sp.config.SFN)
return
}
if sp.config.Default != nil {
sp.sfn = sfn.New(sp.session, sp.config.Default)
return
}
sp.sfn = sfn.New(sp.session)
}

func (sp *awsServiceProvider) DynamoDB() dynamodbiface.DynamoDBAPI {
sp.loadDynamoDB()
return sp.dynamodb
Expand All @@ -169,3 +192,8 @@ func (sp *awsServiceProvider) SSM() ssmiface.SSMAPI {
sp.loadSSM()
return sp.ssm
}

func (sp *awsServiceProvider) SFN() sfniface.SFNAPI {
sp.loadSFN()
return sp.sfn
}

0 comments on commit 4eb3f44

Please sign in to comment.