|
1 | 1 | import { type AWSCredentials, getAwsCredentialProvider } from '../../deps';
|
2 | 2 | import { MongoAWSError } from '../../error';
|
3 |
| -import { request } from '../../utils'; |
4 |
| - |
5 |
| -const AWS_RELATIVE_URI = 'http://169.254.170.2'; |
6 |
| -const AWS_EC2_URI = 'http://169.254.169.254'; |
7 |
| -const AWS_EC2_PATH = '/latest/meta-data/iam/security-credentials'; |
8 | 3 |
|
9 | 4 | /**
|
10 | 5 | * @internal
|
@@ -32,7 +27,7 @@ export type AWSCredentialProvider = () => Promise<AWSCredentials>;
|
32 | 27 | export abstract class AWSTemporaryCredentialProvider {
|
33 | 28 | abstract getCredentials(): Promise<AWSTempCredentials>;
|
34 | 29 | private static _awsSDK: ReturnType<typeof getAwsCredentialProvider>;
|
35 |
| - protected static get awsSDK() { |
| 30 | + static get awsSDK() { |
36 | 31 | AWSTemporaryCredentialProvider._awsSDK ??= getAwsCredentialProvider();
|
37 | 32 | return AWSTemporaryCredentialProvider._awsSDK;
|
38 | 33 | }
|
@@ -144,42 +139,3 @@ export class AWSSDKCredentialProvider extends AWSTemporaryCredentialProvider {
|
144 | 139 | }
|
145 | 140 | }
|
146 | 141 | }
|
147 |
| - |
148 |
| -/** |
149 |
| - * @internal |
150 |
| - * Fetches credentials manually (without the AWS SDK), as outlined in the [Obtaining Credentials](https://github.com/mongodb/specifications/blob/master/source/auth/auth.md#obtaining-credentials) |
151 |
| - * section of the Auth spec. |
152 |
| - */ |
153 |
| -export class LegacyAWSTemporaryCredentialProvider extends AWSTemporaryCredentialProvider { |
154 |
| - override async getCredentials(): Promise<AWSTempCredentials> { |
155 |
| - // If the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI |
156 |
| - // is set then drivers MUST assume that it was set by an AWS ECS agent |
157 |
| - if (process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI) { |
158 |
| - return await request( |
159 |
| - `${AWS_RELATIVE_URI}${process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}` |
160 |
| - ); |
161 |
| - } |
162 |
| - |
163 |
| - // Otherwise assume we are on an EC2 instance |
164 |
| - |
165 |
| - // get a token |
166 |
| - const token = await request(`${AWS_EC2_URI}/latest/api/token`, { |
167 |
| - method: 'PUT', |
168 |
| - json: false, |
169 |
| - headers: { 'X-aws-ec2-metadata-token-ttl-seconds': 30 } |
170 |
| - }); |
171 |
| - |
172 |
| - // get role name |
173 |
| - const roleName = await request(`${AWS_EC2_URI}/${AWS_EC2_PATH}`, { |
174 |
| - json: false, |
175 |
| - headers: { 'X-aws-ec2-metadata-token': token } |
176 |
| - }); |
177 |
| - |
178 |
| - // get temp credentials |
179 |
| - const creds = await request(`${AWS_EC2_URI}/${AWS_EC2_PATH}/${roleName}`, { |
180 |
| - headers: { 'X-aws-ec2-metadata-token': token } |
181 |
| - }); |
182 |
| - |
183 |
| - return creds; |
184 |
| - } |
185 |
| -} |
0 commit comments