i have a JavaScript function (using Cypress) which uses REST API to query some data from elasticsearch. For a first version, I handled authentication with username/password as shown below and that worked fine.
So, update after a few more stolls through the documentation and some experiments:
The documentation itself doesn't give an example for using something else than basic auth, but it also doesn't state that basic auth was the only option.
I tried some more configurations and also the old, experimental browser-build of the js-client, which results in the same error.
I am now working on a solution using the node-module, which apparently supports the API Key Authentication, but is quite inconvenient for usage in cypress tests.
Edit: ikakavas' solution works for me as well, so I'll go with that
It looks like cypress uses the python requests library internally so you could ( see the docs: https://github.com/request/request#custom-http-headers ) add a custom Authorization header. Something like ( entirely untested ) :
private readonly elasticDB = {
node: 'http://elastic:9200',
authHeaders: {
'Authorization: 'ApiKey <base64encoded api key value here>'
}
};
cy.request({
method: 'POST',
url: this.elasticDB.node,
headers: this.elasticDB.authHeader,
body: body
})
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.