Skip to content

[Backport 8.13] Changed API Key from tuple to encoding in the docs #2494

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

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions docs/guide/connecting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ es.options(

# You can persist the authenticated client to use
# later or use for multiple API calls:
auth_client = es.options(
api_key=("api-key-id", "api-key-secret")
)
auth_client = es.options(api_key="api_key")
for i in range(10):
auth_client.index(
index="example-index",
Expand Down Expand Up @@ -320,9 +318,10 @@ es = Elasticsearch(
[[auth-apikey]]
==== API Key authentication

You can configure the client to use {es}'s API Key for connecting to your
cluster. Note that you need the values of `id` and `api_key` to
https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html[authenticate via an API Key].
You can configure the client to use {es}'s API Key for connecting to your
cluster. These can be generated through the
https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html[Elasticsearch Create API key API]
or https://www.elastic.co/guide/en/kibana/current/api-keys.html#create-api-key[Kibana Stack Management].

[source,python]
----
Expand All @@ -332,7 +331,7 @@ from elasticsearch import Elasticsearch
es = Elasticsearch(
"https://localhost:9200",
ca_certs="/path/to/http_ca.crt",
api_key=("api_key.id", "api_key.api_key")
api_key="api_key",
)
----

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ from elasticsearch import Elasticsearch

client = Elasticsearch(
"https://...", # Elasticsearch endpoint
api_key=('api-key-id', 'api-key-secret'), # API key ID and secret
api_key="api_key",
)
----

Expand Down
8 changes: 4 additions & 4 deletions docs/guide/migration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ client = Elasticsearch(

# Include your authentication like 'api_key'
# 'basic_auth', or 'bearer_auth' here:
api_key=("<name>", "<key>")
api_key="api_key"
)
------------------------------------

Expand Down Expand Up @@ -133,7 +133,7 @@ from elasticsearch import Elasticsearch
client = Elasticsearch("http://localhost:9200")

# 8.0+ SUPPORTED USAGE:
client.options(api_key=("id", "api_key")).search(index="blogs")
client.options(api_key="api_key").search(index="blogs")

# 7.x DEPRECATED USAGE (Don't do this!):
client.search(index="blogs", api_key=("id", "api_key"))
Expand Down Expand Up @@ -171,7 +171,7 @@ with the `security.grant_api_key` API:
resp = (
client.options(
# This is the API key being used for the request
api_key=("request-id", "request-api-key")
api_key="request-api-key"
).security.grant_api_key(
# This is the API key being granted
api_key={
Expand Down Expand Up @@ -209,7 +209,7 @@ Starting with the 8.12 client, using a body parameter is fully supported again,
resp = (
client.options(
# This is the API key being used for the request
api_key=("request-id", "request-api-key")
api_key="request-api-key"
).security.grant_api_key(
body={
# This is the API key being granted
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch/_async/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ class AsyncElasticsearch(BaseClient):
# Set 'api_key' on the constructor
client = Elasticsearch(
"http://localhost:9200",
api_key=("id", "api_key")
api_key="api_key",
)
client.search(...)

# Set 'api_key' per request
client.options(api_key=("id", "api_key")).search(...)
client.options(api_key="api_key").search(...)
"""

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch/_sync/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ class Elasticsearch(BaseClient):
# Set 'api_key' on the constructor
client = Elasticsearch(
"http://localhost:9200",
api_key=("id", "api_key")
api_key="api_key",
)
client.search(...)

# Set 'api_key' per request
client.options(api_key=("id", "api_key")).search(...)
client.options(api_key="api_key").search(...)
"""

def __init__(
Expand Down