hackagent 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.
Files changed (117) hide show
  1. hackagent/__init__.py +23 -0
  2. hackagent/agent.py +193 -0
  3. hackagent/api/__init__.py +1 -0
  4. hackagent/api/agent/__init__.py +1 -0
  5. hackagent/api/agent/agent_create.py +340 -0
  6. hackagent/api/agent/agent_destroy.py +136 -0
  7. hackagent/api/agent/agent_list.py +234 -0
  8. hackagent/api/agent/agent_partial_update.py +354 -0
  9. hackagent/api/agent/agent_retrieve.py +227 -0
  10. hackagent/api/agent/agent_update.py +354 -0
  11. hackagent/api/attack/__init__.py +1 -0
  12. hackagent/api/attack/attack_create.py +264 -0
  13. hackagent/api/attack/attack_destroy.py +140 -0
  14. hackagent/api/attack/attack_list.py +242 -0
  15. hackagent/api/attack/attack_partial_update.py +278 -0
  16. hackagent/api/attack/attack_retrieve.py +235 -0
  17. hackagent/api/attack/attack_update.py +278 -0
  18. hackagent/api/key/__init__.py +1 -0
  19. hackagent/api/key/key_create.py +168 -0
  20. hackagent/api/key/key_destroy.py +97 -0
  21. hackagent/api/key/key_list.py +158 -0
  22. hackagent/api/key/key_retrieve.py +150 -0
  23. hackagent/api/prompt/__init__.py +1 -0
  24. hackagent/api/prompt/prompt_create.py +160 -0
  25. hackagent/api/prompt/prompt_destroy.py +98 -0
  26. hackagent/api/prompt/prompt_list.py +173 -0
  27. hackagent/api/prompt/prompt_partial_update.py +174 -0
  28. hackagent/api/prompt/prompt_retrieve.py +151 -0
  29. hackagent/api/prompt/prompt_update.py +174 -0
  30. hackagent/api/result/__init__.py +1 -0
  31. hackagent/api/result/result_create.py +160 -0
  32. hackagent/api/result/result_destroy.py +98 -0
  33. hackagent/api/result/result_list.py +233 -0
  34. hackagent/api/result/result_partial_update.py +178 -0
  35. hackagent/api/result/result_retrieve.py +151 -0
  36. hackagent/api/result/result_trace_create.py +178 -0
  37. hackagent/api/result/result_update.py +174 -0
  38. hackagent/api/run/__init__.py +1 -0
  39. hackagent/api/run/run_create.py +172 -0
  40. hackagent/api/run/run_destroy.py +104 -0
  41. hackagent/api/run/run_list.py +260 -0
  42. hackagent/api/run/run_partial_update.py +186 -0
  43. hackagent/api/run/run_result_create.py +178 -0
  44. hackagent/api/run/run_retrieve.py +163 -0
  45. hackagent/api/run/run_run_tests_create.py +172 -0
  46. hackagent/api/run/run_update.py +186 -0
  47. hackagent/attacks/AdvPrefix/README.md +7 -0
  48. hackagent/attacks/AdvPrefix/__init__.py +0 -0
  49. hackagent/attacks/AdvPrefix/completer.py +438 -0
  50. hackagent/attacks/AdvPrefix/config.py +59 -0
  51. hackagent/attacks/AdvPrefix/preprocessing.py +521 -0
  52. hackagent/attacks/AdvPrefix/scorer.py +259 -0
  53. hackagent/attacks/AdvPrefix/scorer_parser.py +498 -0
  54. hackagent/attacks/AdvPrefix/selector.py +246 -0
  55. hackagent/attacks/AdvPrefix/step1_generate.py +324 -0
  56. hackagent/attacks/AdvPrefix/step4_compute_ce.py +293 -0
  57. hackagent/attacks/AdvPrefix/step6_get_completions.py +387 -0
  58. hackagent/attacks/AdvPrefix/step7_evaluate_responses.py +289 -0
  59. hackagent/attacks/AdvPrefix/step8_aggregate_evaluations.py +177 -0
  60. hackagent/attacks/AdvPrefix/step9_select_prefixes.py +59 -0
  61. hackagent/attacks/AdvPrefix/utils.py +192 -0
  62. hackagent/attacks/__init__.py +6 -0
  63. hackagent/attacks/advprefix.py +1136 -0
  64. hackagent/attacks/base.py +50 -0
  65. hackagent/attacks/strategies.py +539 -0
  66. hackagent/branding.py +143 -0
  67. hackagent/client.py +328 -0
  68. hackagent/errors.py +31 -0
  69. hackagent/logger.py +67 -0
  70. hackagent/models/__init__.py +71 -0
  71. hackagent/models/agent.py +240 -0
  72. hackagent/models/agent_request.py +169 -0
  73. hackagent/models/agent_type_enum.py +12 -0
  74. hackagent/models/attack.py +154 -0
  75. hackagent/models/attack_request.py +82 -0
  76. hackagent/models/evaluation_status_enum.py +14 -0
  77. hackagent/models/organization_minimal.py +68 -0
  78. hackagent/models/paginated_agent_list.py +123 -0
  79. hackagent/models/paginated_attack_list.py +123 -0
  80. hackagent/models/paginated_prompt_list.py +123 -0
  81. hackagent/models/paginated_result_list.py +123 -0
  82. hackagent/models/paginated_run_list.py +123 -0
  83. hackagent/models/paginated_user_api_key_list.py +123 -0
  84. hackagent/models/patched_agent_request.py +176 -0
  85. hackagent/models/patched_attack_request.py +92 -0
  86. hackagent/models/patched_prompt_request.py +162 -0
  87. hackagent/models/patched_result_request.py +237 -0
  88. hackagent/models/patched_run_request.py +138 -0
  89. hackagent/models/prompt.py +226 -0
  90. hackagent/models/prompt_request.py +155 -0
  91. hackagent/models/result.py +294 -0
  92. hackagent/models/result_list_evaluation_status.py +14 -0
  93. hackagent/models/result_request.py +232 -0
  94. hackagent/models/run.py +233 -0
  95. hackagent/models/run_list_status.py +12 -0
  96. hackagent/models/run_request.py +133 -0
  97. hackagent/models/status_enum.py +12 -0
  98. hackagent/models/step_type_enum.py +14 -0
  99. hackagent/models/trace.py +121 -0
  100. hackagent/models/trace_request.py +94 -0
  101. hackagent/models/user_api_key.py +201 -0
  102. hackagent/models/user_api_key_request.py +73 -0
  103. hackagent/models/user_profile_minimal.py +76 -0
  104. hackagent/py.typed +1 -0
  105. hackagent/router/__init__.py +11 -0
  106. hackagent/router/adapters/__init__.py +5 -0
  107. hackagent/router/adapters/google_adk.py +658 -0
  108. hackagent/router/adapters/litellm_adapter.py +290 -0
  109. hackagent/router/base.py +48 -0
  110. hackagent/router/router.py +753 -0
  111. hackagent/types.py +46 -0
  112. hackagent/utils.py +61 -0
  113. hackagent/vulnerabilities/__init__.py +0 -0
  114. hackagent-0.1.0.dist-info/LICENSE +202 -0
  115. hackagent-0.1.0.dist-info/METADATA +173 -0
  116. hackagent-0.1.0.dist-info/RECORD +117 -0
  117. hackagent-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,235 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, Optional, Union
3
+ from uuid import UUID
4
+
5
+ import httpx
6
+
7
+ from ... import errors
8
+ from ...client import AuthenticatedClient, Client
9
+ from ...models.attack import Attack
10
+ from ...types import Response
11
+
12
+
13
+ def _get_kwargs(
14
+ id: UUID,
15
+ ) -> dict[str, Any]:
16
+ _kwargs: dict[str, Any] = {
17
+ "method": "get",
18
+ "url": f"/api/attack/{id}",
19
+ }
20
+
21
+ return _kwargs
22
+
23
+
24
+ def _parse_response(
25
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
26
+ ) -> Optional[Attack]:
27
+ if response.status_code == 200:
28
+ response_200 = Attack.from_dict(response.json())
29
+
30
+ return response_200
31
+ if client.raise_on_unexpected_status:
32
+ raise errors.UnexpectedStatus(response.status_code, response.content)
33
+ else:
34
+ return None
35
+
36
+
37
+ def _build_response(
38
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
39
+ ) -> Response[Attack]:
40
+ return Response(
41
+ status_code=HTTPStatus(response.status_code),
42
+ content=response.content,
43
+ headers=response.headers,
44
+ parsed=_parse_response(client=client, response=response),
45
+ )
46
+
47
+
48
+ def sync_detailed(
49
+ id: UUID,
50
+ *,
51
+ client: AuthenticatedClient,
52
+ ) -> Response[Attack]:
53
+ """Manages Attack configurations through standard CRUD operations.
54
+
55
+ This ViewSet allows clients to:
56
+ - Create new Attack configurations.
57
+ - List existing Attack configurations (with filtering based on user/org).
58
+ - Retrieve details of a specific Attack configuration.
59
+ - Update an existing Attack configuration.
60
+ - Delete an Attack configuration.
61
+
62
+ The actual execution of an attack based on these configurations, and the
63
+ management of run statuses or results, are handled by other parts of the API
64
+ (e.g., potentially a RunViewSet or similar).
65
+
66
+ Attributes:
67
+ queryset: The base queryset, retrieving all Attack objects with related
68
+ entities (agent, owner, organization) pre-fetched.
69
+ serializer_class: The serializer (`AttackSerializer`) used for data
70
+ conversion for Attack configurations.
71
+ authentication_classes: List of authentication backends used.
72
+ permission_classes: List of permission enforcement classes.
73
+ parser_classes: List of parsers for request data (JSONParser).
74
+ lookup_field: The model field used for looking up individual instances ('id').
75
+
76
+ Args:
77
+ id (UUID):
78
+
79
+ Raises:
80
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
81
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
82
+
83
+ Returns:
84
+ Response[Attack]
85
+ """
86
+
87
+ kwargs = _get_kwargs(
88
+ id=id,
89
+ )
90
+
91
+ response = client.get_httpx_client().request(
92
+ **kwargs,
93
+ )
94
+
95
+ return _build_response(client=client, response=response)
96
+
97
+
98
+ def sync(
99
+ id: UUID,
100
+ *,
101
+ client: AuthenticatedClient,
102
+ ) -> Optional[Attack]:
103
+ """Manages Attack configurations through standard CRUD operations.
104
+
105
+ This ViewSet allows clients to:
106
+ - Create new Attack configurations.
107
+ - List existing Attack configurations (with filtering based on user/org).
108
+ - Retrieve details of a specific Attack configuration.
109
+ - Update an existing Attack configuration.
110
+ - Delete an Attack configuration.
111
+
112
+ The actual execution of an attack based on these configurations, and the
113
+ management of run statuses or results, are handled by other parts of the API
114
+ (e.g., potentially a RunViewSet or similar).
115
+
116
+ Attributes:
117
+ queryset: The base queryset, retrieving all Attack objects with related
118
+ entities (agent, owner, organization) pre-fetched.
119
+ serializer_class: The serializer (`AttackSerializer`) used for data
120
+ conversion for Attack configurations.
121
+ authentication_classes: List of authentication backends used.
122
+ permission_classes: List of permission enforcement classes.
123
+ parser_classes: List of parsers for request data (JSONParser).
124
+ lookup_field: The model field used for looking up individual instances ('id').
125
+
126
+ Args:
127
+ id (UUID):
128
+
129
+ Raises:
130
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
131
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
132
+
133
+ Returns:
134
+ Attack
135
+ """
136
+
137
+ return sync_detailed(
138
+ id=id,
139
+ client=client,
140
+ ).parsed
141
+
142
+
143
+ async def asyncio_detailed(
144
+ id: UUID,
145
+ *,
146
+ client: AuthenticatedClient,
147
+ ) -> Response[Attack]:
148
+ """Manages Attack configurations through standard CRUD operations.
149
+
150
+ This ViewSet allows clients to:
151
+ - Create new Attack configurations.
152
+ - List existing Attack configurations (with filtering based on user/org).
153
+ - Retrieve details of a specific Attack configuration.
154
+ - Update an existing Attack configuration.
155
+ - Delete an Attack configuration.
156
+
157
+ The actual execution of an attack based on these configurations, and the
158
+ management of run statuses or results, are handled by other parts of the API
159
+ (e.g., potentially a RunViewSet or similar).
160
+
161
+ Attributes:
162
+ queryset: The base queryset, retrieving all Attack objects with related
163
+ entities (agent, owner, organization) pre-fetched.
164
+ serializer_class: The serializer (`AttackSerializer`) used for data
165
+ conversion for Attack configurations.
166
+ authentication_classes: List of authentication backends used.
167
+ permission_classes: List of permission enforcement classes.
168
+ parser_classes: List of parsers for request data (JSONParser).
169
+ lookup_field: The model field used for looking up individual instances ('id').
170
+
171
+ Args:
172
+ id (UUID):
173
+
174
+ Raises:
175
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
176
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
177
+
178
+ Returns:
179
+ Response[Attack]
180
+ """
181
+
182
+ kwargs = _get_kwargs(
183
+ id=id,
184
+ )
185
+
186
+ response = await client.get_async_httpx_client().request(**kwargs)
187
+
188
+ return _build_response(client=client, response=response)
189
+
190
+
191
+ async def asyncio(
192
+ id: UUID,
193
+ *,
194
+ client: AuthenticatedClient,
195
+ ) -> Optional[Attack]:
196
+ """Manages Attack configurations through standard CRUD operations.
197
+
198
+ This ViewSet allows clients to:
199
+ - Create new Attack configurations.
200
+ - List existing Attack configurations (with filtering based on user/org).
201
+ - Retrieve details of a specific Attack configuration.
202
+ - Update an existing Attack configuration.
203
+ - Delete an Attack configuration.
204
+
205
+ The actual execution of an attack based on these configurations, and the
206
+ management of run statuses or results, are handled by other parts of the API
207
+ (e.g., potentially a RunViewSet or similar).
208
+
209
+ Attributes:
210
+ queryset: The base queryset, retrieving all Attack objects with related
211
+ entities (agent, owner, organization) pre-fetched.
212
+ serializer_class: The serializer (`AttackSerializer`) used for data
213
+ conversion for Attack configurations.
214
+ authentication_classes: List of authentication backends used.
215
+ permission_classes: List of permission enforcement classes.
216
+ parser_classes: List of parsers for request data (JSONParser).
217
+ lookup_field: The model field used for looking up individual instances ('id').
218
+
219
+ Args:
220
+ id (UUID):
221
+
222
+ Raises:
223
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
224
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
225
+
226
+ Returns:
227
+ Attack
228
+ """
229
+
230
+ return (
231
+ await asyncio_detailed(
232
+ id=id,
233
+ client=client,
234
+ )
235
+ ).parsed
@@ -0,0 +1,278 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, Optional, Union
3
+ from uuid import UUID
4
+
5
+ import httpx
6
+
7
+ from ... import errors
8
+ from ...client import AuthenticatedClient, Client
9
+ from ...models.attack import Attack
10
+ from ...models.attack_request import AttackRequest
11
+ from ...types import Response
12
+
13
+
14
+ def _get_kwargs(
15
+ id: UUID,
16
+ *,
17
+ body: AttackRequest,
18
+ ) -> dict[str, Any]:
19
+ headers: dict[str, Any] = {}
20
+
21
+ _kwargs: dict[str, Any] = {
22
+ "method": "put",
23
+ "url": f"/api/attack/{id}",
24
+ }
25
+
26
+ _body = body.to_dict()
27
+
28
+ _kwargs["json"] = _body
29
+ headers["Content-Type"] = "application/json"
30
+
31
+ _kwargs["headers"] = headers
32
+ return _kwargs
33
+
34
+
35
+ def _parse_response(
36
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
37
+ ) -> Optional[Attack]:
38
+ if response.status_code == 200:
39
+ response_200 = Attack.from_dict(response.json())
40
+
41
+ return response_200
42
+ if client.raise_on_unexpected_status:
43
+ raise errors.UnexpectedStatus(response.status_code, response.content)
44
+ else:
45
+ return None
46
+
47
+
48
+ def _build_response(
49
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
50
+ ) -> Response[Attack]:
51
+ return Response(
52
+ status_code=HTTPStatus(response.status_code),
53
+ content=response.content,
54
+ headers=response.headers,
55
+ parsed=_parse_response(client=client, response=response),
56
+ )
57
+
58
+
59
+ def sync_detailed(
60
+ id: UUID,
61
+ *,
62
+ client: AuthenticatedClient,
63
+ body: AttackRequest,
64
+ ) -> Response[Attack]:
65
+ """Manages Attack configurations through standard CRUD operations.
66
+
67
+ This ViewSet allows clients to:
68
+ - Create new Attack configurations.
69
+ - List existing Attack configurations (with filtering based on user/org).
70
+ - Retrieve details of a specific Attack configuration.
71
+ - Update an existing Attack configuration.
72
+ - Delete an Attack configuration.
73
+
74
+ The actual execution of an attack based on these configurations, and the
75
+ management of run statuses or results, are handled by other parts of the API
76
+ (e.g., potentially a RunViewSet or similar).
77
+
78
+ Attributes:
79
+ queryset: The base queryset, retrieving all Attack objects with related
80
+ entities (agent, owner, organization) pre-fetched.
81
+ serializer_class: The serializer (`AttackSerializer`) used for data
82
+ conversion for Attack configurations.
83
+ authentication_classes: List of authentication backends used.
84
+ permission_classes: List of permission enforcement classes.
85
+ parser_classes: List of parsers for request data (JSONParser).
86
+ lookup_field: The model field used for looking up individual instances ('id').
87
+
88
+ Args:
89
+ id (UUID):
90
+ body (AttackRequest): Serializer for the Attack model, which represents an Attack
91
+ configuration.
92
+
93
+ Handles the conversion of Attack configuration instances to JSON (and vice-versa)
94
+ for API requests and responses. It includes read-only fields for related
95
+ object names (like agent_name, owner_username) for convenience in API outputs.
96
+
97
+ Raises:
98
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
99
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
100
+
101
+ Returns:
102
+ Response[Attack]
103
+ """
104
+
105
+ kwargs = _get_kwargs(
106
+ id=id,
107
+ body=body,
108
+ )
109
+
110
+ response = client.get_httpx_client().request(
111
+ **kwargs,
112
+ )
113
+
114
+ return _build_response(client=client, response=response)
115
+
116
+
117
+ def sync(
118
+ id: UUID,
119
+ *,
120
+ client: AuthenticatedClient,
121
+ body: AttackRequest,
122
+ ) -> Optional[Attack]:
123
+ """Manages Attack configurations through standard CRUD operations.
124
+
125
+ This ViewSet allows clients to:
126
+ - Create new Attack configurations.
127
+ - List existing Attack configurations (with filtering based on user/org).
128
+ - Retrieve details of a specific Attack configuration.
129
+ - Update an existing Attack configuration.
130
+ - Delete an Attack configuration.
131
+
132
+ The actual execution of an attack based on these configurations, and the
133
+ management of run statuses or results, are handled by other parts of the API
134
+ (e.g., potentially a RunViewSet or similar).
135
+
136
+ Attributes:
137
+ queryset: The base queryset, retrieving all Attack objects with related
138
+ entities (agent, owner, organization) pre-fetched.
139
+ serializer_class: The serializer (`AttackSerializer`) used for data
140
+ conversion for Attack configurations.
141
+ authentication_classes: List of authentication backends used.
142
+ permission_classes: List of permission enforcement classes.
143
+ parser_classes: List of parsers for request data (JSONParser).
144
+ lookup_field: The model field used for looking up individual instances ('id').
145
+
146
+ Args:
147
+ id (UUID):
148
+ body (AttackRequest): Serializer for the Attack model, which represents an Attack
149
+ configuration.
150
+
151
+ Handles the conversion of Attack configuration instances to JSON (and vice-versa)
152
+ for API requests and responses. It includes read-only fields for related
153
+ object names (like agent_name, owner_username) for convenience in API outputs.
154
+
155
+ Raises:
156
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
157
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
158
+
159
+ Returns:
160
+ Attack
161
+ """
162
+
163
+ return sync_detailed(
164
+ id=id,
165
+ client=client,
166
+ body=body,
167
+ ).parsed
168
+
169
+
170
+ async def asyncio_detailed(
171
+ id: UUID,
172
+ *,
173
+ client: AuthenticatedClient,
174
+ body: AttackRequest,
175
+ ) -> Response[Attack]:
176
+ """Manages Attack configurations through standard CRUD operations.
177
+
178
+ This ViewSet allows clients to:
179
+ - Create new Attack configurations.
180
+ - List existing Attack configurations (with filtering based on user/org).
181
+ - Retrieve details of a specific Attack configuration.
182
+ - Update an existing Attack configuration.
183
+ - Delete an Attack configuration.
184
+
185
+ The actual execution of an attack based on these configurations, and the
186
+ management of run statuses or results, are handled by other parts of the API
187
+ (e.g., potentially a RunViewSet or similar).
188
+
189
+ Attributes:
190
+ queryset: The base queryset, retrieving all Attack objects with related
191
+ entities (agent, owner, organization) pre-fetched.
192
+ serializer_class: The serializer (`AttackSerializer`) used for data
193
+ conversion for Attack configurations.
194
+ authentication_classes: List of authentication backends used.
195
+ permission_classes: List of permission enforcement classes.
196
+ parser_classes: List of parsers for request data (JSONParser).
197
+ lookup_field: The model field used for looking up individual instances ('id').
198
+
199
+ Args:
200
+ id (UUID):
201
+ body (AttackRequest): Serializer for the Attack model, which represents an Attack
202
+ configuration.
203
+
204
+ Handles the conversion of Attack configuration instances to JSON (and vice-versa)
205
+ for API requests and responses. It includes read-only fields for related
206
+ object names (like agent_name, owner_username) for convenience in API outputs.
207
+
208
+ Raises:
209
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
210
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
211
+
212
+ Returns:
213
+ Response[Attack]
214
+ """
215
+
216
+ kwargs = _get_kwargs(
217
+ id=id,
218
+ body=body,
219
+ )
220
+
221
+ response = await client.get_async_httpx_client().request(**kwargs)
222
+
223
+ return _build_response(client=client, response=response)
224
+
225
+
226
+ async def asyncio(
227
+ id: UUID,
228
+ *,
229
+ client: AuthenticatedClient,
230
+ body: AttackRequest,
231
+ ) -> Optional[Attack]:
232
+ """Manages Attack configurations through standard CRUD operations.
233
+
234
+ This ViewSet allows clients to:
235
+ - Create new Attack configurations.
236
+ - List existing Attack configurations (with filtering based on user/org).
237
+ - Retrieve details of a specific Attack configuration.
238
+ - Update an existing Attack configuration.
239
+ - Delete an Attack configuration.
240
+
241
+ The actual execution of an attack based on these configurations, and the
242
+ management of run statuses or results, are handled by other parts of the API
243
+ (e.g., potentially a RunViewSet or similar).
244
+
245
+ Attributes:
246
+ queryset: The base queryset, retrieving all Attack objects with related
247
+ entities (agent, owner, organization) pre-fetched.
248
+ serializer_class: The serializer (`AttackSerializer`) used for data
249
+ conversion for Attack configurations.
250
+ authentication_classes: List of authentication backends used.
251
+ permission_classes: List of permission enforcement classes.
252
+ parser_classes: List of parsers for request data (JSONParser).
253
+ lookup_field: The model field used for looking up individual instances ('id').
254
+
255
+ Args:
256
+ id (UUID):
257
+ body (AttackRequest): Serializer for the Attack model, which represents an Attack
258
+ configuration.
259
+
260
+ Handles the conversion of Attack configuration instances to JSON (and vice-versa)
261
+ for API requests and responses. It includes read-only fields for related
262
+ object names (like agent_name, owner_username) for convenience in API outputs.
263
+
264
+ Raises:
265
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
266
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
267
+
268
+ Returns:
269
+ Attack
270
+ """
271
+
272
+ return (
273
+ await asyncio_detailed(
274
+ id=id,
275
+ client=client,
276
+ body=body,
277
+ )
278
+ ).parsed
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,168 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, Optional, Union
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.user_api_key import UserAPIKey
9
+ from ...models.user_api_key_request import UserAPIKeyRequest
10
+ from ...types import Response
11
+
12
+
13
+ def _get_kwargs(
14
+ *,
15
+ body: UserAPIKeyRequest,
16
+ ) -> dict[str, Any]:
17
+ headers: dict[str, Any] = {}
18
+
19
+ _kwargs: dict[str, Any] = {
20
+ "method": "post",
21
+ "url": "/api/key",
22
+ }
23
+
24
+ _body = body.to_dict()
25
+
26
+ _kwargs["json"] = _body
27
+ headers["Content-Type"] = "application/json"
28
+
29
+ _kwargs["headers"] = headers
30
+ return _kwargs
31
+
32
+
33
+ def _parse_response(
34
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
35
+ ) -> Optional[UserAPIKey]:
36
+ if response.status_code == 201:
37
+ response_201 = UserAPIKey.from_dict(response.json())
38
+
39
+ return response_201
40
+ if client.raise_on_unexpected_status:
41
+ raise errors.UnexpectedStatus(response.status_code, response.content)
42
+ else:
43
+ return None
44
+
45
+
46
+ def _build_response(
47
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
48
+ ) -> Response[UserAPIKey]:
49
+ return Response(
50
+ status_code=HTTPStatus(response.status_code),
51
+ content=response.content,
52
+ headers=response.headers,
53
+ parsed=_parse_response(client=client, response=response),
54
+ )
55
+
56
+
57
+ def sync_detailed(
58
+ *,
59
+ client: AuthenticatedClient,
60
+ body: UserAPIKeyRequest,
61
+ ) -> Response[UserAPIKey]:
62
+ """ViewSet for managing User API Keys.
63
+
64
+ Args:
65
+ body (UserAPIKeyRequest): Serializer for User API Keys.
66
+ Exposes read-only information about the key, including its prefix.
67
+ The full key is only shown once upon creation by the ViewSet.
68
+
69
+ Raises:
70
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
71
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
72
+
73
+ Returns:
74
+ Response[UserAPIKey]
75
+ """
76
+
77
+ kwargs = _get_kwargs(
78
+ body=body,
79
+ )
80
+
81
+ response = client.get_httpx_client().request(
82
+ **kwargs,
83
+ )
84
+
85
+ return _build_response(client=client, response=response)
86
+
87
+
88
+ def sync(
89
+ *,
90
+ client: AuthenticatedClient,
91
+ body: UserAPIKeyRequest,
92
+ ) -> Optional[UserAPIKey]:
93
+ """ViewSet for managing User API Keys.
94
+
95
+ Args:
96
+ body (UserAPIKeyRequest): Serializer for User API Keys.
97
+ Exposes read-only information about the key, including its prefix.
98
+ The full key is only shown once upon creation by the ViewSet.
99
+
100
+ Raises:
101
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
102
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
103
+
104
+ Returns:
105
+ UserAPIKey
106
+ """
107
+
108
+ return sync_detailed(
109
+ client=client,
110
+ body=body,
111
+ ).parsed
112
+
113
+
114
+ async def asyncio_detailed(
115
+ *,
116
+ client: AuthenticatedClient,
117
+ body: UserAPIKeyRequest,
118
+ ) -> Response[UserAPIKey]:
119
+ """ViewSet for managing User API Keys.
120
+
121
+ Args:
122
+ body (UserAPIKeyRequest): Serializer for User API Keys.
123
+ Exposes read-only information about the key, including its prefix.
124
+ The full key is only shown once upon creation by the ViewSet.
125
+
126
+ Raises:
127
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
128
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
129
+
130
+ Returns:
131
+ Response[UserAPIKey]
132
+ """
133
+
134
+ kwargs = _get_kwargs(
135
+ body=body,
136
+ )
137
+
138
+ response = await client.get_async_httpx_client().request(**kwargs)
139
+
140
+ return _build_response(client=client, response=response)
141
+
142
+
143
+ async def asyncio(
144
+ *,
145
+ client: AuthenticatedClient,
146
+ body: UserAPIKeyRequest,
147
+ ) -> Optional[UserAPIKey]:
148
+ """ViewSet for managing User API Keys.
149
+
150
+ Args:
151
+ body (UserAPIKeyRequest): Serializer for User API Keys.
152
+ Exposes read-only information about the key, including its prefix.
153
+ The full key is only shown once upon creation by the ViewSet.
154
+
155
+ Raises:
156
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
157
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
158
+
159
+ Returns:
160
+ UserAPIKey
161
+ """
162
+
163
+ return (
164
+ await asyncio_detailed(
165
+ client=client,
166
+ body=body,
167
+ )
168
+ ).parsed