mirror of
https://github.com/alexandernicholson/s3panoramic.git
synced 2026-03-31 09:07:11 +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",
|
"version": "4",
|
||||||
"specifiers": {
|
"specifiers": {
|
||||||
"jsr:@b-fuze/deno-dom@*": "0.1.48",
|
"jsr:@b-fuze/deno-dom@*": "0.1.48",
|
||||||
|
"jsr:@libs/xml@*": "6.0.1",
|
||||||
"npm:hono@*": "4.6.10"
|
"npm:hono@*": "4.6.10"
|
||||||
},
|
},
|
||||||
"jsr": {
|
"jsr": {
|
||||||
"@b-fuze/deno-dom@0.1.48": {
|
"@b-fuze/deno-dom@0.1.48": {
|
||||||
"integrity": "bf5b591aef2e9e9c59adfcbb93a9ecd45bab5b7c8263625beafa5c8f1662e7da"
|
"integrity": "bf5b591aef2e9e9c59adfcbb93a9ecd45bab5b7c8263625beafa5c8f1662e7da"
|
||||||
|
},
|
||||||
|
"@libs/xml@6.0.1": {
|
||||||
|
"integrity": "64af4f93464c77c3e1158fb97c3657779ca554b14f38616b96cde31e22d8a309"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npm": {
|
"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 { 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 { 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 { 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 {
|
interface Credentials {
|
||||||
awsAccessKeyId: string;
|
awsAccessKeyId: string;
|
||||||
@@ -174,14 +174,10 @@ export class StorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WebIdentityCredentials {
|
class WebIdentityCredentials {
|
||||||
private parser: DOMParser;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private roleArn: string,
|
private roleArn: string,
|
||||||
private token: string,
|
private token: string,
|
||||||
) {
|
) {}
|
||||||
this.parser = new DOMParser();
|
|
||||||
}
|
|
||||||
|
|
||||||
async getCredentials(): Promise<{ accessKeyId: string; secretAccessKey: string; sessionToken: string }> {
|
async getCredentials(): Promise<{ accessKeyId: string; secretAccessKey: string; sessionToken: string }> {
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
@@ -201,20 +197,22 @@ class WebIdentityCredentials {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const xml = await response.text();
|
const xml = await response.text();
|
||||||
const result = this.parser.parseFromString(xml, "text/xml");
|
const result = parseXml(xml);
|
||||||
if (!result) throw new Error("Failed to parse XML response");
|
|
||||||
|
|
||||||
const credentials = result.querySelector("Credentials");
|
const credentials = result.AssumeRoleWithWebIdentityResponse?.Result?.Credentials;
|
||||||
if (!credentials) throw new Error("No credentials in response");
|
if (!credentials) {
|
||||||
|
throw new Error("No credentials in response");
|
||||||
|
}
|
||||||
|
|
||||||
const accessKeyId = credentials.querySelector("AccessKeyId")?.textContent;
|
const { AccessKeyId, SecretAccessKey, SessionToken } = credentials;
|
||||||
const secretAccessKey = credentials.querySelector("SecretAccessKey")?.textContent;
|
if (!AccessKeyId || !SecretAccessKey || !SessionToken) {
|
||||||
const sessionToken = credentials.querySelector("SessionToken")?.textContent;
|
|
||||||
|
|
||||||
if (!accessKeyId || !secretAccessKey || !sessionToken) {
|
|
||||||
throw new Error("Missing required credential fields in response");
|
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