diff --git a/cmd/event-received/factory.go b/cmd/event-received/factory.go index 625735a003..87cd345865 100644 --- a/cmd/event-received/factory.go +++ b/cmd/event-received/factory.go @@ -65,6 +65,7 @@ type Factory struct { searchEndpoint string searchIndexName string searchIndexingEnabled bool + eventClient EventClient // previously constructed values appData *page.AppData @@ -179,3 +180,11 @@ func (f *Factory) UidClient() UidClient { return f.uidClient } + +func (f *Factory) EventClient() EventClient { + if f.eventClient == nil { + f.eventClient = event.NewClient(f.cfg, f.eventBusName) + } + + return f.eventClient +} diff --git a/cmd/event-received/factory_test.go b/cmd/event-received/factory_test.go index 80003b7eee..6d72d7e8ad 100644 --- a/cmd/event-received/factory_test.go +++ b/cmd/event-received/factory_test.go @@ -186,3 +186,18 @@ func TestUidClientWhenSet(t *testing.T) { client := factory.UidClient() assert.Equal(t, expected, client) } + +func TestEventClient(t *testing.T) { + factory := &Factory{} + + client := factory.EventClient() + assert.NotNil(t, client) +} + +func TestEventClientWhenSet(t *testing.T) { + expected := newMockEventClient(t) + factory := &Factory{eventClient: expected} + + client := factory.EventClient() + assert.Equal(t, expected, client) +} diff --git a/cmd/event-received/main.go b/cmd/event-received/main.go index babc7f33bc..32bd77ecc4 100644 --- a/cmd/event-received/main.go +++ b/cmd/event-received/main.go @@ -18,6 +18,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/ministryofjustice/opg-modernising-lpa/internal/app" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/random" "github.com/ministryofjustice/opg-modernising-lpa/internal/s3" @@ -36,6 +37,7 @@ type factory interface { LpaStoreClient() (LpaStoreClient, error) UidStore() (UidStore, error) UidClient() UidClient + EventClient() EventClient } type Handler interface { @@ -64,6 +66,10 @@ type DocumentStore interface { UpdateScanResults(ctx context.Context, lpaID, objectKey string, virusDetected bool) error } +type EventClient interface { + SendApplicationUpdated(ctx context.Context, event event.ApplicationUpdated) error +} + type Event struct { events.S3Event events.CloudWatchEvent diff --git a/cmd/event-received/makeregister_event_handler.go b/cmd/event-received/makeregister_event_handler.go index fdf88f3de2..04cb3ba25d 100644 --- a/cmd/event-received/makeregister_event_handler.go +++ b/cmd/event-received/makeregister_event_handler.go @@ -21,15 +21,17 @@ func (h *makeregisterEventHandler) Handle(ctx context.Context, factory factory, } uidClient := factory.UidClient() + dynamoClient := factory.DynamoClient() + eventClient := factory.EventClient() - return handleUidRequested(ctx, uidStore, uidClient, cloudWatchEvent) + return handleUidRequested(ctx, uidStore, uidClient, cloudWatchEvent, dynamoClient, eventClient) default: return fmt.Errorf("unknown makeregister event") } } -func handleUidRequested(ctx context.Context, uidStore UidStore, uidClient UidClient, e events.CloudWatchEvent) error { +func handleUidRequested(ctx context.Context, uidStore UidStore, uidClient UidClient, e events.CloudWatchEvent, dynamoClient dynamodbClient, eventClient EventClient) error { var v event.UidRequested if err := json.Unmarshal(e.Detail, &v); err != nil { return fmt.Errorf("failed to unmarshal detail: %w", err) @@ -44,5 +46,24 @@ func handleUidRequested(ctx context.Context, uidStore UidStore, uidClient UidCli return fmt.Errorf("failed to set uid: %w", err) } + donor, err := getDonorByLpaUID(ctx, dynamoClient, uid) + if err != nil { + return err + } + + if err := eventClient.SendApplicationUpdated(ctx, event.ApplicationUpdated{ + UID: donor.LpaUID, + Type: donor.Type.String(), + CreatedAt: donor.CreatedAt, + Donor: event.ApplicationUpdatedDonor{ + FirstNames: donor.Donor.FirstNames, + LastName: donor.Donor.LastName, + DateOfBirth: donor.Donor.DateOfBirth, + Address: donor.Donor.Address, + }, + }); err != nil { + return err + } + return nil } diff --git a/cmd/event-received/makeregister_event_handler_test.go b/cmd/event-received/makeregister_event_handler_test.go index ce6cd6d1ae..39fd6e3b26 100644 --- a/cmd/event-received/makeregister_event_handler_test.go +++ b/cmd/event-received/makeregister_event_handler_test.go @@ -1,12 +1,18 @@ package main import ( + "context" "encoding/json" "fmt" "testing" "github.com/aws/aws-lambda-go/events" + "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" + "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + "github.com/ministryofjustice/opg-modernising-lpa/internal/event" + "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -20,18 +26,20 @@ func TestMakeRegisterHandlerHandleUnknownEvent(t *testing.T) { } func TestHandleUidRequested(t *testing.T) { - event := events.CloudWatchEvent{ + e := events.CloudWatchEvent{ DetailType: "uid-requested", Detail: json.RawMessage(`{"lpaID":"an-id","donorSessionID":"donor-id","organisationID":"org-id","type":"personal-welfare","donor":{"name":"a donor","dob":"2000-01-02","postcode":"F1 1FF"}}`), } + dob := date.New("2000", "01", "02") + uidClient := newMockUidClient(t) uidClient.EXPECT(). CreateCase(ctx, &uid.CreateCaseRequestBody{ Type: "personal-welfare", Donor: uid.DonorDetails{ Name: "a donor", - Dob: date.New("2000", "01", "02"), + Dob: dob, Postcode: "F1 1FF", }, }). @@ -42,6 +50,44 @@ func TestHandleUidRequested(t *testing.T) { Set(ctx, "an-id", "donor-id", "org-id", "M-1111-2222-3333"). Return(nil) + dynamoClient := newMockDynamodbClient(t) + dynamoClient. + On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything). + Return(func(ctx context.Context, uid string, v interface{}) error { + b, _ := attributevalue.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456"))}) + attributevalue.Unmarshal(b, v) + return nil + }) + dynamoClient. + On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error { + b, _ := attributevalue.Marshal(&actor.DonorProvidedDetails{ + Donor: actor.Donor{FirstNames: "a", LastName: "b", Address: place.Address{Line1: "a"}, DateOfBirth: dob}, + Type: actor.LpaTypePersonalWelfare, + CreatedAt: testNow, + LpaUID: "M-1111-2222-3333", + PK: dynamo.LpaKey("123"), + SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), + }) + attributevalue.Unmarshal(b, v) + return nil + }) + + eventClient := newMockEventClient(t) + eventClient.EXPECT(). + SendApplicationUpdated(ctx, event.ApplicationUpdated{ + UID: "M-1111-2222-3333", + Type: actor.LpaTypePersonalWelfare.String(), + CreatedAt: testNow, + Donor: event.ApplicationUpdatedDonor{ + FirstNames: "a", + LastName: "b", + DateOfBirth: date.New("2000", "1", "2"), + Address: place.Address{Line1: "a"}, + }, + }). + Return(nil) + factory := newMockFactory(t) factory.EXPECT(). UidStore(). @@ -49,9 +95,15 @@ func TestHandleUidRequested(t *testing.T) { factory.EXPECT(). UidClient(). Return(uidClient) + factory.EXPECT(). + DynamoClient(). + Return(dynamoClient) + factory.EXPECT(). + EventClient(). + Return(eventClient) handler := makeregisterEventHandler{} - err := handler.Handle(ctx, factory, event) + err := handler.Handle(ctx, factory, e) assert.Nil(t, err) } @@ -67,7 +119,7 @@ func TestHandleUidRequestedWhenUidClientErrors(t *testing.T) { CreateCase(ctx, mock.Anything). Return("", expectedError) - err := handleUidRequested(ctx, nil, uidClient, event) + err := handleUidRequested(ctx, nil, uidClient, event, nil, nil) assert.Equal(t, fmt.Errorf("failed to create case: %w", expectedError), err) } @@ -87,6 +139,47 @@ func TestHandleUidRequestedWhenUidStoreErrors(t *testing.T) { Set(ctx, "an-id", "donor-id", "", "M-1111-2222-3333"). Return(expectedError) - err := handleUidRequested(ctx, uidStore, uidClient, event) + err := handleUidRequested(ctx, uidStore, uidClient, event, nil, nil) assert.Equal(t, fmt.Errorf("failed to set uid: %w", expectedError), err) } + +func TestHandleUidRequestedWhenEventClientErrors(t *testing.T) { + e := events.CloudWatchEvent{ + DetailType: "uid-requested", + Detail: json.RawMessage(`{"lpaID":"an-id","donorSessionID":"donor-id","type":"personal-welfare","donor":{"name":"a donor","dob":"2000-01-02","postcode":"F1 1FF"}}`), + } + + uidClient := newMockUidClient(t) + uidClient.EXPECT(). + CreateCase(ctx, mock.Anything). + Return("M-1111-2222-3333", nil) + + uidStore := newMockUidStore(t) + uidStore.EXPECT(). + Set(ctx, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(nil) + + dynamoClient := newMockDynamodbClient(t) + dynamoClient. + On("OneByUID", mock.Anything, mock.Anything, mock.Anything). + Return(func(ctx context.Context, uid string, v interface{}) error { + b, _ := attributevalue.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456"))}) + attributevalue.Unmarshal(b, v) + return nil + }) + dynamoClient. + On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error { + b, _ := attributevalue.Marshal(&actor.DonorProvidedDetails{}) + attributevalue.Unmarshal(b, v) + return nil + }) + + eventClient := newMockEventClient(t) + eventClient.EXPECT(). + SendApplicationUpdated(ctx, mock.Anything). + Return(expectedError) + + err := handleUidRequested(ctx, uidStore, uidClient, e, dynamoClient, eventClient) + assert.Equal(t, expectedError, err) +} diff --git a/cmd/event-received/mock_EventClient_test.go b/cmd/event-received/mock_EventClient_test.go new file mode 100644 index 0000000000..73c9c5f073 --- /dev/null +++ b/cmd/event-received/mock_EventClient_test.go @@ -0,0 +1,84 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package main + +import ( + context "context" + + event "github.com/ministryofjustice/opg-modernising-lpa/internal/event" + mock "github.com/stretchr/testify/mock" +) + +// mockEventClient is an autogenerated mock type for the EventClient type +type mockEventClient struct { + mock.Mock +} + +type mockEventClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockEventClient) EXPECT() *mockEventClient_Expecter { + return &mockEventClient_Expecter{mock: &_m.Mock} +} + +// SendApplicationUpdated provides a mock function with given fields: ctx, _a1 +func (_m *mockEventClient) SendApplicationUpdated(ctx context.Context, _a1 event.ApplicationUpdated) error { + ret := _m.Called(ctx, _a1) + + if len(ret) == 0 { + panic("no return value specified for SendApplicationUpdated") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, event.ApplicationUpdated) error); ok { + r0 = rf(ctx, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockEventClient_SendApplicationUpdated_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendApplicationUpdated' +type mockEventClient_SendApplicationUpdated_Call struct { + *mock.Call +} + +// SendApplicationUpdated is a helper method to define mock.On call +// - ctx context.Context +// - _a1 event.ApplicationUpdated +func (_e *mockEventClient_Expecter) SendApplicationUpdated(ctx interface{}, _a1 interface{}) *mockEventClient_SendApplicationUpdated_Call { + return &mockEventClient_SendApplicationUpdated_Call{Call: _e.mock.On("SendApplicationUpdated", ctx, _a1)} +} + +func (_c *mockEventClient_SendApplicationUpdated_Call) Run(run func(ctx context.Context, _a1 event.ApplicationUpdated)) *mockEventClient_SendApplicationUpdated_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(event.ApplicationUpdated)) + }) + return _c +} + +func (_c *mockEventClient_SendApplicationUpdated_Call) Return(_a0 error) *mockEventClient_SendApplicationUpdated_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockEventClient_SendApplicationUpdated_Call) RunAndReturn(run func(context.Context, event.ApplicationUpdated) error) *mockEventClient_SendApplicationUpdated_Call { + _c.Call.Return(run) + return _c +} + +// newMockEventClient creates a new instance of mockEventClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockEventClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockEventClient { + mock := &mockEventClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/cmd/event-received/mock_factory_test.go b/cmd/event-received/mock_factory_test.go index 040d9a5510..24ea437cc4 100644 --- a/cmd/event-received/mock_factory_test.go +++ b/cmd/event-received/mock_factory_test.go @@ -126,6 +126,53 @@ func (_c *mockFactory_DynamoClient_Call) RunAndReturn(run func() dynamodbClient) return _c } +// EventClient provides a mock function with given fields: +func (_m *mockFactory) EventClient() EventClient { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for EventClient") + } + + var r0 EventClient + if rf, ok := ret.Get(0).(func() EventClient); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(EventClient) + } + } + + return r0 +} + +// mockFactory_EventClient_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EventClient' +type mockFactory_EventClient_Call struct { + *mock.Call +} + +// EventClient is a helper method to define mock.On call +func (_e *mockFactory_Expecter) EventClient() *mockFactory_EventClient_Call { + return &mockFactory_EventClient_Call{Call: _e.mock.On("EventClient")} +} + +func (_c *mockFactory_EventClient_Call) Run(run func()) *mockFactory_EventClient_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockFactory_EventClient_Call) Return(_a0 EventClient) *mockFactory_EventClient_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockFactory_EventClient_Call) RunAndReturn(run func() EventClient) *mockFactory_EventClient_Call { + _c.Call.Return(run) + return _c +} + // LpaStoreClient provides a mock function with given fields: func (_m *mockFactory) LpaStoreClient() (LpaStoreClient, error) { ret := _m.Called() diff --git a/cypress/e2e/donor/lpa-type.cy.js b/cypress/e2e/donor/lpa-type.cy.js index 6a048480d2..1c03826db5 100644 --- a/cypress/e2e/donor/lpa-type.cy.js +++ b/cypress/e2e/donor/lpa-type.cy.js @@ -13,6 +13,18 @@ describe('LPA type', () => { cy.visit(`http://localhost:9001/?detail-type=uid-requested&detail=${url.split('/')[4]}`); cy.contains(`"LpaID":"${url.split('/')[4]}"`); }); + + cy.visit('/dashboard') + + cy.contains('.govuk-body-s', 'Reference number:') + .invoke('text') + .then((text) => { + const uid = text.split(':')[1].trim(); + cy.visit(`http://localhost:9001/?detail-type=application-updated&detail=${uid}`); + + cy.contains(`"uid":"${uid}"`); + cy.contains('"type":"property-and-affairs"'); + }); }); it('errors when unselected', () => { diff --git a/go.sum b/go.sum index 595268a73d..161bf6aa3e 100644 --- a/go.sum +++ b/go.sum @@ -4,94 +4,52 @@ github.com/MicahParks/keyfunc/v3 v3.3.3 h1:c6j9oSu1YUo0k//KwF1miIQlEMtqNlj7XBFLB github.com/MicahParks/keyfunc/v3 v3.3.3/go.mod h1:f/UMyXdKfkZzmBeBFUeYk+zu066J1Fcl48f7Wnl5Z48= github.com/aws/aws-lambda-go v1.47.0 h1:0H8s0vumYx/YKs4sE7YM0ktwL2eWse+kfopsRI1sXVI= github.com/aws/aws-lambda-go v1.47.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A= -github.com/aws/aws-sdk-go-v2 v1.30.1 h1:4y/5Dvfrhd1MxRDD77SrfsDaj8kUkkljU7XE83NPV+o= -github.com/aws/aws-sdk-go-v2 v1.30.1/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc= github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY= github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3 h1:tW1/Rkad38LA15X4UQtjXZXNKsCgkshC3EbmcUmghTg= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.3/go.mod h1:UbnqO+zjqk3uIt9yCACHJ9IVNhyhOCnYk8yA19SAWrM= -github.com/aws/aws-sdk-go-v2/config v1.27.24 h1:NM9XicZ5o1CBU/MZaHwFtimRpWx9ohAUAqkG6AqSqPo= -github.com/aws/aws-sdk-go-v2/config v1.27.24/go.mod h1:aXzi6QJTuQRVVusAO8/NxpdTeTyr/wRcybdDtfUwJSs= github.com/aws/aws-sdk-go-v2/config v1.27.26 h1:T1kAefbKuNum/AbShMsZEro6eRkeOT8YILfE9wyjAYQ= github.com/aws/aws-sdk-go-v2/config v1.27.26/go.mod h1:ivWHkAWFrw/nxty5Fku7soTIVdqZaZ7dw+tc5iGW3GA= -github.com/aws/aws-sdk-go-v2/credentials v1.17.24 h1:YclAsrnb1/GTQNt2nzv+756Iw4mF8AOzcDfweWwwm/M= -github.com/aws/aws-sdk-go-v2/credentials v1.17.24/go.mod h1:Hld7tmnAkoBQdTMNYZGzztzKRdA4fCdn9L83LOoigac= github.com/aws/aws-sdk-go-v2/credentials v1.17.26 h1:tsm8g/nJxi8+/7XyJJcP2dLrnK/5rkFp6+i2nhmz5fk= github.com/aws/aws-sdk-go-v2/credentials v1.17.26/go.mod h1:3vAM49zkIa3q8WT6o9Ve5Z0vdByDMwmdScO0zvThTgI= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.14.7 h1:pPhmvNKbgb9l5VHcPmMx9g+FHtRbY+ba2J6GefXQGEI= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.14.7/go.mod h1:OZU7QRvIYXhKry99PttkDTQyN8yCo8RzYjhIKHdQXoo= github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.14.9 h1:aVVgQDwvAGq8Olf9nb+sQgSujPEybAg4ptxm+L2zisY= github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.14.9/go.mod h1:uCzvi36pXcTcGHwWXPHXkhaK9F4AjNo+IByRSv7BRe4= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9 h1:Aznqksmd6Rfv2HQN9cpqIV/lQRMaIpJkLLaJ1ZI76no= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.9/go.mod h1:WQr3MY7AxGNxaqAtsDWn+fBxmd4XvLkzeqQ8P1VM0/w= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11 h1:KreluoV8FZDEtI6Co2xuNk/UqI9iwMrOx/87PBNIKqw= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.11/go.mod h1:SeSUYBLsMYFoRvHE0Tjvn7kbxaUhl75CJi1sbfhMxkU= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13 h1:5SAoZ4jYpGH4721ZNoS1znQrhOfZinOhc4XuTXx/nVc= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.13/go.mod h1:+rdA6ZLpaSeM7tSg/B0IEDinCIBJGmW8rKDFkYpP04g= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15 h1:SoNJ4RlFEQEbtDcCEt+QG56MY4fm4W8rYirAmq+/DdU= github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.15/go.mod h1:U9ke74k1n2bf+RIgoX1SXFed1HLs51OgUSs+Ph0KJP8= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13 h1:WIijqeaAO7TYFLbhsZmi2rgLEAtWOC1LhxCAVTJlSKw= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.13/go.mod h1:i+kbfa76PQbWw/ULoWnp51EYVWH4ENln76fLQE3lXT8= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15 h1:C6WHdGnTDIYETAm5iErQUiVNsclNx9qbJVPIt03B6bI= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.15/go.mod h1:ZQLZqhcu+JhSrA9/NXRm8SkDvsycE+JkV3WGY41e+IM= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.13 h1:THZJJ6TU/FOiM7DZFnisYV9d49oxXWUzsVIMTuf3VNU= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.13/go.mod h1:VISUTg6n+uBaYIWPBaIG0jk7mbBxm7DUqBtU2cUDDWI= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.15 h1:Z5r7SycxmSllHYmaAZPpmN8GviDrSGhMS6bldqtXZPw= github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.15/go.mod h1:CetW7bDE00QoGEmPUoZuRog07SGVAUVW6LFpNP0YfIg= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.1 h1:Szwz1vpZkvfhFMJ0X5uUECgHeUmPAxk1UGqAVs/pARw= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.1/go.mod h1:b4wouGyJlzkr2HAvPrDGgYNp1EtmlXOkzhEOvl0c0FQ= github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.3 h1:nEhZKd1JQ4EB1tekcqW1oIVpDC1ZFrjrp/cLC5MXjFQ= github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.3/go.mod h1:q9vzW3Xr1KEXa8n4waHiFt1PrppNDlMymlYP+xpsFbY= -github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.22.1 h1:jfkCLx62YWL6bSOkT7aEDKNAX3OwWomlThCxQNBPvbY= -github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.22.1/go.mod h1:dLPiMfhRZhblwOeKqdNde7K9jl/pMuIGCGAwC6vQOIo= github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.22.3 h1:r27/FnxLPixKBRIlslsvhqscBuMK8uysCYG9Kfgm098= github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.22.3/go.mod h1:jqOFyN+QSWSoQC+ppyc4weiO8iNQXbzRbxDjQ1ayYd4= -github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.1 h1:3PRnz+WV+Bc5d9Gx98RvYYJQ32P0KlRUrHMULi3/kjw= -github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.1/go.mod h1:v4y6Klv2BhCY5bysrjNWKfZc1OSmc7x+fhTg4Bc42KY= github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.3 h1:pjZzcXU25gsD2WmlmlayEsyXIWMVOK3//x4BXvK9c0U= github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.3/go.mod h1:4ew4HelByABYyBE+8iU8Rzrp5PdBic5yd9nFMhbnwE8= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3 h1:dT3MqvGhSoaIhRseqw2I0yH81l7wiR2vjs57O51EAm8= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.3/go.mod h1:GlAeCkHwugxdHaueRr4nhPuY+WW+gR8UjlcqzPr1SPI= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.15 h1:2jyRZ9rVIMisyQRnhSS/SqlckveoxXneIumECVFP91Y= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.15/go.mod h1:bDRG3m382v1KJBk1cKz7wIajg87/61EiiymEyfLvAe0= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.17 h1:YPYe6ZmvUfDDDELqEKtAd6bo8zxhkm+XEFEzQisqUIE= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.17/go.mod h1:oBtcnYua/CgzCWYN7NZ5j7PotFDaFSUjCYVTtfyn7vw= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.14 h1:X1J0Kd17n1PeXeoArNXlvnKewCyMvhVQh7iNMy6oi3s= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.14/go.mod h1:VYMN7l7dxp6xtQRjqIau6d7QAbmPG+yJ75GtCy70f18= github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.16 h1:lhAX5f7KpgwyieXjbDnRTjPEUI0l3emSRyxXj1PXP8w= github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.16/go.mod h1:AblAlCwvi7Q/SFowvckgN+8M3uFPlopSYeLlbNDArhA= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.15 h1:I9zMeF107l0rJrpnHpjEiiTSCKYAIw8mALiXcPsGBiA= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.15/go.mod h1:9xWJ3Q/S6Ojusz1UIkfycgD1mGirJfLLKqq3LPT7WN8= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17 h1:HGErhhrxZlQ044RiM+WdoZxp0p+EGM62y3L6pwA4olE= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.17/go.mod h1:RkZEx4l0EHYDJpWppMJ3nD9wZJAa8/0lq9aVC+r2UII= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.13 h1:Eq2THzHt6P41mpjS2sUzz/3dJYFRqdWZ+vQaEMm98EM= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.13/go.mod h1:FgwTca6puegxgCInYwGjmd4tB9195Dd6LCuA+8MjpWw= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.15 h1:246A4lSTXWJw/rmlQI+TT2OcqeDMKBdyjEQrafMaQdA= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.15/go.mod h1:haVfg3761/WF7YPuJOER2MP0k4UAXyHaLclKXB6usDg= -github.com/aws/aws-sdk-go-v2/service/s3 v1.58.0 h1:4rhV0Hn+bf8IAIUphRX1moBcEvKJipCPmswMCl6Q5mw= -github.com/aws/aws-sdk-go-v2/service/s3 v1.58.0/go.mod h1:hdV0NTYd0RwV4FvNKhKUNbPLZoq9CTr/lke+3I7aCAI= github.com/aws/aws-sdk-go-v2/service/s3 v1.58.2 h1:sZXIzO38GZOU+O0C+INqbH7C2yALwfMWpd64tONS/NE= github.com/aws/aws-sdk-go-v2/service/s3 v1.58.2/go.mod h1:Lcxzg5rojyVPU/0eFwLtcyTaek/6Mtic5B1gJo7e/zE= -github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.1 h1:ZoYRD8IJqPkzjBnpokiMNO6L/DQprtpVpD6k0YSaF5U= -github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.1/go.mod h1:GlRarZzIMl9VDi0mLQt+qQOuEkVFPnTkkjyugV1uVa8= github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.3 h1:ilavrucVBQHYnMjD2KmZQDCU1fuluQb0l9zRigGNVEc= github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.3/go.mod h1:TKKN7IQoM7uTnyuFm9bm9cw5P//ZYTl4m3htBWQ1G/c= -github.com/aws/aws-sdk-go-v2/service/sqs v1.34.1 h1:Tp1oKSfWHE8fTz0H+DuD05cXPJ96Z6Rko0W/dAp7wJ0= -github.com/aws/aws-sdk-go-v2/service/sqs v1.34.1/go.mod h1:5gGM2xv51W5Hkyr3vj7JTEf/b5oOCb7rXcEVbXrcTAU= github.com/aws/aws-sdk-go-v2/service/sqs v1.34.3 h1:Vjqy5BZCOIsn4Pj8xzyqgGmsSqzz7y/WXbN3RgOoVrc= github.com/aws/aws-sdk-go-v2/service/sqs v1.34.3/go.mod h1:L0enV3GCRd5iG9B64W35C4/hwsCB00Ib+DKVGTadKHI= -github.com/aws/aws-sdk-go-v2/service/sso v1.22.1 h1:p1GahKIjyMDZtiKoIn0/jAj/TkMzfzndDv5+zi2Mhgc= -github.com/aws/aws-sdk-go-v2/service/sso v1.22.1/go.mod h1:/vWdhoIoYA5hYoPZ6fm7Sv4d8701PiG5VKe8/pPJL60= github.com/aws/aws-sdk-go-v2/service/sso v1.22.3 h1:Fv1vD2L65Jnp5QRsdiM64JvUM4Xe+E0JyVsRQKv6IeA= github.com/aws/aws-sdk-go-v2/service/sso v1.22.3/go.mod h1:ooyCOXjvJEsUw7x+ZDHeISPMhtwI3ZCB7ggFMcFfWLU= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.2 h1:ORnrOK0C4WmYV/uYt3koHEWBLYsRDwk2Np+eEoyV4Z0= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.2/go.mod h1:xyFHA4zGxgYkdD73VeezHt3vSKEG9EmFnGwoKlP00u4= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 h1:yiwVzJW2ZxZTurVbYWA7QOrAaCYQR72t0wrSBfoesUE= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4/go.mod h1:0oxfLkpz3rQ/CHlx5hB7H69YUpFiI1tql6Q6Ne+1bCw= -github.com/aws/aws-sdk-go-v2/service/sts v1.30.1 h1:+woJ607dllHJQtsnJLi52ycuqHMwlW+Wqm2Ppsfp4nQ= -github.com/aws/aws-sdk-go-v2/service/sts v1.30.1/go.mod h1:jiNR3JqT15Dm+QWq2SRgh0x0bCNSRP2L25+CqPNpJlQ= github.com/aws/aws-sdk-go-v2/service/sts v1.30.3 h1:ZsDKRLXGWHk8WdtyYMoGNO7bTudrvuKpDKgMVRlepGE= github.com/aws/aws-sdk-go-v2/service/sts v1.30.3/go.mod h1:zwySh8fpFyXp9yOr/KVzxOl8SRqgf/IDw5aUt9UKFcQ= github.com/aws/smithy-go v1.20.3 h1:ryHwveWzPV5BIof6fyDvor6V3iUL7nTfiTKXHiW05nE= @@ -171,8 +129,6 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/ministryofjustice/opg-go-common v1.4.0 h1:UjtBKWFX/MxWOk3cuUxvjM5qSxUv0u8J+ntPM336xyE= -github.com/ministryofjustice/opg-go-common v1.4.0/go.mod h1:uz6eLy9zp095mnWzBUbwzYjoaoHdCvTmowVC6IZ0Jxg= github.com/ministryofjustice/opg-go-common v1.8.0 h1:Uj+ALL/ZuNsG4tmf2fhlNJ1b6BKxBFWD0L/TG9/IhRE= github.com/ministryofjustice/opg-go-common v1.8.0/go.mod h1:qqspbBfGAq7A5tvl8mPQwWhlYw2FJWT0EkIGo9kHuYw= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= @@ -276,8 +232,6 @@ golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRj golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= -golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= @@ -286,19 +240,14 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= -golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= -golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI= google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 h1:0+ozOGcrp+Y8Aq8TLNN2Aliibms5LEzsq99ZZmAGYm0= diff --git a/terraform/environment/region/event_received.tf b/terraform/environment/region/event_received.tf index 7bda176e37..c6411f08f7 100644 --- a/terraform/environment/region/event_received.tf +++ b/terraform/environment/region/event_received.tf @@ -13,6 +13,7 @@ module "event_received" { lambda_function_image_ecr_url = data.aws_ecr_repository.event_received.repository_url lambda_function_image_tag = var.app_service_container_version event_bus_name = module.event_bus.event_bus.name + event_bus_arn = module.event_bus.event_bus.arn app_public_url = aws_route53_record.app.fqdn uploads_bucket = module.uploads_s3_bucket.bucket uid_base_url = var.uid_service.base_url diff --git a/terraform/environment/region/modules/event_bus/main.tf b/terraform/environment/region/modules/event_bus/main.tf index 88b6b3fd74..46482e5517 100644 --- a/terraform/environment/region/modules/event_bus/main.tf +++ b/terraform/environment/region/modules/event_bus/main.tf @@ -1,4 +1,4 @@ -# Event bus for reduced fees +# Event bus for opg.poas events resource "aws_cloudwatch_event_bus" "main" { name = data.aws_default_tags.current.tags.environment-name diff --git a/terraform/environment/region/modules/event_received/lambda.tf b/terraform/environment/region/modules/event_received/lambda.tf index 4f1d55fa2f..f41f719a74 100644 --- a/terraform/environment/region/modules/event_received/lambda.tf +++ b/terraform/environment/region/modules/event_received/lambda.tf @@ -13,6 +13,7 @@ module "event_received" { SEARCH_ENDPOINT = var.search_endpoint SEARCH_INDEX_NAME = var.search_index_name SEARCH_INDEXING_DISABLED = 1 + EVENT_BUS_NAME = var.event_bus_name } image_uri = "${var.lambda_function_image_ecr_url}:${var.lambda_function_image_tag}" aws_iam_role = var.event_received_lambda_role @@ -251,5 +252,16 @@ data "aws_iam_policy_document" "event_received" { ] } + statement { + sid = "${local.policy_region_prefix}CrossAccountPutAccess" + effect = "Allow" + actions = [ + "events:PutEvents", + ] + resources = [ + var.event_bus_arn + ] + } + provider = aws.region } diff --git a/terraform/environment/region/modules/event_received/variables.tf b/terraform/environment/region/modules/event_received/variables.tf index 4f577e738b..4527a3a2df 100644 --- a/terraform/environment/region/modules/event_received/variables.tf +++ b/terraform/environment/region/modules/event_received/variables.tf @@ -10,6 +10,10 @@ variable "event_bus_name" { type = string } +variable "event_bus_arn" { + type = string +} + variable "lpas_table" { type = object({ arn = string