-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathclient_authentication.py
More file actions
173 lines (149 loc) · 7.09 KB
/
client_authentication.py
File metadata and controls
173 lines (149 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from .basesdk import BaseSDK
from glean.api_client import errors, models, utils
from glean.api_client._hooks import HookContext
from glean.api_client.types import OptionalNullable, UNSET
from glean.api_client.utils import get_security_from_env
from glean.api_client.utils.unmarshal_json_response import unmarshal_json_response
from typing import Mapping, Optional
class ClientAuthentication(BaseSDK):
def create_token(
self,
*,
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> models.CreateAuthTokenResponse:
r"""Create authentication token
Creates an authentication token for the authenticated user. These are
specifically intended to be used with the [Web SDK](https://developers.glean.com/web).
Note: The tokens generated from this endpoint are **not** valid tokens
for use with the Client API (e.g. `/rest/api/v1/*`).
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = None
url_variables = None
if timeout_ms is None:
timeout_ms = self.sdk_configuration.timeout_ms
if server_url is not None:
base_url = server_url
else:
base_url = self._get_url(base_url, url_variables)
req = self._build_request(
method="POST",
path="/rest/api/v1/createauthtoken",
base_url=base_url,
url_variables=url_variables,
request=None,
request_body_required=False,
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value="application/json",
http_headers=http_headers,
security=self.sdk_configuration.security,
timeout_ms=timeout_ms,
)
if retries == UNSET:
if self.sdk_configuration.retry_config is not UNSET:
retries = self.sdk_configuration.retry_config
retry_config = None
if isinstance(retries, utils.RetryConfig):
retry_config = (retries, ["429", "500", "502", "503", "504"])
http_res = self.do_request(
hook_ctx=HookContext(
config=self.sdk_configuration,
base_url=base_url or "",
operation_id="createauthtoken",
oauth2_scopes=[],
security_source=get_security_from_env(
self.sdk_configuration.security, models.Security
),
),
request=req,
error_status_codes=["400", "401", "429", "4XX", "5XX"],
retry_config=retry_config,
)
if utils.match_response(http_res, "200", "application/json"):
return unmarshal_json_response(models.CreateAuthTokenResponse, http_res)
if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"):
http_res_text = utils.stream_to_text(http_res)
raise errors.GleanError("API error occurred", http_res, http_res_text)
if utils.match_response(http_res, "5XX", "*"):
http_res_text = utils.stream_to_text(http_res)
raise errors.GleanError("API error occurred", http_res, http_res_text)
raise errors.GleanError("Unexpected response received", http_res)
async def create_token_async(
self,
*,
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> models.CreateAuthTokenResponse:
r"""Create authentication token
Creates an authentication token for the authenticated user. These are
specifically intended to be used with the [Web SDK](https://developers.glean.com/web).
Note: The tokens generated from this endpoint are **not** valid tokens
for use with the Client API (e.g. `/rest/api/v1/*`).
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = None
url_variables = None
if timeout_ms is None:
timeout_ms = self.sdk_configuration.timeout_ms
if server_url is not None:
base_url = server_url
else:
base_url = self._get_url(base_url, url_variables)
req = self._build_request_async(
method="POST",
path="/rest/api/v1/createauthtoken",
base_url=base_url,
url_variables=url_variables,
request=None,
request_body_required=False,
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value="application/json",
http_headers=http_headers,
security=self.sdk_configuration.security,
timeout_ms=timeout_ms,
)
if retries == UNSET:
if self.sdk_configuration.retry_config is not UNSET:
retries = self.sdk_configuration.retry_config
retry_config = None
if isinstance(retries, utils.RetryConfig):
retry_config = (retries, ["429", "500", "502", "503", "504"])
http_res = await self.do_request_async(
hook_ctx=HookContext(
config=self.sdk_configuration,
base_url=base_url or "",
operation_id="createauthtoken",
oauth2_scopes=[],
security_source=get_security_from_env(
self.sdk_configuration.security, models.Security
),
),
request=req,
error_status_codes=["400", "401", "429", "4XX", "5XX"],
retry_config=retry_config,
)
if utils.match_response(http_res, "200", "application/json"):
return unmarshal_json_response(models.CreateAuthTokenResponse, http_res)
if utils.match_response(http_res, ["400", "401", "429", "4XX"], "*"):
http_res_text = await utils.stream_to_text_async(http_res)
raise errors.GleanError("API error occurred", http_res, http_res_text)
if utils.match_response(http_res, "5XX", "*"):
http_res_text = await utils.stream_to_text_async(http_res)
raise errors.GleanError("API error occurred", http_res, http_res_text)
raise errors.GleanError("Unexpected response received", http_res)