-
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 lambda to create certificate provider
- Loading branch information
Showing
22 changed files
with
751 additions
and
350 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
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
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 |
---|---|---|
|
@@ -26,7 +26,7 @@ func createToken(claims jwt.MapClaims) string { | |
} | ||
|
||
func TestVerifyEmptyJwt(t *testing.T) { | ||
err := verifier.VerifyToken("") | ||
err := verifier.verifyToken("") | ||
assert.NotNil(t, err) | ||
} | ||
|
||
|
@@ -38,7 +38,7 @@ func TestVerifyExpInPast(t *testing.T) { | |
"sub": "M-3467-89QW-ERTY", | ||
}) | ||
|
||
err := verifier.VerifyToken(token) | ||
err := verifier.verifyToken(token) | ||
|
||
assert.NotNil(t, err) | ||
if err != nil { | ||
|
@@ -54,7 +54,7 @@ func TestVerifyIatInFuture(t *testing.T) { | |
"sub": "[email protected]", | ||
}) | ||
|
||
err := verifier.VerifyToken(token) | ||
err := verifier.verifyToken(token) | ||
|
||
assert.NotNil(t, err) | ||
if err != nil { | ||
|
@@ -70,7 +70,7 @@ func TestVerifyIssuer(t *testing.T) { | |
"sub": "[email protected]", | ||
}) | ||
|
||
err := verifier.VerifyToken(token) | ||
err := verifier.verifyToken(token) | ||
|
||
assert.NotNil(t, err) | ||
if err != nil { | ||
|
@@ -86,7 +86,7 @@ func TestVerifyBadEmailForSiriusIssuer(t *testing.T) { | |
"sub": "", | ||
}) | ||
|
||
err := verifier.VerifyToken(token) | ||
err := verifier.verifyToken(token) | ||
|
||
assert.NotNil(t, err) | ||
if err != nil { | ||
|
@@ -102,7 +102,7 @@ func TestVerifyBadUIDForMRLPAIssuer(t *testing.T) { | |
"sub": "", | ||
}) | ||
|
||
err := verifier.VerifyToken(token) | ||
err := verifier.verifyToken(token) | ||
|
||
assert.NotNil(t, err) | ||
if err != nil { | ||
|
@@ -118,7 +118,7 @@ func TestVerifyGoodJwt(t *testing.T) { | |
"sub": "[email protected]", | ||
}) | ||
|
||
err := verifier.VerifyToken(token) | ||
err := verifier.verifyToken(token) | ||
assert.Nil(t, err) | ||
} | ||
|
||
|
@@ -134,7 +134,7 @@ func TestNewJWTVerifier(t *testing.T) { | |
newVerifier := NewJWTVerifier() | ||
os.Unsetenv("JWT_SECRET_KEY") | ||
|
||
err := newVerifier.VerifyToken(token) | ||
err := newVerifier.verifyToken(token) | ||
assert.Nil(t, err) | ||
} | ||
|
||
|
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,12 @@ | ||
package shared | ||
|
||
type Lang string | ||
|
||
var ( | ||
LangCy = Lang("cy") | ||
LangEn = Lang("en") | ||
) | ||
|
||
func (l Lang) IsValid() bool { | ||
return l == LangCy || l == LangEn | ||
} |
Oops, something went wrong.