Update util.ts

This commit is contained in:
Daniel Hougaard
2024-09-23 23:14:26 +04:00
parent 614f7d0afd
commit bf9f20f692

View File

@@ -34,11 +34,20 @@ export const getAwsRegion = async () => {
export const performAwsIamLogin = async (baseUrl: string, identityId: string, region: string) => { export const performAwsIamLogin = async (baseUrl: string, identityId: string, region: string) => {
const body = "Action=GetCallerIdentity&Version=2011-06-15"; const body = "Action=GetCallerIdentity&Version=2011-06-15";
AWS.config.update({ const creds = await new Promise<{ sessionToken?: string; accessKeyId: string; secretAccessKey: string }>((resolve, reject) => {
region: region AWS.config.getCredentials((err, res) => {
if (err) {
throw err;
} else {
if (!res) {
throw new Error("Credentials not found");
}
return resolve(res);
}
});
}); });
console.log("creds", AWS.config.credentials); console.log("creds", creds);
const signOpts = aws4.sign( const signOpts = aws4.sign(
{ {
@@ -47,8 +56,8 @@ export const performAwsIamLogin = async (baseUrl: string, identityId: string, re
region region
}, },
{ {
accessKeyId: AWS.config.credentials?.accessKeyId, accessKeyId: creds.accessKeyId,
secretAccessKey: AWS.config.credentials?.secretAccessKey secretAccessKey: creds.secretAccessKey
} }
); );