|
20 | 20 | from elastic_transport import ObjectApiResponse |
21 | 21 |
|
22 | 22 | from ._base import NamespacedClient |
23 | | -from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters |
| 23 | +from .utils import ( |
| 24 | + SKIP_IN_PATH, |
| 25 | + Stability, |
| 26 | + _availability_warning, |
| 27 | + _quote, |
| 28 | + _rewrite_parameters, |
| 29 | +) |
24 | 30 |
|
25 | 31 |
|
26 | 32 | class SecurityClient(NamespacedClient): |
@@ -682,6 +688,89 @@ async def clear_cached_service_tokens( |
682 | 688 | path_parts=__path_parts, |
683 | 689 | ) |
684 | 690 |
|
| 691 | + @_rewrite_parameters( |
| 692 | + body_fields=("api_key", "expiration", "metadata", "name"), |
| 693 | + ignore_deprecated_options={"api_key"}, |
| 694 | + ) |
| 695 | + @_availability_warning(Stability.EXPERIMENTAL) |
| 696 | + async def clone_api_key( |
| 697 | + self, |
| 698 | + *, |
| 699 | + api_key: t.Optional[str] = None, |
| 700 | + error_trace: t.Optional[bool] = None, |
| 701 | + expiration: t.Optional[t.Union[str, t.Literal[-1], t.Literal[0]]] = None, |
| 702 | + filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None, |
| 703 | + human: t.Optional[bool] = None, |
| 704 | + metadata: t.Optional[t.Mapping[str, t.Any]] = None, |
| 705 | + name: t.Optional[str] = None, |
| 706 | + pretty: t.Optional[bool] = None, |
| 707 | + refresh: t.Optional[ |
| 708 | + t.Union[bool, str, t.Literal["false", "true", "wait_for"]] |
| 709 | + ] = None, |
| 710 | + body: t.Optional[t.Dict[str, t.Any]] = None, |
| 711 | + ) -> ObjectApiResponse[t.Any]: |
| 712 | + """ |
| 713 | + .. raw:: html |
| 714 | +
|
| 715 | + <p>Clone an API key.</p> |
| 716 | + <p>Create a copy of an existing API key with a new ID. |
| 717 | + The cloned key inherits the role descriptors of the source key. |
| 718 | + This is intended for applications (such as Kibana) that need to |
| 719 | + create API keys on behalf of a user using an existing API key credential, |
| 720 | + since derived API keys (API keys created by API keys) are not otherwise supported.</p> |
| 721 | +
|
| 722 | +
|
| 723 | + `<https://www.elastic.co/docs/api/doc/elasticsearch#TODO>`_ |
| 724 | +
|
| 725 | + :param api_key: The credentials of the API key to clone. This is the secret value |
| 726 | + returned when the key was originally created. |
| 727 | + :param expiration: The expiration time for the cloned API key. By default, API |
| 728 | + keys never expire. Set to `null` to explicitly create a key with no expiration. |
| 729 | + :param metadata: Arbitrary metadata to associate with the cloned API key. It |
| 730 | + supports nested data structure. Within the metadata object, keys beginning |
| 731 | + with `_` are reserved for system usage. |
| 732 | + :param name: A name for the cloned API key. If not provided, the name of the |
| 733 | + source key is used. |
| 734 | + :param refresh: If `true` (the default) then refresh the affected shards to make |
| 735 | + this operation visible to search, if `wait_for` then wait for a refresh to |
| 736 | + make this operation visible to search, if `false` then do nothing with refreshes. |
| 737 | + """ |
| 738 | + if api_key is None and body is None: |
| 739 | + raise ValueError("Empty value passed for parameter 'api_key'") |
| 740 | + __path_parts: t.Dict[str, str] = {} |
| 741 | + __path = "/_security/api_key/clone" |
| 742 | + __query: t.Dict[str, t.Any] = {} |
| 743 | + __body: t.Dict[str, t.Any] = body if body is not None else {} |
| 744 | + if error_trace is not None: |
| 745 | + __query["error_trace"] = error_trace |
| 746 | + if filter_path is not None: |
| 747 | + __query["filter_path"] = filter_path |
| 748 | + if human is not None: |
| 749 | + __query["human"] = human |
| 750 | + if pretty is not None: |
| 751 | + __query["pretty"] = pretty |
| 752 | + if refresh is not None: |
| 753 | + __query["refresh"] = refresh |
| 754 | + if not __body: |
| 755 | + if api_key is not None: |
| 756 | + __body["api_key"] = api_key |
| 757 | + if expiration is not None: |
| 758 | + __body["expiration"] = expiration |
| 759 | + if metadata is not None: |
| 760 | + __body["metadata"] = metadata |
| 761 | + if name is not None: |
| 762 | + __body["name"] = name |
| 763 | + __headers = {"accept": "application/json", "content-type": "application/json"} |
| 764 | + return await self.perform_request( # type: ignore[return-value] |
| 765 | + "PUT", |
| 766 | + __path, |
| 767 | + params=__query, |
| 768 | + headers=__headers, |
| 769 | + body=__body, |
| 770 | + endpoint_id="security.clone_api_key", |
| 771 | + path_parts=__path_parts, |
| 772 | + ) |
| 773 | + |
685 | 774 | @_rewrite_parameters( |
686 | 775 | body_fields=("expiration", "metadata", "name", "role_descriptors"), |
687 | 776 | ) |
|
0 commit comments