Skip to content

Commit

Permalink
(fix): update deps, fix compatibility issues (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
fogfish authored Sep 14, 2024
1 parent 5184135 commit e5819f5
Show file tree
Hide file tree
Showing 20 changed files with 221 additions and 178 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"

- uses: actions/checkout@v4.1.1
- uses: actions/checkout@v4

- name: go build
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/check-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"

- uses: actions/checkout@v4.1.1
- uses: actions/checkout@v4

- uses: dominikh/[email protected].0
- uses: dominikh/[email protected].1
with:
install-go: false
4 changes: 2 additions & 2 deletions .github/workflows/check-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"

- uses: actions/checkout@v4.1.1
- uses: actions/checkout@v4

- name: go build
run: |
Expand Down
10 changes: 5 additions & 5 deletions broker/eventbridge/awscdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ type SinkProps struct {
Source []string
Categories []string
Pattern map[string]interface{}
Lambda *scud.FunctionGoProps
Function scud.FunctionProps
}

func NewSink(scope constructs.Construct, id *string, props *SinkProps) *Sink {
sink := &Sink{Construct: constructs.NewConstruct(scope, id)}

//
pattern := &awsevents.EventPattern{}
if props.Categories != nil && len(props.Categories) > 0 {
if len(props.Categories) > 0 {
seq := make([]*string, len(props.Categories))
for i, category := range props.Categories {
seq[i] = jsii.String(category)
}
pattern.DetailType = &seq
}

if props.Source != nil && len(props.Source) > 0 {
if len(props.Source) > 0 {
seq := make([]*string, len(props.Source))
for i, agent := range props.Source {
seq[i] = jsii.String(agent)
Expand All @@ -78,8 +78,8 @@ func NewSink(scope constructs.Construct, id *string, props *SinkProps) *Sink {
},
)

if props.Lambda != nil {
sink.Handler = scud.NewFunctionGo(sink.Construct, jsii.String("Func"), props.Lambda)
if props.Function != nil {
sink.Handler = scud.NewFunction(sink.Construct, jsii.String("Func"), props.Function)

sink.Rule.AddTarget(awseventstargets.NewLambdaFunction(
sink.Handler,
Expand Down
6 changes: 3 additions & 3 deletions broker/eventbridge/awscdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func TestEventBridgeCDK(t *testing.T) {
broker.NewSink(
&eventbridge.SinkProps{
Source: []string{"swarm-example-eventbridge"},
Lambda: &scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventbridge/dequeue",
Function: &scud.FunctionGoProps{
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventbridge/dequeue",
},
},
)
Expand Down
8 changes: 5 additions & 3 deletions broker/eventddb/awscdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ type Sink struct {

type SinkProps struct {
Table awsdynamodb.ITable
Lambda *scud.FunctionGoProps
Function scud.FunctionProps
EventSource *awslambdaeventsources.DynamoEventSourceProps
}

func NewSink(scope constructs.Construct, id *string, props *SinkProps) *Sink {
sink := &Sink{Construct: constructs.NewConstruct(scope, id)}

sink.Handler = scud.NewFunctionGo(sink.Construct, jsii.String("Func"), props.Lambda)
sink.Handler = scud.NewFunction(sink.Construct, jsii.String("Func"), props.Function)

eventsource := &awslambdaeventsources.DynamoEventSourceProps{
StartingPosition: awslambda.StartingPosition_LATEST,
Expand Down Expand Up @@ -142,7 +142,9 @@ func (broker *Broker) NewTable(props *awsdynamodb.TablePropsV2) awsdynamodb.ITab
}

if props.Billing == nil {
props.Billing = awsdynamodb.Billing_OnDemand()
props.Billing = awsdynamodb.Billing_OnDemand(
&awsdynamodb.MaxThroughputProps{},
)
}

if props.DynamoStream == "" {
Expand Down
6 changes: 3 additions & 3 deletions broker/eventddb/awscdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func TestEventDdbCDK(t *testing.T) {

broker.NewSink(
&eventddb.SinkProps{
Lambda: &scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventddb/dequeue",
Function: &scud.FunctionGoProps{
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventddb/dequeue",
},
},
)
Expand Down
4 changes: 2 additions & 2 deletions broker/events3/awscdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ type Sink struct {
type SinkProps struct {
Bucket awss3.Bucket
EventSource *awslambdaeventsources.S3EventSourceProps
Lambda *scud.FunctionGoProps
Function scud.FunctionProps
}

func NewSink(scope constructs.Construct, id *string, props *SinkProps) *Sink {
sink := &Sink{Construct: constructs.NewConstruct(scope, id)}

sink.Handler = scud.NewFunctionGo(sink.Construct, jsii.String("Func"), props.Lambda)
sink.Handler = scud.NewFunction(sink.Construct, jsii.String("Func"), props.Function)

eventsource := &awslambdaeventsources.S3EventSourceProps{
Events: &[]awss3.EventType{
Expand Down
6 changes: 3 additions & 3 deletions broker/events3/awscdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func TestEventS3CDK(t *testing.T) {

broker.NewSink(
&events3.SinkProps{
Lambda: &scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/events3/dequeue",
Function: &scud.FunctionGoProps{
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/events3/dequeue",
},
},
)
Expand Down
6 changes: 3 additions & 3 deletions broker/eventsqs/awscdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ type Sink struct {
}

type SinkProps struct {
Queue awssqs.IQueue
Lambda *scud.FunctionGoProps
Queue awssqs.IQueue
Function scud.FunctionProps
}

func NewSink(scope constructs.Construct, id *string, props *SinkProps) *Sink {
sink := &Sink{Construct: constructs.NewConstruct(scope, id)}

sink.Handler = scud.NewFunctionGo(sink.Construct, jsii.String("Func"), props.Lambda)
sink.Handler = scud.NewFunction(sink.Construct, jsii.String("Func"), props.Function)

source := awslambdaeventsources.NewSqsEventSource(props.Queue,
&awslambdaeventsources.SqsEventSourceProps{})
Expand Down
6 changes: 3 additions & 3 deletions broker/eventsqs/awscdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func TestEventBridgeCDK(t *testing.T) {

broker.NewSink(
&eventsqs.SinkProps{
Lambda: &scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventsqs/dequeue",
Function: &scud.FunctionGoProps{
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventsqs/dequeue",
},
},
)
Expand Down
83 changes: 54 additions & 29 deletions broker/websocket/awscdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/constructs-go/constructs/v10"
"github.com/aws/jsii-runtime-go"
"github.com/fogfish/golem/optics"
"github.com/fogfish/scud"
)

Expand All @@ -40,32 +41,16 @@ type Sink struct {
}

type SinkProps struct {
Route string
Lambda *scud.FunctionGoProps
Gateway awsapigatewayv2.WebSocketApi
Route string
Function scud.FunctionProps
Gateway awsapigatewayv2.WebSocketApi
}

func NewSink(scope constructs.Construct, id *string, props *SinkProps) *Sink {
sink := &Sink{Construct: constructs.NewConstruct(scope, id)}

if props.Lambda.FunctionProps == nil {
props.Lambda.FunctionProps = &awslambda.FunctionProps{}
}

if props.Lambda.FunctionProps.Environment == nil {
props.Lambda.FunctionProps.Environment = &map[string]*string{}
}

if _, has := (*props.Lambda.FunctionProps.Environment)["CONFIG_SWARM_WS_EVENT_TYPE"]; !has {
(*props.Lambda.FunctionProps.Environment)["CONFIG_SWARM_WS_EVENT_TYPE"] = jsii.String(props.Route)
}

if _, has := (*props.Lambda.FunctionProps.Environment)["CONFIG_SWARM_WS_URL"]; !has {
url := aws.ToString(props.Gateway.ApiEndpoint()) + "/" + stage
(*props.Lambda.FunctionProps.Environment)["CONFIG_SWARM_WS_URL"] = aws.String(url)
}

sink.Handler = scud.NewFunctionGo(sink.Construct, jsii.String("Func"), props.Lambda)
defaultEnvironment(props)
sink.Handler = scud.NewFunction(sink.Construct, jsii.String("Func"), props.Function)

it := integrations.NewWebSocketLambdaIntegration(jsii.String(props.Route), sink.Handler,
&integrations.WebSocketLambdaIntegrationProps{},
Expand All @@ -82,6 +67,46 @@ func NewSink(scope constructs.Construct, id *string, props *SinkProps) *Sink {
return sink
}

var (
lensFunction = optics.ForProduct1[scud.FunctionGoProps, *map[string]*string]("Environment")
lensContainer = optics.ForProduct1[scud.ContainerGoProps, *map[string]*string]("Environment")
)

func defineLambdaEnvironment[T any](lens optics.Lens[T, *map[string]*string], props *SinkProps, fprops *T) {
env := lens.Get(fprops)

if env == nil {
env = &map[string]*string{}
}

if _, has := (*env)["CONFIG_SWARM_WS_EVENT_TYPE"]; !has {
(*env)["CONFIG_SWARM_WS_EVENT_TYPE"] = jsii.String(props.Route)
}

if _, has := (*env)["CONFIG_SWARM_WS_URL"]; !has {
url := aws.ToString(props.Gateway.ApiEndpoint()) + "/" + stage
(*env)["CONFIG_SWARM_WS_URL"] = aws.String(url)
}

lens.Put(fprops, env)
}

func defaultEnvironment(props *SinkProps) {
switch fprops := props.Function.(type) {
case *scud.FunctionGoProps:
if fprops.FunctionProps == nil {
fprops.FunctionProps = &awslambda.FunctionProps{}
}

defineLambdaEnvironment(lensFunction, props, fprops)
case *scud.ContainerGoProps:
if fprops.DockerImageFunctionProps == nil {
fprops.DockerImageFunctionProps = &awslambda.DockerImageFunctionProps{}
}
defineLambdaEnvironment(lensContainer, props, fprops)
}
}

//------------------------------------------------------------------------------
//
// AWS CDK Stack Construct
Expand Down Expand Up @@ -123,8 +148,8 @@ func (broker *Broker) NewAuthorizerApiKey(props *AuthorizerApiKeyProps) awsapiga

handler := scud.NewFunctionGo(broker.Construct, jsii.String("Authorizer"),
&scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "broker/websocket/lambda/auth",
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "broker/websocket/lambda/auth",
FunctionProps: &awslambda.FunctionProps{
Environment: &map[string]*string{
"CONFIG_SWARM_WS_AUTHORIZER_ACCESS": jsii.String(props.Access),
Expand Down Expand Up @@ -165,8 +190,8 @@ func (broker *Broker) NewAuthorizerJwt(props *AuthorizerJwtProps) awsapigatewayv

handler := scud.NewFunctionGo(broker.Construct, jsii.String("Authorizer"),
&scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "broker/websocket/lambda/auth",
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "broker/websocket/lambda/auth",
FunctionProps: &awslambda.FunctionProps{
Environment: &map[string]*string{
"CONFIG_SWARM_WS_AUTHORIZER_ISS": jsii.String(props.Issuer),
Expand Down Expand Up @@ -215,8 +240,8 @@ func (broker *Broker) NewAuthorizerUniversal(props *AuthorizerUniversalProps) aw

handler := scud.NewFunctionGo(broker.Construct, jsii.String("Authorizer"),
&scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "broker/websocket/lambda/auth",
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "broker/websocket/lambda/auth",
FunctionProps: &awslambda.FunctionProps{
Environment: &map[string]*string{
"CONFIG_SWARM_WS_AUTHORIZER_ACCESS": jsii.String(props.AuthorizerApiKey.Access),
Expand Down Expand Up @@ -258,8 +283,8 @@ func (broker *Broker) NewGateway(props *WebSocketApiProps) awsapigatewayv2.WebSo
if props.WebSocketApiProps.ConnectRouteOptions == nil && broker.Authorizer != nil {
connector := scud.NewFunctionGo(broker.Construct, jsii.String("Connector"),
&scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "broker/websocket/lambda/connector",
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "broker/websocket/lambda/connector",
},
)

Expand Down
23 changes: 18 additions & 5 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,28 @@ type EventKind[A any] pure.HKT[EventType, A]
// changed together with using unique identifier.
type Event[T any] struct {
//
// Unique identity for event
// It is automatically defined by the library upon the transmission
// Unique identity for event.
// It is automatically defined by the library upon the transmission unless
// defined by sender. Preserving ID across sequence of messages allows
// building request/response semantic.
ID string `json:"id,omitempty"`

//
// Canonical IRI that defines a type of action.
// It is automatically defined by the library upon the transmission
// It is automatically defined by the library upon the transmission unless
// defined by sender.
Type curie.IRI `json:"type,omitempty"`

//
// Direct performer of the event, a software service that emits action to the stream.
// It is automatically defined by the library upon the transmission
// Direct performer of the event, a software service that emits action to
// the stream. It is automatically defined by the library upon the transmission
// unless defined by sender.
Agent curie.IRI `json:"agent,omitempty"`

//
// Indicates target performer of the event, a software service that is able to
Target curie.IRI `json:"target,omitempty"`

//
// Indirect participants, a user who initiated an event.
Participant curie.IRI `json:"participant,omitempty"`
Expand All @@ -58,6 +66,11 @@ type Event[T any] struct {
//
// The object upon which the event is carried out.
Object T `json:"object,omitempty"`

// Status (Pending | Success | Failure)
// Deadline before after | nbf NotBefore
// Target

}

func (Event[T]) HKT1(EventType) {}
Expand Down
6 changes: 3 additions & 3 deletions examples/eventbridge/serverless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func main() {
broker.NewSink(
&eventbridge.SinkProps{
Source: []string{"swarm-example-eventbridge"},
Lambda: &scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventbridge/dequeue",
Function: &scud.FunctionGoProps{
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventbridge/dequeue",
},
},
)
Expand Down
6 changes: 3 additions & 3 deletions examples/eventddb/serverless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func main() {

broker.NewSink(
&eventddb.SinkProps{
Lambda: &scud.FunctionGoProps{
SourceCodePackage: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventddb/dequeue",
Function: &scud.FunctionGoProps{
SourceCodeModule: "github.com/fogfish/swarm",
SourceCodeLambda: "examples/eventddb/dequeue",
},
},
)
Expand Down
Loading

0 comments on commit e5819f5

Please sign in to comment.