Revert "web/satellite: use aws-sdk v3"

This reverts commit 2e3e5547e2.

The S3 client is returning an error related to region with the new
changes.

Change-Id: I989b8a46c0e97c1278517e1de07fe42d5950cf54
This commit is contained in:
Moby von Briesen 2022-05-12 19:43:49 -04:00 committed by Antonio Franco (He/Him)
parent db1cc8ca95
commit 7d35f3e977
8 changed files with 449 additions and 3258 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,9 +14,6 @@
},
"dependencies": {
"@aws-crypto/sha256-browser": "2.0.1",
"@aws-sdk/client-s3": "^3.85.0",
"@aws-sdk/lib-storage": "^3.85.0",
"@aws-sdk/s3-request-presigner": "^3.85.0",
"@aws-sdk/signature-v4": "3.78.0",
"@aws-sdk/types": "3.78.0",
"apollo-cache-inmemory": "1.6.6",
@ -25,16 +22,19 @@
"apollo-link-context": "1.0.20",
"apollo-link-error": "1.1.13",
"apollo-link-http": "1.5.17",
"aws-sdk": "2.1128.0",
"bip39": "3.0.4",
"chart.js": "2.9.4",
"core-js": "3.22.4",
"graphql": "15.3.0",
"graphql-tag": "2.12.6",
"load-script": "1.0.0",
"pbkdf2": "3.1.2",
"pretty-bytes": "5.6.0",
"qrcode": "1.5.0",
"stream-browserify": "3.0.0",
"stripe": "8.215.0",
"util": "0.12.4",
"vue": "2.6.14",
"vue-chartjs": "3.5.1",
"vue-class-component": "7.2.6",

View File

@ -21,7 +21,7 @@
</template>
<script lang="ts">
import { Bucket } from '@aws-sdk/client-s3';
import { Bucket } from 'aws-sdk/clients/s3';
import { Component, Prop, Vue } from 'vue-property-decorator';
import BucketIcon from '@/../static/images/objects/bucketItem.svg';

View File

@ -59,7 +59,7 @@
</template>
<script lang="ts">
import { Bucket } from '@aws-sdk/client-s3';
import { Bucket } from 'aws-sdk/clients/s3';
import { Component, Vue, Watch } from 'vue-property-decorator';
import VLoader from '@/components/common/VLoader.vue';

View File

@ -1,20 +1,8 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
import {
S3Client,
CommonPrefix,
ListObjectsCommand,
DeleteObjectCommand,
PutObjectCommand,
GetObjectCommand, PutObjectCommandInput
} from '@aws-sdk/client-s3';
import { Upload } from "@aws-sdk/lib-storage";
import S3, { CommonPrefix } from "aws-sdk/clients/s3";
import {StoreModule} from "@/types/store";
import {SignatureV4} from "@aws-sdk/signature-v4";
const listCache = new Map();
@ -33,7 +21,7 @@ type BrowserObject = {
};
export type FilesState = {
s3: S3Client | null;
s3: S3 | null;
accessKey: null | string;
path: string;
@ -62,7 +50,7 @@ export type FilesState = {
};
type InitializedFilesState = FilesState & {
s3: S3Client;
s3: S3;
};
function assertIsInitialized(
@ -184,17 +172,17 @@ export const makeFilesModule = (): FilesModule => ({
fetchObjectMap: (arg0) => Promisable<string>;
}
) {
state.s3 = new S3Client({
credentials: {
accessKeyId: accessKey,
secretAccessKey: secretKey,
},
endpoint: endpoint,
forcePathStyle: true,
signerConstructor: SignatureV4,
// TODO: connectTimeout: 0,
// TODO: httpOptions: { timeout: 0 },
});
const s3Config = {
accessKeyId: accessKey,
secretAccessKey: secretKey,
endpoint,
s3ForcePathStyle: true,
signatureVersion: "v4",
connectTimeout: 0,
httpOptions: { timeout: 0 },
};
state.s3 = new S3(s3Config);
state.accessKey = accessKey;
state.bucket = bucket;
state.browserRoot = browserRoot;
@ -312,13 +300,13 @@ export const makeFilesModule = (): FilesModule => ({
assertIsInitialized(state);
const response = await state.s3.send(
new ListObjectsCommand({
const response = await state.s3
.listObjects({
Bucket: state.bucket,
Delimiter: "/",
Prefix: path,
})
);
.promise();
const { Contents, CommonPrefixes } = response;
@ -479,25 +467,21 @@ export const makeFilesModule = (): FilesModule => ({
const fileName = getUniqueFileName(directories.join("/") + file.name);
const params: PutObjectCommandInput = {
const params = {
Bucket: state.bucket,
Key: state.path + fileName,
Body: file,
};
const upload = new Upload({
client: state.s3,
partSize: 64 * 1024 * 1024,
params: params,
})
const upload = state.s3.upload(
{ ...params },
{ partSize: 64 * 1024 * 1024 }
);
upload.on("httpUploadProgress", (progress) => {
let p = 0;
if(progress.loaded && progress.total) {
p = Math.round((progress.loaded / progress.total) * 100);
}
commit("setProgress", {
Key: progress.Key,
progress: p,
Key: params.Key,
progress: Math.round((progress.loaded / progress.total) * 100),
});
});
@ -516,7 +500,7 @@ export const makeFilesModule = (): FilesModule => ({
}
try {
await upload;
await upload.promise();
} catch (e) {
// An error is raised if the upload is aborted by the user
console.log(e);
@ -542,11 +526,12 @@ export const makeFilesModule = (): FilesModule => ({
async createFolder({ state, dispatch }, name) {
assertIsInitialized(state);
await state.s3.send(new PutObjectCommand({
Bucket: state.bucket,
Key: state.path + name + "/.file_placeholder",
Body: "",
}));
await state.s3
.putObject({
Bucket: state.bucket,
Key: state.path + name + "/.file_placeholder",
})
.promise();
dispatch("list");
},
@ -557,10 +542,12 @@ export const makeFilesModule = (): FilesModule => ({
) {
assertIsInitialized(state);
await state.s3.send(new DeleteObjectCommand({
Bucket: state.bucket,
Key: path + file.Key,
}))
await state.s3
.deleteObject({
Bucket: state.bucket,
Key: path + file.Key,
})
.promise();
if (!folder) {
await dispatch("list");
@ -574,12 +561,13 @@ export const makeFilesModule = (): FilesModule => ({
async function recurse(filePath) {
assertIsInitialized(state);
const { Contents, CommonPrefixes } = await state.s3.send(
new ListObjectsCommand({
const { Contents, CommonPrefixes } = await state.s3
.listObjects({
Bucket: state.bucket,
Delimiter: "/",
Prefix: filePath,
}));
})
.promise();
if (Contents === undefined) {
throw new Error(
@ -657,11 +645,10 @@ export const makeFilesModule = (): FilesModule => ({
async download({ state }, file) {
assertIsInitialized(state);
const url = await getSignedUrl(this.s3,
new GetObjectCommand({
Bucket: state.bucket,
Key: state.path + file.Key,
}));
const url = state.s3.getSignedUrl("getObject", {
Bucket: state.bucket,
Key: state.path + file.Key,
});
const downloadURL = function(data, fileName) {
const a = document.createElement("a");
a.href = data;

View File

@ -1,19 +1,12 @@
// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
import {
S3Client,
Bucket,
ListBucketsCommand,
CreateBucketCommand,
DeleteBucketCommand
} from '@aws-sdk/client-s3';
import S3, { Bucket } from 'aws-sdk/clients/s3';
import { EdgeCredentials } from '@/types/accessGrants';
import { APP_STATE_ACTIONS } from '@/utils/constants/actionNames';
import { FilesState } from '@/store/modules/files';
import {StoreModule} from "@/types/store";
import {SignatureV4} from "@aws-sdk/signature-v4";
export const OBJECTS_ACTIONS = {
CLEAR: 'clearObjects',
@ -56,10 +49,10 @@ const {
export class ObjectsState {
public apiKey = '';
public gatewayCredentials: EdgeCredentials = new EdgeCredentials();
public s3Client: S3Client = new S3Client({
forcePathStyle: true,
signerConstructor: SignatureV4,
// TODO: httpOptions: { timeout: 0 },
public s3Client: S3 = new S3({
s3ForcePathStyle: true,
signatureVersion: "v4",
httpOptions: { timeout: 0 },
});
public bucketsList: Bucket[] = [];
public passphrase = '';
@ -90,16 +83,16 @@ export function makeObjectsModule(): StoreModule<ObjectsState, ObjectsContext> {
state.gatewayCredentials = credentials;
},
[SET_S3_CLIENT](state: ObjectsState) {
state.s3Client = new S3Client({
credentials: {
accessKeyId: state.gatewayCredentials.accessKeyId,
secretAccessKey: state.gatewayCredentials.secretKey,
},
const s3Config = {
accessKeyId: state.gatewayCredentials.accessKeyId,
secretAccessKey: state.gatewayCredentials.secretKey,
endpoint: state.gatewayCredentials.endpoint,
forcePathStyle: true,
signerConstructor: SignatureV4,
// TODO: httpOptions: { timeout: 0 },
});
s3ForcePathStyle: true,
signatureVersion: "v4",
httpOptions: { timeout: 0 },
};
state.s3Client = new S3(s3Config);
},
[SET_BUCKETS](state: ObjectsState, buckets: Bucket[]) {
state.bucketsList = buckets;
@ -117,10 +110,10 @@ export function makeObjectsModule(): StoreModule<ObjectsState, ObjectsContext> {
state.apiKey = '';
state.passphrase = '';
state.gatewayCredentials = new EdgeCredentials();
state.s3Client = new S3Client({
forcePathStyle: true,
signerConstructor: SignatureV4,
// TODO: httpOptions: { timeout: 0 },
state.s3Client = new S3({
s3ForcePathStyle: true,
signatureVersion: "v4",
httpOptions: { timeout: 0 },
});
state.bucketsList = [];
state.fileComponentBucketName = '';
@ -143,24 +136,24 @@ export function makeObjectsModule(): StoreModule<ObjectsState, ObjectsContext> {
commit(SET_FILE_COMPONENT_BUCKET_NAME, bucketName);
},
fetchBuckets: async function(ctx): Promise<void> {
const result = await ctx.state.s3Client.send(new ListBucketsCommand({}));
const result = await ctx.state.s3Client.listBuckets().promise();
ctx.commit(SET_BUCKETS, result.Buckets);
},
createBucket: async function(ctx, name: string): Promise<void> {
await ctx.state.s3Client.send(new CreateBucketCommand({
await ctx.state.s3Client.createBucket({
Bucket: name,
}))
}).promise();
},
createDemoBucket: async function(ctx): Promise<void> {
await ctx.state.s3Client.send(new CreateBucketCommand({
await ctx.state.s3Client.createBucket({
Bucket: DEMO_BUCKET_NAME,
}))
}).promise();
},
deleteBucket: async function(ctx, name: string): Promise<void> {
await ctx.state.s3Client.send(
new DeleteBucketCommand({
Bucket: name,
}));
await ctx.state.s3Client.deleteBucket({
Bucket: name,
}).promise();
},
clearObjects: function({commit}: ObjectsContext): void {
commit(CLEAR);

View File

@ -102,6 +102,7 @@ import {APP_STATE_ACTIONS} from '@/utils/constants/actionNames';
import {AppState} from '@/utils/constants/appStateEnum';
import {ACCESS_GRANTS_ACTIONS} from '@/store/modules/accessGrants';
import {OAuthClient, OAuthClientsAPI} from '@/api/oauthClients';
import {URLSearchParams} from "url";
const oauthClientsAPI = new OAuthClientsAPI();

View File

@ -40,6 +40,7 @@ module.exports = {
plugins: plugins,
resolve: {
fallback: {
"util": require.resolve("util/"),
"stream": require.resolve("stream-browserify"),
"buffer": require.resolve("buffer"),
},