Skip to content

Commit c35dc9c

Browse files
author
Krzysztof Godlewski
committed
Add neptune_storage_api
1 parent d5b9ab9 commit c35dc9c

17 files changed

+1168
-2
lines changed

openapi-generator-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ post_hooks:
44
- "ruff check . --fix"
55
- "ruff format "
66
- "isort ."
7-
- "echo >> py.typed"
7+
- "echo -n > py.typed"
88
content_type_overrides:
99
application/x-protobuf: application/octet-stream

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ exclude = ["src/neptune_api/proto", "src/neptune_retrieval_api/proto"]
8686
select = ["F", "UP"]
8787

8888
[tool.mypy]
89-
files = ['src/neptune_api', 'src/neptune_retrieval_api']
89+
files = ['src/neptune_api', 'src/neptune_retrieval_api', 'src/neptune_storage_api']
9090
mypy_path = "stubs"
9191
install_types = "True"
9292
non_interactive = "True"

scripts/update-storagebridge.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
if [ ! -f "storagebridge_swagger.json" ]; then
4+
echo "storagebridge_swagger.json not found. Make sure it's in CWD when running the script"
5+
exit 1
6+
fi
7+
8+
# Show every command and exit on error
9+
set -ex
10+
11+
## Preserve specific files
12+
mkdir -p tmp
13+
14+
# Modify the Swagger JSON to support application/x-protobuf
15+
jq '
16+
.paths |= with_entries(
17+
.value |= with_entries(
18+
if .value.produces? and (.value.produces | index("application/json")) and (.value.produces | index("application/x-protobuf"))
19+
then
20+
.value.produces = ["application/x-protobuf"]
21+
else
22+
.
23+
end
24+
)
25+
)
26+
' storagebridge_swagger.json > tmp/storagebridge_swagger.json && mv tmp/storagebridge_swagger.json storagebridge_swagger.json
27+
28+
jq '
29+
.paths |= with_entries(
30+
.value |= with_entries(
31+
if .value.produces? and (.value.produces | index("application/x-protobuf"))
32+
then
33+
.value.responses."200".schema = {
34+
"type": "string",
35+
"format": "binary"
36+
}
37+
else
38+
.
39+
end
40+
)
41+
)
42+
' storagebridge_swagger.json > tmp/storagebridge_swagger.json && mv tmp/storagebridge_swagger.json storagebridge_swagger.json
43+
44+
# Add license information using jq
45+
jq '.info.license = {"name": "", "url": ""}' storagebridge_swagger.json > tmp_storagebridge_swagger.json && mv tmp_storagebridge_swagger.json storagebridge_swagger.json
46+
47+
48+
openapi-python-client generate \
49+
--overwrite \
50+
--meta none \
51+
--path "storagebridge_swagger.json" \
52+
--custom-template-path=templates/ \
53+
--config openapi-generator-config.yaml \
54+
--output-path src/neptune_storage_api
55+
56+
57+
# Clean tmp directories
58+
rm -rf tmp
59+
60+
61+
cat scripts/preserve_files.txt | while read entry; do
62+
git checkout HEAD -- $entry
63+
done
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""A client library for accessing storagebridge"""
2+
3+
from .client import (
4+
AuthenticatedClient,
5+
Client,
6+
)
7+
8+
__all__ = (
9+
"AuthenticatedClient",
10+
"Client",
11+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contains methods for accessing the API"""

src/neptune_storage_api/api/storagebridge/__init__.py

Whitespace-only changes.
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
from http import HTTPStatus
2+
from typing import (
3+
Any,
4+
Optional,
5+
Union,
6+
cast,
7+
)
8+
9+
import httpx
10+
11+
from ... import errors
12+
from ...client import (
13+
AuthenticatedClient,
14+
Client,
15+
)
16+
from ...models.create_signed_urls_request import CreateSignedUrlsRequest
17+
from ...models.create_signed_urls_response import CreateSignedUrlsResponse
18+
from ...types import Response
19+
20+
21+
def _get_kwargs(
22+
*,
23+
body: CreateSignedUrlsRequest,
24+
) -> dict[str, Any]:
25+
headers: dict[str, Any] = {}
26+
27+
_kwargs: dict[str, Any] = {
28+
"method": "post",
29+
"url": "/api/storagebridge/v1/azure/signedUrl",
30+
}
31+
32+
_body = body.to_dict()
33+
34+
_kwargs["json"] = _body
35+
headers["Content-Type"] = "application/json"
36+
37+
_kwargs["headers"] = headers
38+
return _kwargs
39+
40+
41+
def _parse_response(
42+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
43+
) -> Optional[Union[Any, CreateSignedUrlsResponse]]:
44+
if response.status_code == 200:
45+
response_200 = CreateSignedUrlsResponse.from_dict(response.json())
46+
47+
return response_200
48+
if response.status_code == 401:
49+
response_401 = cast(Any, None)
50+
return response_401
51+
if response.status_code == 403:
52+
response_403 = cast(Any, None)
53+
return response_403
54+
if response.status_code == 413:
55+
response_413 = cast(Any, None)
56+
return response_413
57+
if client.raise_on_unexpected_status:
58+
raise errors.UnexpectedStatus(response.status_code, response.content)
59+
else:
60+
return None
61+
62+
63+
def _build_response(
64+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
65+
) -> Response[Union[Any, CreateSignedUrlsResponse]]:
66+
return Response(
67+
status_code=HTTPStatus(response.status_code),
68+
content=response.content,
69+
headers=response.headers,
70+
parsed=_parse_response(client=client, response=response),
71+
)
72+
73+
74+
def sync_detailed(
75+
*,
76+
client: Union[AuthenticatedClient, Client],
77+
body: CreateSignedUrlsRequest,
78+
) -> Response[Union[Any, CreateSignedUrlsResponse]]:
79+
"""
80+
Args:
81+
body (CreateSignedUrlsRequest):
82+
83+
Raises:
84+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
85+
httpx.TimeoutException: If the request takes longer than Client.timeout.
86+
87+
Returns:
88+
Response[Union[Any, CreateSignedUrlsResponse]]
89+
"""
90+
91+
kwargs = _get_kwargs(
92+
body=body,
93+
)
94+
95+
response = client.get_httpx_client().request(
96+
**kwargs,
97+
)
98+
99+
return _build_response(client=client, response=response)
100+
101+
102+
def sync(
103+
*,
104+
client: Union[AuthenticatedClient, Client],
105+
body: CreateSignedUrlsRequest,
106+
) -> Optional[Union[Any, CreateSignedUrlsResponse]]:
107+
"""
108+
Args:
109+
body (CreateSignedUrlsRequest):
110+
111+
Raises:
112+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
113+
httpx.TimeoutException: If the request takes longer than Client.timeout.
114+
115+
Returns:
116+
Union[Any, CreateSignedUrlsResponse]
117+
"""
118+
119+
return sync_detailed(
120+
client=client,
121+
body=body,
122+
).parsed
123+
124+
125+
async def asyncio_detailed(
126+
*,
127+
client: Union[AuthenticatedClient, Client],
128+
body: CreateSignedUrlsRequest,
129+
) -> Response[Union[Any, CreateSignedUrlsResponse]]:
130+
"""
131+
Args:
132+
body (CreateSignedUrlsRequest):
133+
134+
Raises:
135+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
136+
httpx.TimeoutException: If the request takes longer than Client.timeout.
137+
138+
Returns:
139+
Response[Union[Any, CreateSignedUrlsResponse]]
140+
"""
141+
142+
kwargs = _get_kwargs(
143+
body=body,
144+
)
145+
146+
response = await client.get_async_httpx_client().request(**kwargs)
147+
148+
return _build_response(client=client, response=response)
149+
150+
151+
async def asyncio(
152+
*,
153+
client: Union[AuthenticatedClient, Client],
154+
body: CreateSignedUrlsRequest,
155+
) -> Optional[Union[Any, CreateSignedUrlsResponse]]:
156+
"""
157+
Args:
158+
body (CreateSignedUrlsRequest):
159+
160+
Raises:
161+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
162+
httpx.TimeoutException: If the request takes longer than Client.timeout.
163+
164+
Returns:
165+
Union[Any, CreateSignedUrlsResponse]
166+
"""
167+
168+
return (
169+
await asyncio_detailed(
170+
client=client,
171+
body=body,
172+
)
173+
).parsed

0 commit comments

Comments
 (0)