-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AwsSigV4 signing functionality #279
Merged
Merged
Changes from 9 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d78ae1c
Add AwsSigV4 signing functionality
harshavamsi 59bbbf4
Adlicense text to signer types
harshavamsi caf4d74
Pulling aws signer into separate namespace
harshavamsi 7faaae1
Adding separate injection point for v4Signer
harshavamsi 6a67179
Fix name spacing and bump version
harshavamsi 90a443d
Typo in readme
harshavamsi e50e8fc
Adding 0BSD to allow license
harshavamsi f58e21e
Split code snippets into USER GUIDE
harshavamsi f1e5a16
Remove un-used package and update license
harshavamsi 93f347b
Merge branch 'main' into awsv4signer
harshavamsi 6d7b79c
Fix language in user guide
harshavamsi 8505f85
Add types to dev dependencies
harshavamsi 562d683
Update USER_GUIDE.md
harshavamsi 341df4f
add credentials refresh options
rawpixel-vincent f629fa1
fix AwsSigv4Signer type with Promise
rawpixel-vincent c952ba0
remove JSDoc
rawpixel-vincent 4abf7ea
update example usage
rawpixel-vincent 48e5b3a
update credentials refresh strategy
rawpixel-vincent e376ef4
update credentials refresh and expiration
rawpixel-vincent 1475bf0
fix types
rawpixel-vincent 52ab9ad
add failure to refresh credentials test case
rawpixel-vincent d31eb6f
cleanup and comments
rawpixel-vincent f036b30
clarify code example in the docs
rawpixel-vincent ef2b3c7
remove explicit async from code example
rawpixel-vincent 13d30de
remove unused credentialsState.acquiredAt
rawpixel-vincent b1308b9
Minor doc and misc fixes
harshavamsi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
# User Guide | ||
|
||
- [Initializing a Client](#initializing-a-client) | ||
- [Initializing a Client with AWS SigV4 Signing](#initializing-a-client-with-aws-sigv4-signing) | ||
- [Creating an Index](#creating-an-index) | ||
- [Add a Document to the Index](#add-a-document-to-the-index) | ||
- [Search for the Document](#search-for-the-document) | ||
- [Delete the document](#delete-the-document) | ||
- [Delete the index](#delete-the-index) | ||
|
||
|
||
## Initializing a Client | ||
```javascript | ||
'use strict'; | ||
|
||
var host = 'localhost'; | ||
var protocol = 'https'; | ||
var port = 9200; | ||
var auth = 'admin:admin'; // For testing only. Don't store credentials in code. | ||
var ca_certs_path = '/full/path/to/root-ca.pem'; | ||
|
||
// Optional client certificates if you don't want to use HTTP basic authentication. | ||
// var client_cert_path = '/full/path/to/client.pem' | ||
// var client_key_path = '/full/path/to/client-key.pem' | ||
|
||
// Create a client with SSL/TLS enabled. | ||
var { Client } = require('@opensearch-project/opensearch'); | ||
var fs = require('fs'); | ||
var client = new Client({ | ||
node: protocol + '://' + auth + '@' + host + ':' + port, | ||
ssl: { | ||
ca: fs.readFileSync(ca_certs_path), | ||
// You can turn off certificate verification (rejectUnauthorized: false) if you're using self-signed certificates with a hostname mismatch. | ||
// cert: fs.readFileSync(client_cert_path), | ||
// key: fs.readFileSync(client_key_path) | ||
}, | ||
}); | ||
``` | ||
|
||
## Initializing a Client with AWS SigV4 Signing | ||
|
||
```javascript | ||
const endpoint = ""; // OpenSearch domain URL e.g. https://search-xxx.region.es.amazonaws.com | ||
const { Client } = require('@opensearch-project/opensearch'); | ||
const { AwsSigv4Signer } = require('@opensearch-project/opensearch/aws'); | ||
const { defaultProvider } = require("@aws-sdk/credential-provider-node"); | ||
|
||
async function getClient() { | ||
const credentials = await defaultProvider()(); | ||
var client = new Client({ | ||
...AwsV4Signer({ | ||
harshavamsi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
credentials: credentials, | ||
region: "us-west-2", | ||
}), | ||
node: endpoint, | ||
}); | ||
return client; | ||
} | ||
``` | ||
|
||
## Creating an Index | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pick one or the other in the headings? a) "Create an Index", "Add a Document", "Delete ..." |
||
|
||
```javascript | ||
var index_name = 'books'; | ||
var settings = { | ||
settings: { | ||
index: { | ||
number_of_shards: 4, | ||
number_of_replicas: 3, | ||
}, | ||
}, | ||
}; | ||
|
||
var response = await client.indices.create({ | ||
index: index_name, | ||
body: settings, | ||
}); | ||
|
||
console.log('Creating index:'); | ||
harshavamsi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.log(response.body); | ||
``` | ||
|
||
## Add a Document to the Index | ||
|
||
```javascript | ||
var document = { | ||
title: 'The Outsider', | ||
author: 'Stephen King', | ||
year: '2018', | ||
genre: 'Crime fiction', | ||
}; | ||
|
||
var id = '1'; | ||
|
||
var response = await client.index({ | ||
id: id, | ||
index: index_name, | ||
body: document, | ||
refresh: true, | ||
}); | ||
|
||
console.log('Adding document:'); | ||
console.log(response.body); | ||
``` | ||
|
||
## Search for the Document | ||
|
||
```javascript | ||
var query = { | ||
query: { | ||
match: { | ||
title: { | ||
query: 'The Outsider', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
var response = await client.search({ | ||
index: index_name, | ||
body: query, | ||
}); | ||
|
||
console.log('Search results:'); | ||
console.log(response.body.hits); | ||
``` | ||
|
||
## Delete the document | ||
|
||
```javascript | ||
var response = await client.delete({ | ||
index: index_name, | ||
id: id, | ||
}); | ||
|
||
console.log('Deleting document:'); | ||
console.log(response.body); | ||
``` | ||
|
||
## Delete the index | ||
|
||
```javascript | ||
var response = await client.indices.delete({ | ||
index: index_name, | ||
}); | ||
|
||
console.log('Deleting index:'); | ||
console.log(response.body); | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: To authenticate with the Amazon OpenSearch Service use
AwsSigv4Signer
.