audithub-sdk 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- audithub_sdk/__init__.py +410 -0
- audithub_sdk/api/__init__.py +22 -0
- audithub_sdk/api/admin_api.py +6117 -0
- audithub_sdk/api/configuration_api.py +520 -0
- audithub_sdk/api/custom_detectors_org_lib_api.py +1461 -0
- audithub_sdk/api/custom_detectors_std_lib_api.py +546 -0
- audithub_sdk/api/editor_languages_api.py +1383 -0
- audithub_sdk/api/generic_api.py +1275 -0
- audithub_sdk/api/hints_org_lib_api.py +2049 -0
- audithub_sdk/api/hints_std_lib_api.py +546 -0
- audithub_sdk/api/issues_api.py +2742 -0
- audithub_sdk/api/organizations_api.py +12148 -0
- audithub_sdk/api/projects_api.py +7069 -0
- audithub_sdk/api/subscriptions_api.py +1490 -0
- audithub_sdk/api/tasks_api.py +4276 -0
- audithub_sdk/api/tools_api.py +2298 -0
- audithub_sdk/api/users_api.py +2657 -0
- audithub_sdk/api/v_specs_org_lib_api.py +1461 -0
- audithub_sdk/api/v_specs_std_lib_api.py +546 -0
- audithub_sdk/api/versions_api.py +5419 -0
- audithub_sdk/api_client.py +808 -0
- audithub_sdk/api_response.py +21 -0
- audithub_sdk/configuration.py +572 -0
- audithub_sdk/exceptions.py +218 -0
- audithub_sdk/models/__init__.py +180 -0
- audithub_sdk/models/accounting_data.py +138 -0
- audithub_sdk/models/active_organization_users.py +120 -0
- audithub_sdk/models/admin_resource_patch.py +94 -0
- audithub_sdk/models/api_blacklisted_hint.py +96 -0
- audithub_sdk/models/api_key.py +89 -0
- audithub_sdk/models/api_key_base.py +87 -0
- audithub_sdk/models/api_key_with_secret.py +91 -0
- audithub_sdk/models/application_function.py +97 -0
- audithub_sdk/models/archive_input.py +104 -0
- audithub_sdk/models/artifact.py +102 -0
- audithub_sdk/models/comment.py +121 -0
- audithub_sdk/models/comment_with_mutations.py +121 -0
- audithub_sdk/models/container_resources.py +93 -0
- audithub_sdk/models/contents_inner.py +136 -0
- audithub_sdk/models/custom_detector.py +101 -0
- audithub_sdk/models/custom_detector_from_organization_library.py +99 -0
- audithub_sdk/models/custom_detector_from_standard_library.py +108 -0
- audithub_sdk/models/custom_detector_from_version.py +99 -0
- audithub_sdk/models/custom_detector_with_id.py +103 -0
- audithub_sdk/models/data.py +134 -0
- audithub_sdk/models/defi_vanguard_v2_input.py +93 -0
- audithub_sdk/models/defi_vanguard_v2_parameters.py +132 -0
- audithub_sdk/models/directory.py +111 -0
- audithub_sdk/models/editor_language.py +99 -0
- audithub_sdk/models/editor_language_with_id.py +101 -0
- audithub_sdk/models/effective_user_access_restriction.py +94 -0
- audithub_sdk/models/env_var.py +89 -0
- audithub_sdk/models/extra_function_arguments.py +107 -0
- audithub_sdk/models/favorite_project_assignment.py +87 -0
- audithub_sdk/models/file.py +101 -0
- audithub_sdk/models/file_thread_subject.py +103 -0
- audithub_sdk/models/finding_action.py +101 -0
- audithub_sdk/models/finding_action_base.py +96 -0
- audithub_sdk/models/finding_reference.py +91 -0
- audithub_sdk/models/finding_thread_subject.py +103 -0
- audithub_sdk/models/fio_data.py +113 -0
- audithub_sdk/models/fork_network_public.py +89 -0
- audithub_sdk/models/fuzzing_blacklist_entry.py +89 -0
- audithub_sdk/models/git_input.py +113 -0
- audithub_sdk/models/hint.py +101 -0
- audithub_sdk/models/hint_ad_hoc.py +113 -0
- audithub_sdk/models/hint_from_organization_library.py +99 -0
- audithub_sdk/models/hint_from_standard_library.py +108 -0
- audithub_sdk/models/hint_from_version.py +99 -0
- audithub_sdk/models/hint_with_id.py +103 -0
- audithub_sdk/models/http_validation_error.py +95 -0
- audithub_sdk/models/id_and_message_response.py +89 -0
- audithub_sdk/models/included_user_info.py +87 -0
- audithub_sdk/models/input_info.py +134 -0
- audithub_sdk/models/invitation.py +128 -0
- audithub_sdk/models/invitation_patch.py +94 -0
- audithub_sdk/models/invited_user.py +101 -0
- audithub_sdk/models/issue.py +138 -0
- audithub_sdk/models/issue_action.py +93 -0
- audithub_sdk/models/issue_batch_announce.py +88 -0
- audithub_sdk/models/issue_complete.py +167 -0
- audithub_sdk/models/issue_configuration_options.py +125 -0
- audithub_sdk/models/issue_details.py +110 -0
- audithub_sdk/models/issue_for_list.py +118 -0
- audithub_sdk/models/issue_impact.py +89 -0
- audithub_sdk/models/issue_info_base_complete.py +126 -0
- audithub_sdk/models/issue_info_editable.py +142 -0
- audithub_sdk/models/issue_likelihood.py +89 -0
- audithub_sdk/models/issue_patch.py +103 -0
- audithub_sdk/models/issue_resolution.py +100 -0
- audithub_sdk/models/issue_severity.py +89 -0
- audithub_sdk/models/issue_state_transition_function.py +110 -0
- audithub_sdk/models/issue_status.py +91 -0
- audithub_sdk/models/issue_status_transition.py +104 -0
- audithub_sdk/models/issue_thread_subject.py +99 -0
- audithub_sdk/models/issue_type.py +91 -0
- audithub_sdk/models/issue_type_info.py +87 -0
- audithub_sdk/models/machine_info.py +109 -0
- audithub_sdk/models/model_tool_input.py +102 -0
- audithub_sdk/models/model_tool_phase_parameters.py +169 -0
- audithub_sdk/models/new_invitation.py +103 -0
- audithub_sdk/models/new_organization.py +101 -0
- audithub_sdk/models/new_organization_package.py +132 -0
- audithub_sdk/models/new_organization_subscription.py +125 -0
- audithub_sdk/models/npm_project_dependency.py +103 -0
- audithub_sdk/models/onboarding_request.py +113 -0
- audithub_sdk/models/or_ca_input.py +134 -0
- audithub_sdk/models/or_ca_parameters.py +149 -0
- audithub_sdk/models/orca_value.py +138 -0
- audithub_sdk/models/organization.py +108 -0
- audithub_sdk/models/organization_access_restriction.py +101 -0
- audithub_sdk/models/organization_active_quota.py +104 -0
- audithub_sdk/models/organization_admin.py +110 -0
- audithub_sdk/models/organization_consumption.py +104 -0
- audithub_sdk/models/organization_quota.py +96 -0
- audithub_sdk/models/organization_subscription.py +135 -0
- audithub_sdk/models/package_data.py +140 -0
- audithub_sdk/models/package_subscription.py +103 -0
- audithub_sdk/models/patch_user.py +108 -0
- audithub_sdk/models/pending_finding_actions.py +99 -0
- audithub_sdk/models/picus_input.py +93 -0
- audithub_sdk/models/picus_parameters.py +111 -0
- audithub_sdk/models/picus_v2_input.py +93 -0
- audithub_sdk/models/picus_v2_parameters.py +195 -0
- audithub_sdk/models/project.py +200 -0
- audithub_sdk/models/project_admin.py +206 -0
- audithub_sdk/models/project_data.py +97 -0
- audithub_sdk/models/project_dependency.py +103 -0
- audithub_sdk/models/project_git_hub_link.py +87 -0
- audithub_sdk/models/project_info_input.py +186 -0
- audithub_sdk/models/project_info_output.py +186 -0
- audithub_sdk/models/project_thread_subject.py +97 -0
- audithub_sdk/models/project_update_response.py +93 -0
- audithub_sdk/models/psa.py +96 -0
- audithub_sdk/models/psa_message.py +94 -0
- audithub_sdk/models/public_configuration.py +216 -0
- audithub_sdk/models/put_user.py +91 -0
- audithub_sdk/models/registered_user.py +94 -0
- audithub_sdk/models/resource_patch.py +94 -0
- audithub_sdk/models/resources.py +87 -0
- audithub_sdk/models/root_model_list_union_custom_detector_from_version_custom_detector_from_standard_library_custom_detector_from_organization_library_inner.py +149 -0
- audithub_sdk/models/root_model_list_union_hint_from_version_hint_from_standard_library_hint_from_organization_library_hint_ad_hoc_inner.py +164 -0
- audithub_sdk/models/root_model_list_union_v_spec_from_version_v_spec_from_standard_library_v_spec_from_organization_library_v_spec_ad_hoc_inner.py +164 -0
- audithub_sdk/models/security_tool.py +89 -0
- audithub_sdk/models/self_onboard_request.py +94 -0
- audithub_sdk/models/source_reference.py +103 -0
- audithub_sdk/models/step_definition.py +91 -0
- audithub_sdk/models/step_resources.py +103 -0
- audithub_sdk/models/subject.py +168 -0
- audithub_sdk/models/success_and_message_response.py +93 -0
- audithub_sdk/models/task.py +184 -0
- audithub_sdk/models/task_admin.py +144 -0
- audithub_sdk/models/task_creation.py +89 -0
- audithub_sdk/models/task_fio_data.py +97 -0
- audithub_sdk/models/task_patch.py +94 -0
- audithub_sdk/models/task_resources.py +103 -0
- audithub_sdk/models/task_status.py +94 -0
- audithub_sdk/models/task_step.py +145 -0
- audithub_sdk/models/temp_version.py +93 -0
- audithub_sdk/models/thread.py +146 -0
- audithub_sdk/models/thread_comment.py +87 -0
- audithub_sdk/models/thread_patch.py +101 -0
- audithub_sdk/models/user.py +106 -0
- audithub_sdk/models/user_access_restriction.py +108 -0
- audithub_sdk/models/user_for_admin.py +108 -0
- audithub_sdk/models/user_group.py +89 -0
- audithub_sdk/models/user_information.py +89 -0
- audithub_sdk/models/user_organization_setting.py +89 -0
- audithub_sdk/models/user_patch.py +103 -0
- audithub_sdk/models/user_project_setting.py +89 -0
- audithub_sdk/models/user_thread_setting.py +89 -0
- audithub_sdk/models/user_to_organization_assignment.py +87 -0
- audithub_sdk/models/v_spec.py +101 -0
- audithub_sdk/models/v_spec_ad_hoc.py +113 -0
- audithub_sdk/models/v_spec_from_organization_library.py +99 -0
- audithub_sdk/models/v_spec_from_standard_library.py +108 -0
- audithub_sdk/models/v_spec_from_version.py +99 -0
- audithub_sdk/models/v_spec_with_id.py +103 -0
- audithub_sdk/models/validation_error.py +108 -0
- audithub_sdk/models/vanguard_detector.py +91 -0
- audithub_sdk/models/version.py +134 -0
- audithub_sdk/models/version_admin.py +142 -0
- audithub_sdk/models/version_data.py +103 -0
- audithub_sdk/models/version_patch.py +120 -0
- audithub_sdk/models/version_resources.py +103 -0
- audithub_sdk/models/zk_vanguard_input.py +93 -0
- audithub_sdk/models/zk_vanguard_parameters.py +108 -0
- audithub_sdk/models/zk_vanguard_v2_input.py +93 -0
- audithub_sdk/models/zk_vanguard_v2_parameters.py +108 -0
- audithub_sdk/py.typed +0 -0
- audithub_sdk/rest.py +199 -0
- audithub_sdk-0.1.0.dist-info/METADATA +129 -0
- audithub_sdk-0.1.0.dist-info/RECORD +197 -0
- audithub_sdk-0.1.0.dist-info/WHEEL +5 -0
- audithub_sdk-0.1.0.dist-info/top_level.txt +2 -0
- audithub_sdk_ext/__init__.py +11 -0
- audithub_sdk_ext/auth.py +207 -0
audithub_sdk_ext/auth.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"""Stable authentication helpers layered on top of the generated SDK."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import ssl
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from typing import Callable, Optional, Union
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
|
|
12
|
+
import audithub_sdk
|
|
13
|
+
from audithub_sdk import rest
|
|
14
|
+
|
|
15
|
+
VerifyTypes = Union[bool, str, ssl.SSLContext]
|
|
16
|
+
AsyncClientFactory = Callable[..., httpx.AsyncClient]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class OIDCClientCredentialsContext:
|
|
21
|
+
"""Configuration for OIDC client-credentials authentication."""
|
|
22
|
+
|
|
23
|
+
oidc_configuration_url: str
|
|
24
|
+
client_id: str
|
|
25
|
+
client_secret: str
|
|
26
|
+
scope: Optional[str] = "openid profile"
|
|
27
|
+
auth_timeout: Union[float, httpx.Timeout] = 10.0
|
|
28
|
+
verify_ssl: Optional[VerifyTypes] = None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class OIDCTokenProvider:
|
|
32
|
+
"""Fetches and caches OIDC access tokens."""
|
|
33
|
+
|
|
34
|
+
def __init__(
|
|
35
|
+
self,
|
|
36
|
+
context: OIDCClientCredentialsContext,
|
|
37
|
+
*,
|
|
38
|
+
_client_factory: Optional[AsyncClientFactory] = None,
|
|
39
|
+
) -> None:
|
|
40
|
+
self.context = context
|
|
41
|
+
self._client_factory = _client_factory or httpx.AsyncClient
|
|
42
|
+
self._access_token: Optional[str] = None
|
|
43
|
+
self._token_endpoint: Optional[str] = None
|
|
44
|
+
self._lock: Optional[asyncio.Lock] = None
|
|
45
|
+
|
|
46
|
+
async def get_token(self) -> str:
|
|
47
|
+
"""Return a cached access token, fetching one if needed."""
|
|
48
|
+
async with self._get_lock():
|
|
49
|
+
if self._access_token is not None:
|
|
50
|
+
return self._access_token
|
|
51
|
+
|
|
52
|
+
token_endpoint = await self._get_token_endpoint_locked()
|
|
53
|
+
token_request_data = {
|
|
54
|
+
"client_id": self.context.client_id,
|
|
55
|
+
"client_secret": self.context.client_secret,
|
|
56
|
+
"grant_type": "client_credentials",
|
|
57
|
+
}
|
|
58
|
+
if self.context.scope is not None:
|
|
59
|
+
token_request_data["scope"] = self.context.scope
|
|
60
|
+
|
|
61
|
+
async with self._create_http_client() as client:
|
|
62
|
+
response = await client.post(token_endpoint, data=token_request_data)
|
|
63
|
+
response.raise_for_status()
|
|
64
|
+
|
|
65
|
+
token_data = response.json()
|
|
66
|
+
access_token = token_data.get("access_token")
|
|
67
|
+
if not isinstance(access_token, str) or not access_token:
|
|
68
|
+
raise RuntimeError("OIDC token response did not include an access_token")
|
|
69
|
+
|
|
70
|
+
self._access_token = access_token
|
|
71
|
+
return access_token
|
|
72
|
+
|
|
73
|
+
async def invalidate(self) -> None:
|
|
74
|
+
"""Drop the cached access token."""
|
|
75
|
+
async with self._get_lock():
|
|
76
|
+
self._access_token = None
|
|
77
|
+
|
|
78
|
+
def _get_lock(self) -> asyncio.Lock:
|
|
79
|
+
if self._lock is None:
|
|
80
|
+
self._lock = asyncio.Lock()
|
|
81
|
+
return self._lock
|
|
82
|
+
|
|
83
|
+
async def _get_token_endpoint_locked(self) -> str:
|
|
84
|
+
if self._token_endpoint is not None:
|
|
85
|
+
return self._token_endpoint
|
|
86
|
+
|
|
87
|
+
async with self._create_http_client() as client:
|
|
88
|
+
response = await client.get(self.context.oidc_configuration_url)
|
|
89
|
+
response.raise_for_status()
|
|
90
|
+
|
|
91
|
+
configuration_data = response.json()
|
|
92
|
+
token_endpoint = configuration_data.get("token_endpoint")
|
|
93
|
+
if not isinstance(token_endpoint, str) or not token_endpoint:
|
|
94
|
+
raise RuntimeError("OIDC discovery response did not include a token_endpoint")
|
|
95
|
+
|
|
96
|
+
self._token_endpoint = token_endpoint
|
|
97
|
+
return token_endpoint
|
|
98
|
+
|
|
99
|
+
def _create_http_client(self) -> httpx.AsyncClient:
|
|
100
|
+
client_kwargs = {"timeout": self.context.auth_timeout}
|
|
101
|
+
if self.context.verify_ssl is not None:
|
|
102
|
+
client_kwargs["verify"] = self.context.verify_ssl
|
|
103
|
+
return self._client_factory(**client_kwargs)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class _AuthenticatedRESTClientObject(rest.RESTClientObject):
|
|
107
|
+
"""Generated REST client with token injection and a single 401 retry."""
|
|
108
|
+
|
|
109
|
+
def __init__(
|
|
110
|
+
self,
|
|
111
|
+
configuration: audithub_sdk.Configuration,
|
|
112
|
+
token_provider: OIDCTokenProvider,
|
|
113
|
+
*,
|
|
114
|
+
_client_factory: Optional[AsyncClientFactory] = None,
|
|
115
|
+
) -> None:
|
|
116
|
+
super().__init__(configuration)
|
|
117
|
+
self._token_provider = token_provider
|
|
118
|
+
self._client_factory = _client_factory
|
|
119
|
+
|
|
120
|
+
async def request(
|
|
121
|
+
self,
|
|
122
|
+
method,
|
|
123
|
+
url,
|
|
124
|
+
headers=None,
|
|
125
|
+
body=None,
|
|
126
|
+
post_params=None,
|
|
127
|
+
_request_timeout=None,
|
|
128
|
+
):
|
|
129
|
+
request_headers = dict(headers or {})
|
|
130
|
+
used_provider_token = "Authorization" not in request_headers
|
|
131
|
+
|
|
132
|
+
if used_provider_token:
|
|
133
|
+
request_headers["Authorization"] = f"Bearer {await self._token_provider.get_token()}"
|
|
134
|
+
|
|
135
|
+
response = await super().request(
|
|
136
|
+
method,
|
|
137
|
+
url,
|
|
138
|
+
headers=request_headers,
|
|
139
|
+
body=body,
|
|
140
|
+
post_params=post_params,
|
|
141
|
+
_request_timeout=_request_timeout,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
if response.status != 401 or not used_provider_token:
|
|
145
|
+
return response
|
|
146
|
+
|
|
147
|
+
await self._token_provider.invalidate()
|
|
148
|
+
request_headers["Authorization"] = f"Bearer {await self._token_provider.get_token()}"
|
|
149
|
+
return await super().request(
|
|
150
|
+
method,
|
|
151
|
+
url,
|
|
152
|
+
headers=request_headers,
|
|
153
|
+
body=body,
|
|
154
|
+
post_params=post_params,
|
|
155
|
+
_request_timeout=_request_timeout,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
def _create_pool_manager(self) -> httpx.AsyncClient:
|
|
159
|
+
if self._client_factory is not None:
|
|
160
|
+
client_kwargs = {
|
|
161
|
+
"trust_env": True,
|
|
162
|
+
"verify": self.ssl_context,
|
|
163
|
+
}
|
|
164
|
+
if self.proxy:
|
|
165
|
+
client_kwargs["proxy"] = httpx.Proxy(
|
|
166
|
+
url=self.proxy,
|
|
167
|
+
headers=self.proxy_headers,
|
|
168
|
+
)
|
|
169
|
+
return self._client_factory(**client_kwargs)
|
|
170
|
+
return super()._create_pool_manager()
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class AuthenticatedApiClient(audithub_sdk.ApiClient):
|
|
174
|
+
"""Generated ApiClient wired with a stable handwritten OIDC auth layer."""
|
|
175
|
+
|
|
176
|
+
def __init__(
|
|
177
|
+
self,
|
|
178
|
+
configuration: Optional[audithub_sdk.Configuration] = None,
|
|
179
|
+
*,
|
|
180
|
+
token_provider: Optional[OIDCTokenProvider] = None,
|
|
181
|
+
auth_context: Optional[OIDCClientCredentialsContext] = None,
|
|
182
|
+
header_name=None,
|
|
183
|
+
header_value=None,
|
|
184
|
+
cookie=None,
|
|
185
|
+
_oidc_client_factory: Optional[AsyncClientFactory] = None,
|
|
186
|
+
_rest_client_factory: Optional[AsyncClientFactory] = None,
|
|
187
|
+
) -> None:
|
|
188
|
+
if token_provider is None:
|
|
189
|
+
if auth_context is None:
|
|
190
|
+
raise ValueError("AuthenticatedApiClient requires token_provider or auth_context")
|
|
191
|
+
token_provider = OIDCTokenProvider(
|
|
192
|
+
auth_context,
|
|
193
|
+
_client_factory=_oidc_client_factory,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
super().__init__(
|
|
197
|
+
configuration=configuration,
|
|
198
|
+
header_name=header_name,
|
|
199
|
+
header_value=header_value,
|
|
200
|
+
cookie=cookie,
|
|
201
|
+
)
|
|
202
|
+
self.token_provider = token_provider
|
|
203
|
+
self.rest_client = _AuthenticatedRESTClientObject(
|
|
204
|
+
self.configuration,
|
|
205
|
+
token_provider,
|
|
206
|
+
_client_factory=_rest_client_factory,
|
|
207
|
+
)
|