Skip to content

Commit 203a2b0

Browse files
author
Krzysztof Godlewski
committed
Add neptune_storage_api
1 parent ed8c053 commit 203a2b0

File tree

16 files changed

+1159
-1
lines changed

16 files changed

+1159
-1
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 --target-version=py38"
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

scripts/update-storagebridge.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
15+
# Function to download Swagger JSON
16+
download_swagger() {
17+
local swagger_url=$1
18+
local output_file=$2
19+
20+
curl -o "${output_file}" "${swagger_url}"
21+
}
22+
23+
# Function to convert Swagger 2.0 to OpenAPI 3.0
24+
convert_swagger_to_openapi() {
25+
local input_file=$1
26+
local output_file=$2
27+
28+
curl -X POST "https://converter.swagger.io/api/convert" \
29+
-H "Content-Type: application/json" \
30+
-d @"${input_file}" \
31+
-o "${output_file}"
32+
}
33+
34+
35+
# Modify the Swagger JSON to support application/x-protobuf
36+
jq '
37+
.paths |= with_entries(
38+
.value |= with_entries(
39+
if .value.produces? and (.value.produces | index("application/json")) and (.value.produces | index("application/x-protobuf"))
40+
then
41+
.value.produces = ["application/x-protobuf"]
42+
else
43+
.
44+
end
45+
)
46+
)
47+
' storagebridge_swagger.json > tmp/storagebridge_swagger.json && mv tmp/storagebridge_swagger.json storagebridge_swagger.json
48+
49+
jq '
50+
.paths |= with_entries(
51+
.value |= with_entries(
52+
if .value.produces? and (.value.produces | index("application/x-protobuf"))
53+
then
54+
.value.responses."200".schema = {
55+
"type": "string",
56+
"format": "binary"
57+
}
58+
else
59+
.
60+
end
61+
)
62+
)
63+
' storagebridge_swagger.json > tmp/storagebridge_swagger.json && mv tmp/storagebridge_swagger.json storagebridge_swagger.json
64+
65+
## Convert the Swagger JSON to OpenAPI 3.0
66+
convert_swagger_to_openapi "storagebridge_swagger.json" "storagebridge_openapi.json"
67+
# Add license information using jq
68+
jq '.info.license = {"name": "", "url": ""}' storagebridge_openapi.json > tmp_storagebridge_openapi.json && mv tmp_storagebridge_openapi.json storagebridge_openapi.json
69+
70+
71+
openapi-python-client generate \
72+
--overwrite \
73+
--meta none \
74+
--path "storagebridge_openapi.json" \
75+
--custom-template-path=templates/ \
76+
--config openapi-generator-config.yaml \
77+
--output-path src/neptune_storage_api
78+
79+
80+
# Clean tmp directories
81+
rm -rf tmp
82+
83+
84+
cat scripts/preserve_files.txt | while read entry; do
85+
git checkout HEAD -- $entry
86+
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)