mirror of
https://github.com/alexandernicholson/s3panoramic.git
synced 2026-01-31 01:13:03 +09:00
fix: migrate to real xml parser
This commit is contained in:
parent
7bc6533a6b
commit
9809ef2c4d
4
deno.lock
generated
4
deno.lock
generated
@@ -2,11 +2,15 @@
|
||||
"version": "4",
|
||||
"specifiers": {
|
||||
"jsr:@b-fuze/deno-dom@*": "0.1.48",
|
||||
"jsr:@libs/xml@*": "6.0.1",
|
||||
"npm:hono@*": "4.6.10"
|
||||
},
|
||||
"jsr": {
|
||||
"@b-fuze/deno-dom@0.1.48": {
|
||||
"integrity": "bf5b591aef2e9e9c59adfcbb93a9ecd45bab5b7c8263625beafa5c8f1662e7da"
|
||||
},
|
||||
"@libs/xml@6.0.1": {
|
||||
"integrity": "64af4f93464c77c3e1158fb97c3657779ca554b14f38616b96cde31e22d8a309"
|
||||
}
|
||||
},
|
||||
"npm": {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ListObjectsOptions, ListObjectsResult, StorageObject } from "../types/m
|
||||
import { S3, type ListObjectsV2Request } from "https://deno.land/x/aws_api@v0.8.1/services/s3/mod.ts";
|
||||
import { ApiFactory } from "https://deno.land/x/aws_api@v0.8.1/client/mod.ts";
|
||||
import { getSignedUrl } from "https://deno.land/x/aws_s3_presign@2.2.1/mod.ts";
|
||||
import { DOMParser, Element } from "jsr:@b-fuze/deno-dom";
|
||||
import { parse as parseXml } from "jsr:@libs/xml";
|
||||
|
||||
interface Credentials {
|
||||
awsAccessKeyId: string;
|
||||
@@ -174,14 +174,10 @@ export class StorageService {
|
||||
}
|
||||
|
||||
class WebIdentityCredentials {
|
||||
private parser: DOMParser;
|
||||
|
||||
constructor(
|
||||
private roleArn: string,
|
||||
private token: string,
|
||||
) {
|
||||
this.parser = new DOMParser();
|
||||
}
|
||||
) {}
|
||||
|
||||
async getCredentials(): Promise<{ accessKeyId: string; secretAccessKey: string; sessionToken: string }> {
|
||||
const params = new URLSearchParams({
|
||||
@@ -201,20 +197,22 @@ class WebIdentityCredentials {
|
||||
}
|
||||
|
||||
const xml = await response.text();
|
||||
const result = this.parser.parseFromString(xml, "text/xml");
|
||||
if (!result) throw new Error("Failed to parse XML response");
|
||||
const result = parseXml(xml);
|
||||
|
||||
const credentials = result.querySelector("Credentials");
|
||||
if (!credentials) throw new Error("No credentials in response");
|
||||
const credentials = result.AssumeRoleWithWebIdentityResponse?.Result?.Credentials;
|
||||
if (!credentials) {
|
||||
throw new Error("No credentials in response");
|
||||
}
|
||||
|
||||
const accessKeyId = credentials.querySelector("AccessKeyId")?.textContent;
|
||||
const secretAccessKey = credentials.querySelector("SecretAccessKey")?.textContent;
|
||||
const sessionToken = credentials.querySelector("SessionToken")?.textContent;
|
||||
|
||||
if (!accessKeyId || !secretAccessKey || !sessionToken) {
|
||||
const { AccessKeyId, SecretAccessKey, SessionToken } = credentials;
|
||||
if (!AccessKeyId || !SecretAccessKey || !SessionToken) {
|
||||
throw new Error("Missing required credential fields in response");
|
||||
}
|
||||
|
||||
return { accessKeyId, secretAccessKey, sessionToken };
|
||||
return {
|
||||
accessKeyId: AccessKeyId,
|
||||
secretAccessKey: SecretAccessKey,
|
||||
sessionToken: SessionToken,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user