-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed8c053
commit 895f83f
Showing
17 changed files
with
1,160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [ ! -f "storagebridge_swagger.json" ]; then | ||
echo "storagebridge_swagger.json not found. Make sure it's in CWD when running the script" | ||
exit 1 | ||
fi | ||
|
||
# Show every command and exit on error | ||
set -ex | ||
|
||
## Preserve specific files | ||
mkdir -p tmp | ||
|
||
|
||
# Function to download Swagger JSON | ||
download_swagger() { | ||
local swagger_url=$1 | ||
local output_file=$2 | ||
|
||
curl -o "${output_file}" "${swagger_url}" | ||
} | ||
|
||
# Function to convert Swagger 2.0 to OpenAPI 3.0 | ||
convert_swagger_to_openapi() { | ||
local input_file=$1 | ||
local output_file=$2 | ||
|
||
curl -X POST "https://converter.swagger.io/api/convert" \ | ||
-H "Content-Type: application/json" \ | ||
-d @"${input_file}" \ | ||
-o "${output_file}" | ||
} | ||
|
||
|
||
# Modify the Swagger JSON to support application/x-protobuf | ||
jq ' | ||
.paths |= with_entries( | ||
.value |= with_entries( | ||
if .value.produces? and (.value.produces | index("application/json")) and (.value.produces | index("application/x-protobuf")) | ||
then | ||
.value.produces = ["application/x-protobuf"] | ||
else | ||
. | ||
end | ||
) | ||
) | ||
' storagebridge_swagger.json > tmp/storagebridge_swagger.json && mv tmp/storagebridge_swagger.json storagebridge_swagger.json | ||
|
||
jq ' | ||
.paths |= with_entries( | ||
.value |= with_entries( | ||
if .value.produces? and (.value.produces | index("application/x-protobuf")) | ||
then | ||
.value.responses."200".schema = { | ||
"type": "string", | ||
"format": "binary" | ||
} | ||
else | ||
. | ||
end | ||
) | ||
) | ||
' storagebridge_swagger.json > tmp/storagebridge_swagger.json && mv tmp/storagebridge_swagger.json storagebridge_swagger.json | ||
|
||
## Convert the Swagger JSON to OpenAPI 3.0 | ||
convert_swagger_to_openapi "storagebridge_swagger.json" "storagebridge_openapi.json" | ||
# Add license information using jq | ||
jq '.info.license = {"name": "", "url": ""}' storagebridge_openapi.json > tmp_storagebridge_openapi.json && mv tmp_storagebridge_openapi.json storagebridge_openapi.json | ||
|
||
|
||
openapi-python-client generate \ | ||
--overwrite \ | ||
--meta none \ | ||
--path "storagebridge_openapi.json" \ | ||
--custom-template-path=templates/ \ | ||
--config openapi-generator-config.yaml \ | ||
--output-path src/neptune_storage_api | ||
|
||
|
||
# Clean tmp directories | ||
rm -rf tmp | ||
|
||
|
||
cat scripts/preserve_files.txt | while read entry; do | ||
git checkout HEAD -- $entry | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"""A client library for accessing storagebridge""" | ||
|
||
from .client import ( | ||
AuthenticatedClient, | ||
Client, | ||
) | ||
|
||
__all__ = ( | ||
"AuthenticatedClient", | ||
"Client", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Contains methods for accessing the API""" |
Empty file.
173 changes: 173 additions & 0 deletions
173
src/neptune_storage_api/api/storagebridge/signed_url.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
from http import HTTPStatus | ||
from typing import ( | ||
Any, | ||
Optional, | ||
Union, | ||
cast, | ||
) | ||
|
||
import httpx | ||
|
||
from ... import errors | ||
from ...client import ( | ||
AuthenticatedClient, | ||
Client, | ||
) | ||
from ...models.create_signed_urls_request import CreateSignedUrlsRequest | ||
from ...models.create_signed_urls_response import CreateSignedUrlsResponse | ||
from ...types import Response | ||
|
||
|
||
def _get_kwargs( | ||
*, | ||
body: CreateSignedUrlsRequest, | ||
) -> dict[str, Any]: | ||
headers: dict[str, Any] = {} | ||
|
||
_kwargs: dict[str, Any] = { | ||
"method": "post", | ||
"url": "/api/storagebridge/v1/azure/signedUrl", | ||
} | ||
|
||
_body = body.to_dict() | ||
|
||
_kwargs["json"] = _body | ||
headers["Content-Type"] = "application/json" | ||
|
||
_kwargs["headers"] = headers | ||
return _kwargs | ||
|
||
|
||
def _parse_response( | ||
*, client: Union[AuthenticatedClient, Client], response: httpx.Response | ||
) -> Optional[Union[Any, CreateSignedUrlsResponse]]: | ||
if response.status_code == 200: | ||
response_200 = CreateSignedUrlsResponse.from_dict(response.json()) | ||
|
||
return response_200 | ||
if response.status_code == 401: | ||
response_401 = cast(Any, None) | ||
return response_401 | ||
if response.status_code == 403: | ||
response_403 = cast(Any, None) | ||
return response_403 | ||
if response.status_code == 413: | ||
response_413 = cast(Any, None) | ||
return response_413 | ||
if client.raise_on_unexpected_status: | ||
raise errors.UnexpectedStatus(response.status_code, response.content) | ||
else: | ||
return None | ||
|
||
|
||
def _build_response( | ||
*, client: Union[AuthenticatedClient, Client], response: httpx.Response | ||
) -> Response[Union[Any, CreateSignedUrlsResponse]]: | ||
return Response( | ||
status_code=HTTPStatus(response.status_code), | ||
content=response.content, | ||
headers=response.headers, | ||
parsed=_parse_response(client=client, response=response), | ||
) | ||
|
||
|
||
def sync_detailed( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
body: CreateSignedUrlsRequest, | ||
) -> Response[Union[Any, CreateSignedUrlsResponse]]: | ||
""" | ||
Args: | ||
body (CreateSignedUrlsRequest): | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[Union[Any, CreateSignedUrlsResponse]] | ||
""" | ||
|
||
kwargs = _get_kwargs( | ||
body=body, | ||
) | ||
|
||
response = client.get_httpx_client().request( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(client=client, response=response) | ||
|
||
|
||
def sync( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
body: CreateSignedUrlsRequest, | ||
) -> Optional[Union[Any, CreateSignedUrlsResponse]]: | ||
""" | ||
Args: | ||
body (CreateSignedUrlsRequest): | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Union[Any, CreateSignedUrlsResponse] | ||
""" | ||
|
||
return sync_detailed( | ||
client=client, | ||
body=body, | ||
).parsed | ||
|
||
|
||
async def asyncio_detailed( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
body: CreateSignedUrlsRequest, | ||
) -> Response[Union[Any, CreateSignedUrlsResponse]]: | ||
""" | ||
Args: | ||
body (CreateSignedUrlsRequest): | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[Union[Any, CreateSignedUrlsResponse]] | ||
""" | ||
|
||
kwargs = _get_kwargs( | ||
body=body, | ||
) | ||
|
||
response = await client.get_async_httpx_client().request(**kwargs) | ||
|
||
return _build_response(client=client, response=response) | ||
|
||
|
||
async def asyncio( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
body: CreateSignedUrlsRequest, | ||
) -> Optional[Union[Any, CreateSignedUrlsResponse]]: | ||
""" | ||
Args: | ||
body (CreateSignedUrlsRequest): | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Union[Any, CreateSignedUrlsResponse] | ||
""" | ||
|
||
return ( | ||
await asyncio_detailed( | ||
client=client, | ||
body=body, | ||
) | ||
).parsed |
Oops, something went wrong.