-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add update for when certificate provider signs
- Loading branch information
Showing
23 changed files
with
854 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ddb | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/dynamodb" | ||
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute" | ||
"github.com/aws/aws-xray-sdk-go/xray" | ||
"github.com/ministryofjustice/opg-data-lpa-store/internal/shared" | ||
) | ||
|
||
type Client struct { | ||
ddb *dynamodb.DynamoDB | ||
tableName string | ||
} | ||
|
||
func (c *Client) Put(ctx context.Context, data any) error { | ||
item, err := dynamodbattribute.MarshalMap(data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.ddb.PutItemWithContext(ctx, &dynamodb.PutItemInput{ | ||
TableName: aws.String(c.tableName), | ||
Item: item, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (c *Client) Get(ctx context.Context, uid string) (shared.Lpa, error) { | ||
lpa := shared.Lpa{} | ||
|
||
marshalledUid, err := dynamodbattribute.Marshal(uid) | ||
if err != nil { | ||
return lpa, err | ||
} | ||
|
||
getItemOutput, err := c.ddb.GetItemWithContext(ctx, &dynamodb.GetItemInput{ | ||
TableName: aws.String(c.tableName), | ||
Key: map[string]*dynamodb.AttributeValue{ | ||
"uid": marshalledUid, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return lpa, err | ||
} | ||
|
||
err = dynamodbattribute.UnmarshalMap(getItemOutput.Item, &lpa) | ||
|
||
return lpa, err | ||
} | ||
|
||
func New(endpoint, tableName string) *Client { | ||
sess := session.Must(session.NewSession()) | ||
sess.Config.Endpoint = &endpoint | ||
|
||
c := &Client{ | ||
ddb: dynamodb.New(sess), | ||
tableName: tableName, | ||
} | ||
|
||
xray.AWS(c.ddb.Client) | ||
|
||
return c | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1 @@ | ||
package shared | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/dynamodb" | ||
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute" | ||
"github.com/aws/aws-xray-sdk-go/xray" | ||
) | ||
|
||
type DynamoDBClient struct { | ||
ddb *dynamodb.DynamoDB | ||
tableName string | ||
} | ||
|
||
func (c DynamoDBClient) Put(ctx context.Context, data Lpa) error { | ||
item, err := dynamodbattribute.MarshalMap(data) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = c.ddb.PutItemWithContext(ctx, &dynamodb.PutItemInput{ | ||
TableName: aws.String(c.tableName), | ||
Item: item, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (c DynamoDBClient) Get(ctx context.Context, uid string) (Lpa, error) { | ||
lpa := Lpa{} | ||
|
||
marshalledUid, err := dynamodbattribute.Marshal(uid) | ||
if err != nil { | ||
return lpa, err | ||
} | ||
|
||
getItemOutput, err := c.ddb.GetItemWithContext(ctx, &dynamodb.GetItemInput{ | ||
TableName: aws.String(c.tableName), | ||
Key: map[string]*dynamodb.AttributeValue{ | ||
"uid": marshalledUid, | ||
}, | ||
}) | ||
|
||
if err != nil { | ||
return lpa, err | ||
} | ||
|
||
err = dynamodbattribute.UnmarshalMap(getItemOutput.Item, &lpa) | ||
|
||
return lpa, err | ||
} | ||
|
||
func NewDynamoDB(tableName string) DynamoDBClient { | ||
sess := session.Must(session.NewSession()) | ||
|
||
endpoint := os.Getenv("AWS_DYNAMODB_ENDPOINT") | ||
sess.Config.Endpoint = &endpoint | ||
|
||
c := DynamoDBClient{ | ||
ddb: dynamodb.New(sess), | ||
tableName: tableName, | ||
} | ||
|
||
xray.AWS(c.ddb.Client) | ||
|
||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.