Skip to content

RFC: add signature v4 #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

AMar4enko
Copy link

@AMar4enko AMar4enko commented Mar 8, 2025

This is basic implementation for attaching AWS Signature v4 to HttpClientRequest
Usage example is somewhat along these lines:

import { SignatureV4 }  from '@effect-aws/signature-v4/Aws4Fetch.js'
export class ApiClient extends Effect.Service<ApiClient>()(
  `ApiClient`,
  {
    effect: Effect.gen(function* () {
      const { transformClient } = yield* SignatureV4

      return yield* HttpApiClient.make(Api, {
        baseUrl: ApiBaseUrl,
        transformClient,
      })
    }),
  },
) {}

const Sig4 = SignatureV4.Default.pipe(
  Layer.provide(Credentials.layer(awsCreds))
)

const runtime = ManagedRuntime.make(
  Layer.provide(ApiClient),
  Layer.provide(Sig4),
)

Copy link

changeset-bot bot commented Mar 9, 2025

⚠️ No Changeset found

Latest commit: 4c34768

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@AMar4enko AMar4enko marked this pull request as draft March 9, 2025 17:05
)

export class Credentials extends Context.Tag(`@effect-aws/signature-v4/Credentials`)<Credentials, Ref.Ref<Option.Option<AWSCredentialsRedacted>>>() {
static layer = (credentials?: AWSCredentials) => Layer.effect(Credentials, Ref.make(redactCredentials(credentials)))
Copy link
Owner

Choose a reason for hiding this comment

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

I suggest using layer for normal options and layerConfig for Config wrapped options
it is quite a pattern within ecosystem
See here or here
also I suggest use Redacted creds end to end so you don't need redactCredentials

* 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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants