-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdk/python: Move bucket providers to an Enum
Signed-off-by: Aaron Wilson <[email protected]>
- Loading branch information
Showing
33 changed files
with
244 additions
and
182 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
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
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
# | ||
# Copyright (c) 2022-2024, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
|
||
from enum import IntEnum | ||
|
||
|
||
|
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
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,44 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from typing import Union | ||
|
||
from aistore.sdk.errors import InvalidBckProvider | ||
|
||
ALIAS_S3 = "s3" | ||
ALIAS_GS = "gs" | ||
|
||
|
||
class Provider(Enum): | ||
""" | ||
Represent the providers used for a bucket. See https://aistore.nvidia.com/docs/providers and api/apc/provider.go | ||
""" | ||
|
||
AIS = "ais" | ||
AMAZON = "aws" | ||
AZURE = "azure" | ||
GOOGLE = "gcp" | ||
HTTP = "ht" | ||
|
||
@staticmethod | ||
def parse(provider: Union[Provider, str]) -> Provider: | ||
""" | ||
Parse a provider Enum instance from a given value. | ||
Args: | ||
provider: A Provider or string. | ||
Returns: The given Provider or a new one constructed from the given value. | ||
Raises: InvalidBckProvider if provided with a string that is not a valid Provider option. | ||
""" | ||
if isinstance(provider, Provider): | ||
return provider | ||
try: | ||
# Use the provider alias for the given string if one exists | ||
provider = provider_aliases.get(provider, provider) | ||
return Provider(provider) | ||
except ValueError as exc: | ||
raise InvalidBckProvider(provider) from exc | ||
|
||
|
||
provider_aliases = {ALIAS_GS: Provider.GOOGLE.value, ALIAS_S3: Provider.AMAZON.value} |
Oops, something went wrong.