Skip to content

Commit

Permalink
chore(credential-providers): unavailable browser credential providers…
Browse files Browse the repository at this point in the history
… throw at runtime
  • Loading branch information
kuhe committed Mar 1, 2024
1 parent 3a82d4c commit 0de968e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/credential-providers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,7 @@ See [`fromSSO()`](#fromsso) fro more information

## `fromEnv()`

- Not available in browser & native apps unless your code or bundler populates the
`process.env` global object.
- Not available in browser & native apps

```javascript
import { fromEnv } from "@aws-sdk/credential-providers"; // ES6 import
Expand Down
3 changes: 0 additions & 3 deletions packages/credential-providers/src/fromEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,5 @@ import { AwsCredentialIdentityProvider } from "@smithy/types";
* credentials: fromEnv(),
* });
* ```
*
* To use this in non-Node.js environments such as a browser, your code or
* build system must populate the `process.env` global object.
*/
export const fromEnv = (init?: FromEnvInit): AwsCredentialIdentityProvider => _fromEnv(init);
43 changes: 42 additions & 1 deletion packages/credential-providers/src/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@ export * from "./fromCognitoIdentity";
export * from "./fromCognitoIdentityPool";
export { fromHttp } from "@aws-sdk/credential-provider-http";
export type { FromHttpOptions, HttpProviderCredentials } from "@aws-sdk/credential-provider-http";
export * from "./fromEnv";
export * from "./fromTemporaryCredentials";
export * from "./fromWebToken";

export const fromContainerMetadata = async () => {
notAvailable("fromContainerMetadata");
};

export const fromEnv = async () => {
notAvailable("fromEnv");
};

export const fromIni = async () => {
notAvailable("fromIni");
};

export const fromInstanceMetadata = async () => {
notAvailable("fromInstanceMetadata");
};

export const fromNodeProviderChain = async () => {
notAvailable("fromNodeProviderChain");
};

export const fromProcess = async () => {
notAvailable("fromProcess");
};

export const fromSSO = async () => {
notAvailable("fromSSO");
};

export const fromTokenFile = async () => {
notAvailable("fromTokenFile");
};

/**
* @internal
*/
const notAvailable = (name: string): never => {
throw new Error(
`${name} is not available in the browser mode or similar environment.
See https://www.npmjs.com/package/@aws-sdk/credential-providers for usage.`
);
};

0 comments on commit 0de968e

Please sign in to comment.