Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ new TypeScriptLibProject({
workspacePeerDeps: [secretsManagerClient],
});

const proj = new TypeScriptLibProject({
parent: project,
name: "signature-v4",
description: "AWS Signature V4 for Effect HttpClientRequest",
peerDeps: [...commonPeerDeps, "@smithy/signature-v4@^5", "@smithy/types@^4", "aws4fetch@^1", "@aws-crypto/sha256-js@^5"]
});


proj.addFields({
peerDependenciesMeta: {
'@smithy/signature-v4': { optional: true },
'@smithy/types': { optional: true },
'aws4fetch': { optional: true },
'@aws-crypto/sha256-js': { optional: true },
}
})

new TypeScriptLibProject({
parent: project,
name: "ssm",
Expand Down
21 changes: 21 additions & 0 deletions packages/signature-v4/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions packages/signature-v4/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions packages/signature-v4/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions packages/signature-v4/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions packages/signature-v4/.projen/files.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 120 additions & 0 deletions packages/signature-v4/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions packages/signature-v4/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions packages/signature-v4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## Installation

```bash
npm install --save @effect-aws/signature-v4
```

_Note_: depending on the chosen implementation either `aws4fetch` or `@smithy/signature-v4` dependency is required

## Usage

1. Let's start with creating AWS credentials layer.
Credentials have type `Ref<Option<AWSCredentials>>`, making it possible to update it's value at any moment during app lifetime

```typescript
import { Credentials } from '@effect-aws/signature-v4/Credentials'
import awsCredentials from './credentials.ts'


const CredentialsLayer = Credentials.layer(awsCredentials)

/**
* We can access or modify credentials directly from within our Effect app like this
*
*/
Effect.gen(function* () {
/**
* Get credentials
*/
const credentials: Option<AWSCredentials> = yield* Credentials.pipe(
Effect.andThen(Ref.get)
)
/**
* Populate credentials with new value
*/
yield* Credentials.pipe(
Effect.andThen(Ref.set(Option.some(newCredentials)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you clarify why do you need Ref
I feel like using Ref with Layer is a bit off, it makes it impure.
I would rather use the globalValue and 2 functions: withCredentials and setCredentials (hof and setter). see example here, however global value strips Credentials as dependency and requires default value, which suits well if you use shell aws config or sso...

)

// or via handy API
const credentials = yield* Credentials.current
yield* Credentials.update(newCredentials)
}).pipe(
Effect.provide(CredentialsLayer)
)
```

_Note_: secretAccessKey and sessionToken credentials values are wrapped with `Redacted`

2. Use signer of choice to sign HttpClientRequest
```typescript
import { SignatureV4 } from '@effect-aws/signature-v4/Smithy'
// or
import { SignatureV4 } from '@effect-aws/signature-v4/Aws4Fetch'
```

_Note_: avoid importing an implementation via barrel-import due to different set of peer dependencies

```typescript
const SigV4 = SignatureV4.Default.pipe(
Effect.provideMerge(CredentialsLayer) // or Effect.provide if you're not planning to access credentials directly in your code
)

Effect.gen(function* () {
// you got a hold of an HttpClientRequest
const signedRequest = yield* SignatureV4.signRequest(request)

// or use transformClient to modify and HttpClient to automatically sign requests

const { transformClient } = yield* SignatureV4

const apiClient = yield* HttpApiClient.make(Api, {
baseUrl,
transformClient,
})
}).pipe(
Layer.provide(SigV4)
)
```
Loading