fix: 修复配额说明重复和undefined问题
- 在editStorageForm中初始化oss_storage_quota_value和oss_quota_unit - 删除重复的旧配额说明块,保留新的当前配额设置显示 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
201
backend/node_modules/@aws-sdk/s3-request-presigner/LICENSE
generated
vendored
Normal file
201
backend/node_modules/@aws-sdk/s3-request-presigner/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
125
backend/node_modules/@aws-sdk/s3-request-presigner/README.md
generated
vendored
Normal file
125
backend/node_modules/@aws-sdk/s3-request-presigner/README.md
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
# @aws-sdk/s3-request-presigner
|
||||
|
||||
[](https://www.npmjs.com/package/@aws-sdk/s3-request-presigner)
|
||||
[](https://www.npmjs.com/package/@aws-sdk/s3-request-presigner)
|
||||
|
||||
This package provides a presigner based on signature V4 that will attempt to
|
||||
generate signed url for S3.
|
||||
|
||||
### Get Presigned URL with Client and Command
|
||||
|
||||
You can generated presigned url from S3 client and command. Here's the example:
|
||||
|
||||
```javascript
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
|
||||
const client = new S3Client(clientParams);
|
||||
const command = new GetObjectCommand(getObjectParams);
|
||||
const url = await getSignedUrl(client, command, { expiresIn: 3600 });
|
||||
```
|
||||
|
||||
You can get signed URL for other S3 operations too, like `PutObjectCommand`.
|
||||
`expiresIn` config from the examples above is optional. If not set, it's default
|
||||
at `900`.
|
||||
|
||||
If you already have a request, you can pre-sign the request following the
|
||||
section bellow.
|
||||
|
||||
### Get Presigned URL from an Existing Request
|
||||
|
||||
```javascript
|
||||
import { S3RequestPresigner } from "@aws-sdk/s3-request-presigner";
|
||||
import { Sha256 } from "@aws-crypto/sha256-browser";
|
||||
import { Hash } from "@aws-sdk/hash-node";
|
||||
const signer = new S3RequestPresigner({
|
||||
region: regionProvider,
|
||||
credentials: credentialsProvider,
|
||||
sha256: Hash.bind(null, "sha256"), // In Node.js
|
||||
//sha256: Sha256 // In browsers
|
||||
});
|
||||
const presigned = await signer.presign(request);
|
||||
```
|
||||
|
||||
To avoid redundant construction parameters when instantiating the s3 presigner,
|
||||
you can simply spread the configuration of an existing s3 client and supply it to
|
||||
the presigner's constructor.
|
||||
|
||||
```javascript
|
||||
//s3 is instantiated from S3Client from @aws-sdk/client-s3-* packages
|
||||
const signer = new S3RequestPresigner({
|
||||
...s3.config,
|
||||
});
|
||||
```
|
||||
|
||||
### Get Presigned URL with headers that cannot be signed
|
||||
|
||||
By using the `getSignedUrl` with a `S3Client` you are able to sign your
|
||||
headers, improving the security of presigned url. Importantly, if you want to
|
||||
sign any `x-amz-*` headers (like the ChecksumSHA256 header in this example),
|
||||
you need to provide those headers to the set of `unhoistableHeaders` in the
|
||||
`getSignedUrl` params which will force those headers to be present in the
|
||||
upload request.
|
||||
|
||||
```javascript
|
||||
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||
|
||||
const s3Client = new S3Client({ region: "us-east-1" });
|
||||
const command = new PutObjectCommand({
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
ChecksumSHA256: sha,
|
||||
});
|
||||
|
||||
const presigned = getSignedUrl(s3Client, command, {
|
||||
expiresIn: expiration,
|
||||
// Set of all x-amz-* headers you wish to have signed
|
||||
unhoistableHeaders: new Set(["x-amz-checksum-sha256"]),
|
||||
});
|
||||
```
|
||||
|
||||
### Get Presigned URL with headers that should be signed
|
||||
|
||||
For headers that are not `x-amz-*` you are able to add them to the set of
|
||||
`signableHeaders` to be enforced in the presigned urls request.
|
||||
|
||||
```javascript
|
||||
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||
|
||||
const s3Client = new S3Client({ region: "us-east-1" });
|
||||
const command = new PutObjectCommand({
|
||||
Bucket: bucket,
|
||||
Key: key,
|
||||
ContentType: contentType,
|
||||
});
|
||||
|
||||
const presigned = getSignedUrl(s3Client, command, {
|
||||
signableHeaders: new Set(["content-type"]),
|
||||
expiresIn: expiration,
|
||||
});
|
||||
```
|
||||
|
||||
### PutObject with use of `hoistableHeaders`
|
||||
|
||||
`hoistableHeaders` overrides the default behavior of not hoisting
|
||||
any headers that begin with `x-amz-*`.
|
||||
|
||||
```js
|
||||
// example: Server Side Encryption headers
|
||||
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
||||
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
|
||||
|
||||
const params = {
|
||||
Key: "...",
|
||||
Bucket: "...",
|
||||
ServerSideEncryption: "aws:kms",
|
||||
SSEKMSKeyId: "arn:aws:kms:us-west-2:0000:key/abcd-1234-abcd",
|
||||
};
|
||||
const s3Client = new S3Client();
|
||||
const command = new PutObjectCommand(params);
|
||||
|
||||
const preSignedUrl = await getSignedUrl(s3Client, command, {
|
||||
hoistableHeaders: new Set(["x-amz-server-side-encryption", "x-amz-server-side-encryption-aws-kms-key-id"]),
|
||||
});
|
||||
```
|
||||
132
backend/node_modules/@aws-sdk/s3-request-presigner/dist-cjs/index.js
generated
vendored
Normal file
132
backend/node_modules/@aws-sdk/s3-request-presigner/dist-cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
'use strict';
|
||||
|
||||
var utilFormatUrl = require('@aws-sdk/util-format-url');
|
||||
var middlewareEndpoint = require('@smithy/middleware-endpoint');
|
||||
var protocolHttp = require('@smithy/protocol-http');
|
||||
var signatureV4MultiRegion = require('@aws-sdk/signature-v4-multi-region');
|
||||
|
||||
const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
|
||||
const SHA256_HEADER = "X-Amz-Content-Sha256";
|
||||
|
||||
class S3RequestPresigner {
|
||||
signer;
|
||||
constructor(options) {
|
||||
const resolvedOptions = {
|
||||
service: options.signingName || options.service || "s3",
|
||||
uriEscapePath: options.uriEscapePath || false,
|
||||
applyChecksum: options.applyChecksum || false,
|
||||
...options,
|
||||
};
|
||||
this.signer = new signatureV4MultiRegion.SignatureV4MultiRegion(resolvedOptions);
|
||||
}
|
||||
presign(requestToSign, { unsignableHeaders = new Set(), hoistableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
|
||||
this.prepareRequest(requestToSign, {
|
||||
unsignableHeaders,
|
||||
unhoistableHeaders,
|
||||
hoistableHeaders,
|
||||
});
|
||||
return this.signer.presign(requestToSign, {
|
||||
expiresIn: 900,
|
||||
unsignableHeaders,
|
||||
unhoistableHeaders,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
presignWithCredentials(requestToSign, credentials, { unsignableHeaders = new Set(), hoistableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
|
||||
this.prepareRequest(requestToSign, {
|
||||
unsignableHeaders,
|
||||
unhoistableHeaders,
|
||||
hoistableHeaders,
|
||||
});
|
||||
return this.signer.presignWithCredentials(requestToSign, credentials, {
|
||||
expiresIn: 900,
|
||||
unsignableHeaders,
|
||||
unhoistableHeaders,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
prepareRequest(requestToSign, { unsignableHeaders = new Set(), unhoistableHeaders = new Set(), hoistableHeaders = new Set(), } = {}) {
|
||||
unsignableHeaders.add("content-type");
|
||||
Object.keys(requestToSign.headers)
|
||||
.map((header) => header.toLowerCase())
|
||||
.filter((header) => header.startsWith("x-amz-server-side-encryption"))
|
||||
.forEach((header) => {
|
||||
if (!hoistableHeaders.has(header)) {
|
||||
unhoistableHeaders.add(header);
|
||||
}
|
||||
});
|
||||
requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
|
||||
const currentHostHeader = requestToSign.headers.host;
|
||||
const port = requestToSign.port;
|
||||
const expectedHostHeader = `${requestToSign.hostname}${requestToSign.port != null ? ":" + port : ""}`;
|
||||
if (!currentHostHeader || (currentHostHeader === requestToSign.hostname && requestToSign.port != null)) {
|
||||
requestToSign.headers.host = expectedHostHeader;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getSignedUrl = async (client, command, options = {}) => {
|
||||
let s3Presigner;
|
||||
let region;
|
||||
if (typeof client.config.endpointProvider === "function") {
|
||||
const endpointV2 = await middlewareEndpoint.getEndpointFromInstructions(command.input, command.constructor, client.config);
|
||||
const authScheme = endpointV2.properties?.authSchemes?.[0];
|
||||
if (authScheme?.name === "sigv4a") {
|
||||
region = authScheme?.signingRegionSet?.join(",");
|
||||
}
|
||||
else {
|
||||
region = authScheme?.signingRegion;
|
||||
}
|
||||
s3Presigner = new S3RequestPresigner({
|
||||
...client.config,
|
||||
signingName: authScheme?.signingName,
|
||||
region: async () => region,
|
||||
});
|
||||
}
|
||||
else {
|
||||
s3Presigner = new S3RequestPresigner(client.config);
|
||||
}
|
||||
const presignInterceptMiddleware = (next, context) => async (args) => {
|
||||
const { request } = args;
|
||||
if (!protocolHttp.HttpRequest.isInstance(request)) {
|
||||
throw new Error("Request to be presigned is not an valid HTTP request.");
|
||||
}
|
||||
delete request.headers["amz-sdk-invocation-id"];
|
||||
delete request.headers["amz-sdk-request"];
|
||||
delete request.headers["x-amz-user-agent"];
|
||||
let presigned;
|
||||
const presignerOptions = {
|
||||
...options,
|
||||
signingRegion: options.signingRegion ?? context["signing_region"] ?? region,
|
||||
signingService: options.signingService ?? context["signing_service"],
|
||||
};
|
||||
if (context.s3ExpressIdentity) {
|
||||
presigned = await s3Presigner.presignWithCredentials(request, context.s3ExpressIdentity, presignerOptions);
|
||||
}
|
||||
else {
|
||||
presigned = await s3Presigner.presign(request, presignerOptions);
|
||||
}
|
||||
return {
|
||||
response: {},
|
||||
output: {
|
||||
$metadata: { httpStatusCode: 200 },
|
||||
presigned,
|
||||
},
|
||||
};
|
||||
};
|
||||
const middlewareName = "presignInterceptMiddleware";
|
||||
const clientStack = client.middlewareStack.clone();
|
||||
clientStack.addRelativeTo(presignInterceptMiddleware, {
|
||||
name: middlewareName,
|
||||
relation: "before",
|
||||
toMiddleware: "awsAuthMiddleware",
|
||||
override: true,
|
||||
});
|
||||
const handler = command.resolveMiddleware(clientStack, client.config, {});
|
||||
const { output } = await handler({ input: command.input });
|
||||
const { presigned } = output;
|
||||
return utilFormatUrl.formatUrl(presigned);
|
||||
};
|
||||
|
||||
exports.S3RequestPresigner = S3RequestPresigner;
|
||||
exports.getSignedUrl = getSignedUrl;
|
||||
9
backend/node_modules/@aws-sdk/s3-request-presigner/dist-es/constants.js
generated
vendored
Normal file
9
backend/node_modules/@aws-sdk/s3-request-presigner/dist-es/constants.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
|
||||
export const SHA256_HEADER = "X-Amz-Content-Sha256";
|
||||
export const ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
|
||||
export const CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
|
||||
export const AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
|
||||
export const SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
|
||||
export const EXPIRES_QUERY_PARAM = "X-Amz-Expires";
|
||||
export const HOST_HEADER = "host";
|
||||
export const ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
|
||||
66
backend/node_modules/@aws-sdk/s3-request-presigner/dist-es/getSignedUrl.js
generated
vendored
Normal file
66
backend/node_modules/@aws-sdk/s3-request-presigner/dist-es/getSignedUrl.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
import { formatUrl } from "@aws-sdk/util-format-url";
|
||||
import { getEndpointFromInstructions } from "@smithy/middleware-endpoint";
|
||||
import { HttpRequest } from "@smithy/protocol-http";
|
||||
import { S3RequestPresigner } from "./presigner";
|
||||
export const getSignedUrl = async (client, command, options = {}) => {
|
||||
let s3Presigner;
|
||||
let region;
|
||||
if (typeof client.config.endpointProvider === "function") {
|
||||
const endpointV2 = await getEndpointFromInstructions(command.input, command.constructor, client.config);
|
||||
const authScheme = endpointV2.properties?.authSchemes?.[0];
|
||||
if (authScheme?.name === "sigv4a") {
|
||||
region = authScheme?.signingRegionSet?.join(",");
|
||||
}
|
||||
else {
|
||||
region = authScheme?.signingRegion;
|
||||
}
|
||||
s3Presigner = new S3RequestPresigner({
|
||||
...client.config,
|
||||
signingName: authScheme?.signingName,
|
||||
region: async () => region,
|
||||
});
|
||||
}
|
||||
else {
|
||||
s3Presigner = new S3RequestPresigner(client.config);
|
||||
}
|
||||
const presignInterceptMiddleware = (next, context) => async (args) => {
|
||||
const { request } = args;
|
||||
if (!HttpRequest.isInstance(request)) {
|
||||
throw new Error("Request to be presigned is not an valid HTTP request.");
|
||||
}
|
||||
delete request.headers["amz-sdk-invocation-id"];
|
||||
delete request.headers["amz-sdk-request"];
|
||||
delete request.headers["x-amz-user-agent"];
|
||||
let presigned;
|
||||
const presignerOptions = {
|
||||
...options,
|
||||
signingRegion: options.signingRegion ?? context["signing_region"] ?? region,
|
||||
signingService: options.signingService ?? context["signing_service"],
|
||||
};
|
||||
if (context.s3ExpressIdentity) {
|
||||
presigned = await s3Presigner.presignWithCredentials(request, context.s3ExpressIdentity, presignerOptions);
|
||||
}
|
||||
else {
|
||||
presigned = await s3Presigner.presign(request, presignerOptions);
|
||||
}
|
||||
return {
|
||||
response: {},
|
||||
output: {
|
||||
$metadata: { httpStatusCode: 200 },
|
||||
presigned,
|
||||
},
|
||||
};
|
||||
};
|
||||
const middlewareName = "presignInterceptMiddleware";
|
||||
const clientStack = client.middlewareStack.clone();
|
||||
clientStack.addRelativeTo(presignInterceptMiddleware, {
|
||||
name: middlewareName,
|
||||
relation: "before",
|
||||
toMiddleware: "awsAuthMiddleware",
|
||||
override: true,
|
||||
});
|
||||
const handler = command.resolveMiddleware(clientStack, client.config, {});
|
||||
const { output } = await handler({ input: command.input });
|
||||
const { presigned } = output;
|
||||
return formatUrl(presigned);
|
||||
};
|
||||
2
backend/node_modules/@aws-sdk/s3-request-presigner/dist-es/index.js
generated
vendored
Normal file
2
backend/node_modules/@aws-sdk/s3-request-presigner/dist-es/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./getSignedUrl";
|
||||
export * from "./presigner";
|
||||
58
backend/node_modules/@aws-sdk/s3-request-presigner/dist-es/presigner.js
generated
vendored
Normal file
58
backend/node_modules/@aws-sdk/s3-request-presigner/dist-es/presigner.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
import { SignatureV4MultiRegion } from "@aws-sdk/signature-v4-multi-region";
|
||||
import { SHA256_HEADER, UNSIGNED_PAYLOAD } from "./constants";
|
||||
export class S3RequestPresigner {
|
||||
signer;
|
||||
constructor(options) {
|
||||
const resolvedOptions = {
|
||||
service: options.signingName || options.service || "s3",
|
||||
uriEscapePath: options.uriEscapePath || false,
|
||||
applyChecksum: options.applyChecksum || false,
|
||||
...options,
|
||||
};
|
||||
this.signer = new SignatureV4MultiRegion(resolvedOptions);
|
||||
}
|
||||
presign(requestToSign, { unsignableHeaders = new Set(), hoistableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
|
||||
this.prepareRequest(requestToSign, {
|
||||
unsignableHeaders,
|
||||
unhoistableHeaders,
|
||||
hoistableHeaders,
|
||||
});
|
||||
return this.signer.presign(requestToSign, {
|
||||
expiresIn: 900,
|
||||
unsignableHeaders,
|
||||
unhoistableHeaders,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
presignWithCredentials(requestToSign, credentials, { unsignableHeaders = new Set(), hoistableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
|
||||
this.prepareRequest(requestToSign, {
|
||||
unsignableHeaders,
|
||||
unhoistableHeaders,
|
||||
hoistableHeaders,
|
||||
});
|
||||
return this.signer.presignWithCredentials(requestToSign, credentials, {
|
||||
expiresIn: 900,
|
||||
unsignableHeaders,
|
||||
unhoistableHeaders,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
prepareRequest(requestToSign, { unsignableHeaders = new Set(), unhoistableHeaders = new Set(), hoistableHeaders = new Set(), } = {}) {
|
||||
unsignableHeaders.add("content-type");
|
||||
Object.keys(requestToSign.headers)
|
||||
.map((header) => header.toLowerCase())
|
||||
.filter((header) => header.startsWith("x-amz-server-side-encryption"))
|
||||
.forEach((header) => {
|
||||
if (!hoistableHeaders.has(header)) {
|
||||
unhoistableHeaders.add(header);
|
||||
}
|
||||
});
|
||||
requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
|
||||
const currentHostHeader = requestToSign.headers.host;
|
||||
const port = requestToSign.port;
|
||||
const expectedHostHeader = `${requestToSign.hostname}${requestToSign.port != null ? ":" + port : ""}`;
|
||||
if (!currentHostHeader || (currentHostHeader === requestToSign.hostname && requestToSign.port != null)) {
|
||||
requestToSign.headers.host = expectedHostHeader;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/constants.d.ts
generated
vendored
Normal file
9
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/constants.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export declare const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
|
||||
export declare const SHA256_HEADER = "X-Amz-Content-Sha256";
|
||||
export declare const ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
|
||||
export declare const CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
|
||||
export declare const AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
|
||||
export declare const SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
|
||||
export declare const EXPIRES_QUERY_PARAM = "X-Amz-Expires";
|
||||
export declare const HOST_HEADER = "host";
|
||||
export declare const ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
|
||||
6
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/getSignedUrl.d.ts
generated
vendored
Normal file
6
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/getSignedUrl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Client, Command } from "@smithy/smithy-client";
|
||||
import { MetadataBearer, RequestPresigningArguments } from "@smithy/types";
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare const getSignedUrl: <InputTypesUnion extends object, InputType extends InputTypesUnion, OutputType extends MetadataBearer = MetadataBearer>(client: Client<any, InputTypesUnion, MetadataBearer, any>, command: Command<InputType, OutputType, any, InputTypesUnion, MetadataBearer>, options?: RequestPresigningArguments) => Promise<string>;
|
||||
2
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/index.d.ts
generated
vendored
Normal file
2
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./getSignedUrl";
|
||||
export * from "./presigner";
|
||||
15
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/presigner.d.ts
generated
vendored
Normal file
15
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/presigner.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { SignatureV4MultiRegionInit } from "@aws-sdk/signature-v4-multi-region";
|
||||
import { AwsCredentialIdentity, RequestPresigner, RequestPresigningArguments } from "@smithy/types";
|
||||
import { HttpRequest as IHttpRequest } from "@smithy/types";
|
||||
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
||||
export type S3RequestPresignerOptions = PartialBy<SignatureV4MultiRegionInit, "service" | "uriEscapePath"> & {
|
||||
signingName?: string;
|
||||
};
|
||||
export declare class S3RequestPresigner implements RequestPresigner {
|
||||
private readonly signer;
|
||||
constructor(options: S3RequestPresignerOptions);
|
||||
presign(requestToSign: IHttpRequest, { unsignableHeaders, hoistableHeaders, unhoistableHeaders, ...options }?: RequestPresigningArguments): Promise<IHttpRequest>;
|
||||
presignWithCredentials(requestToSign: IHttpRequest, credentials: AwsCredentialIdentity, { unsignableHeaders, hoistableHeaders, unhoistableHeaders, ...options }?: RequestPresigningArguments): Promise<IHttpRequest>;
|
||||
private prepareRequest;
|
||||
}
|
||||
export {};
|
||||
9
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/ts3.4/constants.d.ts
generated
vendored
Normal file
9
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/ts3.4/constants.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export declare const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
|
||||
export declare const SHA256_HEADER = "X-Amz-Content-Sha256";
|
||||
export declare const ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
|
||||
export declare const CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
|
||||
export declare const AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
|
||||
export declare const SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
|
||||
export declare const EXPIRES_QUERY_PARAM = "X-Amz-Expires";
|
||||
export declare const HOST_HEADER = "host";
|
||||
export declare const ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
|
||||
11
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/ts3.4/getSignedUrl.d.ts
generated
vendored
Normal file
11
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/ts3.4/getSignedUrl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Client, Command } from "@smithy/smithy-client";
|
||||
import { MetadataBearer, RequestPresigningArguments } from "@smithy/types";
|
||||
export declare const getSignedUrl: <
|
||||
InputTypesUnion extends object,
|
||||
InputType extends InputTypesUnion,
|
||||
OutputType extends MetadataBearer = MetadataBearer
|
||||
>(
|
||||
client: Client<any, InputTypesUnion, MetadataBearer, any>,
|
||||
command: Command<InputType, OutputType, any, InputTypesUnion, MetadataBearer>,
|
||||
options?: RequestPresigningArguments
|
||||
) => Promise<string>;
|
||||
2
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/ts3.4/index.d.ts
generated
vendored
Normal file
2
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/ts3.4/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./getSignedUrl";
|
||||
export * from "./presigner";
|
||||
40
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/ts3.4/presigner.d.ts
generated
vendored
Normal file
40
backend/node_modules/@aws-sdk/s3-request-presigner/dist-types/ts3.4/presigner.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { SignatureV4MultiRegionInit } from "@aws-sdk/signature-v4-multi-region";
|
||||
import {
|
||||
AwsCredentialIdentity,
|
||||
RequestPresigner,
|
||||
RequestPresigningArguments,
|
||||
} from "@smithy/types";
|
||||
import { HttpRequest as IHttpRequest } from "@smithy/types";
|
||||
type PartialBy<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> &
|
||||
Partial<Pick<T, K>>;
|
||||
export type S3RequestPresignerOptions = PartialBy<
|
||||
SignatureV4MultiRegionInit,
|
||||
"service" | "uriEscapePath"
|
||||
> & {
|
||||
signingName?: string;
|
||||
};
|
||||
export declare class S3RequestPresigner implements RequestPresigner {
|
||||
private readonly signer;
|
||||
constructor(options: S3RequestPresignerOptions);
|
||||
presign(
|
||||
requestToSign: IHttpRequest,
|
||||
{
|
||||
unsignableHeaders,
|
||||
hoistableHeaders,
|
||||
unhoistableHeaders,
|
||||
...options
|
||||
}?: RequestPresigningArguments
|
||||
): Promise<IHttpRequest>;
|
||||
presignWithCredentials(
|
||||
requestToSign: IHttpRequest,
|
||||
credentials: AwsCredentialIdentity,
|
||||
{
|
||||
unsignableHeaders,
|
||||
hoistableHeaders,
|
||||
unhoistableHeaders,
|
||||
...options
|
||||
}?: RequestPresigningArguments
|
||||
): Promise<IHttpRequest>;
|
||||
private prepareRequest;
|
||||
}
|
||||
export {};
|
||||
64
backend/node_modules/@aws-sdk/s3-request-presigner/package.json
generated
vendored
Normal file
64
backend/node_modules/@aws-sdk/s3-request-presigner/package.json
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
{
|
||||
"name": "@aws-sdk/s3-request-presigner",
|
||||
"version": "3.971.0",
|
||||
"scripts": {
|
||||
"build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
|
||||
"build:cjs": "node ../../scripts/compilation/inline s3-request-presigner",
|
||||
"build:es": "tsc -p tsconfig.es.json",
|
||||
"build:include:deps": "yarn g:turbo run build -F=\"$npm_package_name\"",
|
||||
"build:types": "tsc -p tsconfig.types.json",
|
||||
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
||||
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
|
||||
"extract:docs": "api-extractor run --local",
|
||||
"test": "yarn g:vitest run",
|
||||
"test:watch": "yarn g:vitest watch"
|
||||
},
|
||||
"main": "./dist-cjs/index.js",
|
||||
"module": "./dist-es/index.js",
|
||||
"types": "./dist-types/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"author": {
|
||||
"name": "AWS SDK for JavaScript Team",
|
||||
"url": "https://aws.amazon.com/javascript/"
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@aws-sdk/signature-v4-multi-region": "3.970.0",
|
||||
"@aws-sdk/types": "3.969.0",
|
||||
"@aws-sdk/util-format-url": "3.969.0",
|
||||
"@smithy/middleware-endpoint": "^4.4.7",
|
||||
"@smithy/protocol-http": "^5.3.8",
|
||||
"@smithy/smithy-client": "^4.10.8",
|
||||
"@smithy/types": "^4.12.0",
|
||||
"tslib": "^2.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@aws-sdk/client-s3": "3.971.0",
|
||||
"@smithy/hash-node": "^4.2.8",
|
||||
"@tsconfig/recommended": "1.0.1",
|
||||
"@types/node": "^20.14.8",
|
||||
"concurrently": "7.0.0",
|
||||
"downlevel-dts": "0.10.1",
|
||||
"rimraf": "5.0.10",
|
||||
"typescript": "~5.8.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"typesVersions": {
|
||||
"<4.0": {
|
||||
"dist-types/*": [
|
||||
"dist-types/ts3.4/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist-*/**"
|
||||
],
|
||||
"homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages/s3-request-presigner",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/aws/aws-sdk-js-v3.git",
|
||||
"directory": "packages/s3-request-presigner"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user