|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import httpx |
| 6 | + |
| 7 | +from ..._types import Body, Query, Headers, NotGiven, not_given |
| 8 | +from ..._compat import cached_property |
| 9 | +from ..._resource import SyncAPIResource, AsyncAPIResource |
| 10 | +from ..._response import ( |
| 11 | + to_raw_response_wrapper, |
| 12 | + to_streamed_response_wrapper, |
| 13 | + async_to_raw_response_wrapper, |
| 14 | + async_to_streamed_response_wrapper, |
| 15 | +) |
| 16 | +from ..._base_client import make_request_options |
| 17 | +from ...types.auth.auth_context import AuthContext |
| 18 | + |
| 19 | +__all__ = ["ContextResource", "AsyncContextResource"] |
| 20 | + |
| 21 | + |
| 22 | +class ContextResource(SyncAPIResource): |
| 23 | + """Inspect the identity and authorization context for the current request.""" |
| 24 | + |
| 25 | + @cached_property |
| 26 | + def with_raw_response(self) -> ContextResourceWithRawResponse: |
| 27 | + """ |
| 28 | + This property can be used as a prefix for any HTTP method call to return |
| 29 | + the raw response object instead of the parsed content. |
| 30 | +
|
| 31 | + For more information, see https://www.github.com/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers |
| 32 | + """ |
| 33 | + return ContextResourceWithRawResponse(self) |
| 34 | + |
| 35 | + @cached_property |
| 36 | + def with_streaming_response(self) -> ContextResourceWithStreamingResponse: |
| 37 | + """ |
| 38 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 39 | +
|
| 40 | + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response |
| 41 | + """ |
| 42 | + return ContextResourceWithStreamingResponse(self) |
| 43 | + |
| 44 | + def retrieve( |
| 45 | + self, |
| 46 | + *, |
| 47 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 48 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 49 | + extra_headers: Headers | None = None, |
| 50 | + extra_query: Query | None = None, |
| 51 | + extra_body: Body | None = None, |
| 52 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 53 | + ) -> AuthContext: |
| 54 | + """ |
| 55 | + Returns the authenticated principal, organization, credential scope, and |
| 56 | + effective request scope. The response is derived from the verified request |
| 57 | + context and does not expose credential secrets. |
| 58 | + """ |
| 59 | + return self._get( |
| 60 | + "/auth/context", |
| 61 | + options=make_request_options( |
| 62 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 63 | + ), |
| 64 | + cast_to=AuthContext, |
| 65 | + ) |
| 66 | + |
| 67 | + |
| 68 | +class AsyncContextResource(AsyncAPIResource): |
| 69 | + """Inspect the identity and authorization context for the current request.""" |
| 70 | + |
| 71 | + @cached_property |
| 72 | + def with_raw_response(self) -> AsyncContextResourceWithRawResponse: |
| 73 | + """ |
| 74 | + This property can be used as a prefix for any HTTP method call to return |
| 75 | + the raw response object instead of the parsed content. |
| 76 | +
|
| 77 | + For more information, see https://www.github.com/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers |
| 78 | + """ |
| 79 | + return AsyncContextResourceWithRawResponse(self) |
| 80 | + |
| 81 | + @cached_property |
| 82 | + def with_streaming_response(self) -> AsyncContextResourceWithStreamingResponse: |
| 83 | + """ |
| 84 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 85 | +
|
| 86 | + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response |
| 87 | + """ |
| 88 | + return AsyncContextResourceWithStreamingResponse(self) |
| 89 | + |
| 90 | + async def retrieve( |
| 91 | + self, |
| 92 | + *, |
| 93 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 94 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 95 | + extra_headers: Headers | None = None, |
| 96 | + extra_query: Query | None = None, |
| 97 | + extra_body: Body | None = None, |
| 98 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 99 | + ) -> AuthContext: |
| 100 | + """ |
| 101 | + Returns the authenticated principal, organization, credential scope, and |
| 102 | + effective request scope. The response is derived from the verified request |
| 103 | + context and does not expose credential secrets. |
| 104 | + """ |
| 105 | + return await self._get( |
| 106 | + "/auth/context", |
| 107 | + options=make_request_options( |
| 108 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 109 | + ), |
| 110 | + cast_to=AuthContext, |
| 111 | + ) |
| 112 | + |
| 113 | + |
| 114 | +class ContextResourceWithRawResponse: |
| 115 | + def __init__(self, context: ContextResource) -> None: |
| 116 | + self._context = context |
| 117 | + |
| 118 | + self.retrieve = to_raw_response_wrapper( |
| 119 | + context.retrieve, |
| 120 | + ) |
| 121 | + |
| 122 | + |
| 123 | +class AsyncContextResourceWithRawResponse: |
| 124 | + def __init__(self, context: AsyncContextResource) -> None: |
| 125 | + self._context = context |
| 126 | + |
| 127 | + self.retrieve = async_to_raw_response_wrapper( |
| 128 | + context.retrieve, |
| 129 | + ) |
| 130 | + |
| 131 | + |
| 132 | +class ContextResourceWithStreamingResponse: |
| 133 | + def __init__(self, context: ContextResource) -> None: |
| 134 | + self._context = context |
| 135 | + |
| 136 | + self.retrieve = to_streamed_response_wrapper( |
| 137 | + context.retrieve, |
| 138 | + ) |
| 139 | + |
| 140 | + |
| 141 | +class AsyncContextResourceWithStreamingResponse: |
| 142 | + def __init__(self, context: AsyncContextResource) -> None: |
| 143 | + self._context = context |
| 144 | + |
| 145 | + self.retrieve = async_to_streamed_response_wrapper( |
| 146 | + context.retrieve, |
| 147 | + ) |
0 commit comments