From 2719642a720e63a3b6258d504cea1731958040e6 Mon Sep 17 00:00:00 2001 From: Iulia Feroli Date: Thu, 21 Mar 2024 10:33:13 +0100 Subject: [PATCH 1/2] Changed API Key from tuple to encoding in the docs (#2477) (cherry picked from commit cafeba0882197e3562726934aa65a6ff008f65fb) --- docs/guide/connecting.asciidoc | 13 ++++++------- docs/guide/getting-started.asciidoc | 2 +- docs/guide/migration.asciidoc | 8 ++++---- elasticsearch/_sync/client/__init__.py | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/docs/guide/connecting.asciidoc b/docs/guide/connecting.asciidoc index 34f62298a..a6f41a97b 100644 --- a/docs/guide/connecting.asciidoc +++ b/docs/guide/connecting.asciidoc @@ -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", @@ -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] ---- @@ -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", ) ---- diff --git a/docs/guide/getting-started.asciidoc b/docs/guide/getting-started.asciidoc index aef383f5d..db0a8095b 100644 --- a/docs/guide/getting-started.asciidoc +++ b/docs/guide/getting-started.asciidoc @@ -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", ) ---- diff --git a/docs/guide/migration.asciidoc b/docs/guide/migration.asciidoc index 7a01f2ec8..1230399d7 100644 --- a/docs/guide/migration.asciidoc +++ b/docs/guide/migration.asciidoc @@ -91,7 +91,7 @@ client = Elasticsearch( # Include your authentication like 'api_key' # 'basic_auth', or 'bearer_auth' here: - api_key=("", "") + api_key="api_key" ) ------------------------------------ @@ -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")) @@ -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={ @@ -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 diff --git a/elasticsearch/_sync/client/__init__.py b/elasticsearch/_sync/client/__init__.py index 77e5088ca..457853455 100644 --- a/elasticsearch/_sync/client/__init__.py +++ b/elasticsearch/_sync/client/__init__.py @@ -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__( From acc3f92c515c630e9592862621de624c86752567 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Tue, 26 Mar 2024 13:41:40 +0400 Subject: [PATCH 2/2] Fix api_key docstring in async case too (#2487) --- elasticsearch/_async/client/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/elasticsearch/_async/client/__init__.py b/elasticsearch/_async/client/__init__.py index 9d97a2ab0..01bfa04fd 100644 --- a/elasticsearch/_async/client/__init__.py +++ b/elasticsearch/_async/client/__init__.py @@ -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__(