-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #794 from terascope/s3-sender-failure-tests
Update s3 client to v3
- Loading branch information
Showing
30 changed files
with
2,420 additions
and
1,902 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "file-assets-bundle", | ||
"version": "2.2.2", | ||
"version": "2.3.0", | ||
"description": "A set of processors for working with files", | ||
"repository": "https://github.com/terascope/file-assets.git", | ||
"author": "Terascope, LLC <[email protected]>", | ||
|
@@ -28,15 +28,14 @@ | |
"dependencies": {}, | ||
"devDependencies": { | ||
"@terascope/eslint-config": "^0.7.1", | ||
"@terascope/file-asset-apis": "^0.6.2", | ||
"@terascope/file-asset-apis": "^0.7.0", | ||
"@terascope/job-components": "^0.58.5", | ||
"@terascope/scripts": "^0.50.7", | ||
"@types/fs-extra": "^11.0.1", | ||
"@types/jest": "^29.5.0", | ||
"@types/json2csv": "^5.0.3", | ||
"@types/node": "^18.15.11", | ||
"@types/node-gzip": "^1.1.0", | ||
"aws-sdk": "^2.1351.0", | ||
"eslint": "^8.35.0", | ||
"fs-extra": "^11.1.1", | ||
"jest": "^29.5.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@terascope/file-asset-apis", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"description": "file reader and sender apis", | ||
"publishConfig": { | ||
"access": "public" | ||
|
@@ -23,6 +23,8 @@ | |
"author": "Terascope, LLC <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@aws-sdk/client-s3": "^3.315.0", | ||
"@aws-sdk/node-http-handler": "^3.310.0", | ||
"@terascope/utils": "^0.45.5", | ||
"csvtojson": "^2.0.10", | ||
"fs-extra": "^11.1.1", | ||
|
@@ -34,7 +36,6 @@ | |
"devDependencies": { | ||
"@terascope/scripts": "^0.50.7", | ||
"@types/jest": "^29.5.0", | ||
"aws-sdk": "^2.1351.0", | ||
"jest": "^29.5.0", | ||
"jest-extended": "^3.2.4", | ||
"jest-fixtures": "^0.6.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/file-asset-apis/src/s3/client-types/client-params.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export { | ||
GetObjectRequest, | ||
ListObjectsRequest, | ||
PutObjectRequest, | ||
DeleteObjectRequest, | ||
DeleteBucketRequest, | ||
HeadBucketRequest, | ||
CreateBucketRequest, | ||
UploadPartRequest, | ||
CompleteMultipartUploadRequest, | ||
AbortMultipartUploadRequest, | ||
AbortMultipartUploadCommand | ||
} from '@aws-sdk/client-s3'; |
9 changes: 9 additions & 0 deletions
9
packages/file-asset-apis/src/s3/client-types/client-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { | ||
GetObjectOutput, | ||
ListObjectsOutput, | ||
PutObjectOutput, | ||
DeleteObjectOutput, | ||
ListBucketsOutput, | ||
CreateBucketOutput, | ||
CompletedPart, | ||
} from '@aws-sdk/client-s3'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type { S3Client } from '@aws-sdk/client-s3'; | ||
export * as S3ClientParams from './client-params'; | ||
export * as S3ClientResponse from './client-response'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import fs from 'fs-extra'; | ||
import { Agent } from 'https'; | ||
import { S3Client as BaseClient } from '@aws-sdk/client-s3'; | ||
import { NodeHttpHandler } from '@aws-sdk/node-http-handler'; | ||
import type { S3ClientConfig as baseConfig } from '@aws-sdk/client-s3'; | ||
import { debugLogger, has } from '@terascope/utils'; | ||
import type { S3Client } from './client-types'; | ||
|
||
export interface S3ClientConfig extends baseConfig { | ||
sslEnabled?: boolean, | ||
certLocation?: string, | ||
httpOptions?: object, | ||
secretAccessKey?: string, | ||
accessKeyId?: string | ||
} | ||
|
||
export async function createS3Client( | ||
config: S3ClientConfig, | ||
logger = debugLogger('s3-client') | ||
): Promise<S3Client> { | ||
config.logger = logger; | ||
logger.info(`Using S3 endpoint: ${config.endpoint}`); | ||
// pull certLocation from env | ||
// https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-registering-certs.html | ||
// Instead of updating the client, we can just update the config before creating the client | ||
if (config.sslEnabled) { | ||
const certPath = config.certLocation ?? '/etc/ssl/certs/ca-certificates.crt'; | ||
const pathFound = await fs.exists(certPath); | ||
|
||
if (!pathFound) { | ||
throw new Error( | ||
`No cert path was found in config.certLocation: "${config.certLocation}" or in default "/etc/ssl/certs/ca-certificates.crt" location` | ||
); | ||
} | ||
// Assumes all certs needed are in a single bundle | ||
const certs = await fs.readFile(certPath); | ||
|
||
const configHttpOptions = config.httpOptions ?? {}; | ||
|
||
const httpOptions = Object.assign( | ||
{ rejectUnauthorized: true }, | ||
configHttpOptions, | ||
{ ca: [certs] } | ||
); | ||
|
||
config.requestHandler = new NodeHttpHandler({ | ||
httpsAgent: new Agent(httpOptions) | ||
}); | ||
} | ||
|
||
// config specified old style, need to move top level values into credentials | ||
if (!has(config, 'credentials') && has(config, 'accessKeyId') && has(config, 'secretAccessKey')) { | ||
const { accessKeyId, secretAccessKey } = config; | ||
config.credentials = { | ||
accessKeyId, | ||
secretAccessKey | ||
} as any; | ||
} | ||
|
||
return new BaseClient(config); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.