-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pulling saws igner intoo separate namespace
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
- Loading branch information
1 parent
59bbbf4
commit 8f871b3
Showing
13 changed files
with
604 additions
and
274 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,28 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import { Credentials } from '@aws-sdk/types'; | ||
import Connection from '../Connection'; | ||
import * as http from 'http'; | ||
|
||
interface AwsV4SignerOptions { | ||
credentials: Credentials; | ||
region: string; | ||
} | ||
|
||
export interface AwsV4SignerResponse { | ||
Connection: Connection; | ||
buildSignedRequestObject(request: any): http.ClientRequestArgs; | ||
} | ||
|
||
export default function AwsV4Signer(opts: AwsV4SignerOptions): AwsV4SignerResponse; | ||
|
||
export {}; |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
import { OpenSearchClientError } from '../errors'; | ||
|
||
export declare class AwsV4SignerError extends OpenSearchClientError { | ||
name: string; | ||
message: string; | ||
data: any; | ||
constructor(message: string, data: any); | ||
} |
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,27 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
'use strict'; | ||
const { OpenSearchClientError } = require('../errors'); | ||
|
||
class AwsV4SignerError extends OpenSearchClientError { | ||
constructor(message, data) { | ||
super(message, data); | ||
Error.captureStackTrace(this, AwsV4SignerError); | ||
this.name = 'AwsV4SignerError'; | ||
this.message = message || 'AwsV4Signer Error'; | ||
this.data = data; | ||
} | ||
} | ||
|
||
module.exports = { | ||
AwsV4SignerError, | ||
}; |
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
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
const { test } = require('tap'); | ||
const { URL } = require('url'); | ||
const { v4: uuidv4 } = require('uuid'); | ||
const { AwsV4Signer } = require('../../index'); | ||
const { AwsV4SignerError } = require('../../lib/aws/errors'); | ||
const { Connection } = require('../../index'); | ||
|
||
test('Sign with SigV4', (t) => { | ||
t.plan(2); | ||
|
||
const mockCreds = { | ||
accessKeyId: uuidv4(), | ||
secretAccessKey: uuidv4(), | ||
}; | ||
|
||
const mockRegion = 'us-west-2'; | ||
|
||
const AwsV4SignerOptions = { credentials: mockCreds, region: mockRegion }; | ||
|
||
const auth = AwsV4Signer(AwsV4SignerOptions); | ||
|
||
const connection = new Connection({ | ||
url: new URL('https://localhost:9200'), | ||
}); | ||
|
||
const request = connection.buildRequestObject({ | ||
path: '/hello', | ||
method: 'GET', | ||
headers: { | ||
'X-Custom-Test': true, | ||
}, | ||
}); | ||
const signedRequest = auth.buildSignedRequestObject(request); | ||
t.hasProp(signedRequest.headers, 'X-Amz-Date'); | ||
t.hasProp(signedRequest.headers, 'Authorization'); | ||
}); | ||
|
||
test('Sign with SigV4 failure (with empty region)', (t) => { | ||
t.plan(2); | ||
|
||
const mockCreds = { | ||
accessKeyId: uuidv4(), | ||
secretAccessKey: uuidv4(), | ||
}; | ||
|
||
const AwsV4SignerOptions = { credentials: mockCreds }; | ||
|
||
try { | ||
AwsV4Signer(AwsV4SignerOptions); | ||
t.fail('Should fail'); | ||
} catch (err) { | ||
t.ok(err instanceof AwsV4SignerError); | ||
t.equal(err.message, 'Region cannot be empty'); | ||
} | ||
}); | ||
|
||
test('Sign with SigV4 failure (with empty credentials)', (t) => { | ||
t.plan(2); | ||
|
||
const mockRegion = 'us-west-2'; | ||
|
||
const AwsV4SignerOptions = { region: mockRegion }; | ||
|
||
try { | ||
AwsV4Signer(AwsV4SignerOptions); | ||
t.fail('Should fail'); | ||
} catch (err) { | ||
t.ok(err instanceof AwsV4SignerError); | ||
t.equal(err.message, 'Credentials cannot be empty'); | ||
} | ||
}); |
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