77
88import httpx
99
10- from ..types import api_key_list_params , api_key_create_params , api_key_update_params , api_key_retrieve_params
10+ from ..types import (
11+ api_key_list_params ,
12+ api_key_create_params ,
13+ api_key_rotate_params ,
14+ api_key_update_params ,
15+ api_key_retrieve_params ,
16+ )
1117from .._types import Body , Omit , Query , Headers , NoneType , NotGiven , omit , not_given
1218from .._utils import path_template , maybe_transform , async_maybe_transform
1319from .._compat import cached_property
@@ -277,6 +283,57 @@ def delete(
277283 cast_to = NoneType ,
278284 )
279285
286+ def rotate (
287+ self ,
288+ id : str ,
289+ * ,
290+ days_to_expire : Optional [int ] | Omit = omit ,
291+ expire_in_days : Optional [int ] | Omit = omit ,
292+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
293+ # The extra values given here take precedence over values defined on the client or passed to this method.
294+ extra_headers : Headers | None = None ,
295+ extra_query : Query | None = None ,
296+ extra_body : Body | None = None ,
297+ timeout : float | httpx .Timeout | None | NotGiven = not_given ,
298+ ) -> CreatedAPIKey :
299+ """Rotate an API key.
300+
301+ Issues a new key that copies the name and project of the
302+ rotated key, and schedules the rotated key to expire after a grace period so
303+ in-flight callers can swap over. The new plaintext key is returned once.
304+
305+ Args:
306+ days_to_expire: Lifetime in days for the new key, up to 3650. Omit to reuse the rotated key's
307+ original lifetime, or never-expires if it had none.
308+
309+ expire_in_days: Grace period in days before the rotated key expires. Use 0 to expire it
310+ immediately. Omit for the default grace period of 7 days.
311+
312+ extra_headers: Send extra headers
313+
314+ extra_query: Add additional query parameters to the request
315+
316+ extra_body: Add additional JSON properties to the request
317+
318+ timeout: Override the client-level default timeout for this request, in seconds
319+ """
320+ if not id :
321+ raise ValueError (f"Expected a non-empty value for `id` but received { id !r} " )
322+ return self ._post (
323+ path_template ("/org/api_keys/{id}/rotate" , id = id ),
324+ body = maybe_transform (
325+ {
326+ "days_to_expire" : days_to_expire ,
327+ "expire_in_days" : expire_in_days ,
328+ },
329+ api_key_rotate_params .APIKeyRotateParams ,
330+ ),
331+ options = make_request_options (
332+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
333+ ),
334+ cast_to = CreatedAPIKey ,
335+ )
336+
280337
281338class AsyncAPIKeysResource (AsyncAPIResource ):
282339 """Create and manage API keys for organization and project-scoped access."""
@@ -529,6 +586,57 @@ async def delete(
529586 cast_to = NoneType ,
530587 )
531588
589+ async def rotate (
590+ self ,
591+ id : str ,
592+ * ,
593+ days_to_expire : Optional [int ] | Omit = omit ,
594+ expire_in_days : Optional [int ] | Omit = omit ,
595+ # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
596+ # The extra values given here take precedence over values defined on the client or passed to this method.
597+ extra_headers : Headers | None = None ,
598+ extra_query : Query | None = None ,
599+ extra_body : Body | None = None ,
600+ timeout : float | httpx .Timeout | None | NotGiven = not_given ,
601+ ) -> CreatedAPIKey :
602+ """Rotate an API key.
603+
604+ Issues a new key that copies the name and project of the
605+ rotated key, and schedules the rotated key to expire after a grace period so
606+ in-flight callers can swap over. The new plaintext key is returned once.
607+
608+ Args:
609+ days_to_expire: Lifetime in days for the new key, up to 3650. Omit to reuse the rotated key's
610+ original lifetime, or never-expires if it had none.
611+
612+ expire_in_days: Grace period in days before the rotated key expires. Use 0 to expire it
613+ immediately. Omit for the default grace period of 7 days.
614+
615+ extra_headers: Send extra headers
616+
617+ extra_query: Add additional query parameters to the request
618+
619+ extra_body: Add additional JSON properties to the request
620+
621+ timeout: Override the client-level default timeout for this request, in seconds
622+ """
623+ if not id :
624+ raise ValueError (f"Expected a non-empty value for `id` but received { id !r} " )
625+ return await self ._post (
626+ path_template ("/org/api_keys/{id}/rotate" , id = id ),
627+ body = await async_maybe_transform (
628+ {
629+ "days_to_expire" : days_to_expire ,
630+ "expire_in_days" : expire_in_days ,
631+ },
632+ api_key_rotate_params .APIKeyRotateParams ,
633+ ),
634+ options = make_request_options (
635+ extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
636+ ),
637+ cast_to = CreatedAPIKey ,
638+ )
639+
532640
533641class APIKeysResourceWithRawResponse :
534642 def __init__ (self , api_keys : APIKeysResource ) -> None :
@@ -549,6 +657,9 @@ def __init__(self, api_keys: APIKeysResource) -> None:
549657 self .delete = to_raw_response_wrapper (
550658 api_keys .delete ,
551659 )
660+ self .rotate = to_raw_response_wrapper (
661+ api_keys .rotate ,
662+ )
552663
553664
554665class AsyncAPIKeysResourceWithRawResponse :
@@ -570,6 +681,9 @@ def __init__(self, api_keys: AsyncAPIKeysResource) -> None:
570681 self .delete = async_to_raw_response_wrapper (
571682 api_keys .delete ,
572683 )
684+ self .rotate = async_to_raw_response_wrapper (
685+ api_keys .rotate ,
686+ )
573687
574688
575689class APIKeysResourceWithStreamingResponse :
@@ -591,6 +705,9 @@ def __init__(self, api_keys: APIKeysResource) -> None:
591705 self .delete = to_streamed_response_wrapper (
592706 api_keys .delete ,
593707 )
708+ self .rotate = to_streamed_response_wrapper (
709+ api_keys .rotate ,
710+ )
594711
595712
596713class AsyncAPIKeysResourceWithStreamingResponse :
@@ -612,3 +729,6 @@ def __init__(self, api_keys: AsyncAPIKeysResource) -> None:
612729 self .delete = async_to_streamed_response_wrapper (
613730 api_keys .delete ,
614731 )
732+ self .rotate = async_to_streamed_response_wrapper (
733+ api_keys .rotate ,
734+ )
0 commit comments