-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): support for CustomEmailSender
- Loading branch information
Showing
19 changed files
with
1,230 additions
and
433 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ describe( | |
const createUserResult = await client | ||
.adminCreateUser({ | ||
UserAttributes: [{ Name: "phone_number", Value: "0400000000" }], | ||
Username: "abc", | ||
Username: "[email protected]", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
@@ -31,12 +31,13 @@ describe( | |
Value: expect.stringMatching(UUID), | ||
}, | ||
{ Name: "phone_number", Value: "0400000000" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
], | ||
Enabled: true, | ||
UserCreateDate: roundedDate, | ||
UserLastModifiedDate: roundedDate, | ||
UserStatus: "FORCE_CHANGE_PASSWORD", | ||
Username: "abc", | ||
Username: "[email protected]", | ||
}, | ||
}); | ||
}); | ||
|
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
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,58 @@ | ||
import { | ||
buildClient, | ||
CommitmentPolicy, | ||
KmsKeyringNode, | ||
} from "@aws-crypto/client-node"; | ||
import { KMS } from "aws-sdk"; | ||
import { Context } from "./context"; | ||
|
||
export interface KMSConfig { | ||
KMSKeyId?: string; | ||
KMSKeyAlias?: string; | ||
} | ||
|
||
const { encrypt } = buildClient(CommitmentPolicy.REQUIRE_ENCRYPT_ALLOW_DECRYPT); | ||
|
||
export class CryptoService { | ||
_keyringNode?: KmsKeyringNode; | ||
config?: KMSConfig & AWS.KMS.ClientConfiguration; | ||
|
||
constructor(config?: KMSConfig) { | ||
this.config = config; | ||
} | ||
|
||
get keyringNode(): KmsKeyringNode { | ||
if (this._keyringNode) { | ||
return this._keyringNode; | ||
} | ||
|
||
if (!this.config || !this.config.KMSKeyAlias || !this.config.KMSKeyId) { | ||
throw new Error( | ||
"KMSConfig.KMSKeyAlias and KMSConfig.KMSKeyId is required when using a CustomEmailSender trigger." | ||
); | ||
} | ||
|
||
const { KMSKeyId, KMSKeyAlias, ...clientConfig } = this.config; | ||
|
||
const generatorKeyId = KMSKeyAlias; | ||
const keyIds = [KMSKeyId]; | ||
|
||
return (this._keyringNode = new KmsKeyringNode({ | ||
generatorKeyId, | ||
keyIds, | ||
clientProvider: () => new KMS(clientConfig), | ||
})); | ||
} | ||
|
||
async encrypt(ctx: Context, plaintext: string): Promise<string> { | ||
ctx.logger.debug({ plaintext }, "encrypting code"); | ||
|
||
const { result } = await encrypt(this.keyringNode, plaintext); | ||
|
||
const encryptedCode = result.toString("base64"); | ||
|
||
ctx.logger.debug({ encryptedCode }, "code succesfully encrypted"); | ||
|
||
return encryptedCode; | ||
} | ||
} |
Oops, something went wrong.