Skip to content

Commit f13c8ec

Browse files
authored
Access config values out from stores (#210)
* Access config values out from stores * Update `from_url` typing * doc note
1 parent 993947b commit f13c8ec

File tree

16 files changed

+352
-24
lines changed

16 files changed

+352
-24
lines changed

docs/api/store/aws.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# AWS S3
22

33
::: obstore.store.S3Store
4+
::: obstore.store.S3ConfigInput
5+
options:
6+
show_if_no_docstring: true
47
::: obstore.store.S3Config
58
options:
69
show_if_no_docstring: true

docs/api/store/azure.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Microsoft Azure
22

33
::: obstore.store.AzureStore
4+
::: obstore.store.AzureConfigInput
5+
options:
6+
show_if_no_docstring: true
47
::: obstore.store.AzureConfig
58
options:
69
show_if_no_docstring: true

docs/api/store/gcs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Google Cloud Storage
22

33
::: obstore.store.GCSStore
4+
::: obstore.store.GCSConfigInput
5+
options:
6+
show_if_no_docstring: true
47
::: obstore.store.GCSConfig
58
options:
69
show_if_no_docstring: true

obstore/python/obstore/store/__init__.pyi

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ from pathlib import Path
33
from typing import Any, Unpack, overload
44

55
from ._aws import S3Config as S3Config
6+
from ._aws import S3ConfigInput as S3ConfigInput
67
from ._aws import S3Store as S3Store
78
from ._azure import AzureConfig as AzureConfig
9+
from ._azure import AzureConfigInput as AzureConfigInput
810
from ._azure import AzureStore as AzureStore
911
from ._client import ClientConfig as ClientConfig
1012
from ._gcs import GCSConfig as GCSConfig
13+
from ._gcs import GCSConfigInput as GCSConfigInput
1114
from ._gcs import GCSStore as GCSStore
1215
from ._http import HTTPStore as HTTPStore
1316
from ._retry import BackoffConfig as BackoffConfig
@@ -17,28 +20,28 @@ from ._retry import RetryConfig as RetryConfig
1720
def from_url(
1821
url: str,
1922
*,
20-
config: S3Config | None = None,
23+
config: S3Config | S3ConfigInput | None = None,
2124
client_options: ClientConfig | None = None,
2225
retry_config: RetryConfig | None = None,
23-
**kwargs: Unpack[S3Config],
26+
**kwargs: Unpack[S3ConfigInput],
2427
) -> ObjectStore: ...
2528
@overload
2629
def from_url(
2730
url: str,
2831
*,
29-
config: GCSConfig | None = None,
32+
config: GCSConfig | GCSConfigInput | None = None,
3033
client_options: ClientConfig | None = None,
3134
retry_config: RetryConfig | None = None,
32-
**kwargs: Unpack[GCSConfig],
35+
**kwargs: Unpack[GCSConfigInput],
3336
) -> ObjectStore: ...
3437
@overload
3538
def from_url(
3639
url: str,
3740
*,
38-
config: AzureConfig | None = None,
41+
config: AzureConfig | AzureConfigInput | None = None,
3942
client_options: ClientConfig | None = None,
4043
retry_config: RetryConfig | None = None,
41-
**kwargs: Unpack[AzureConfig],
44+
**kwargs: Unpack[AzureConfigInput],
4245
) -> ObjectStore: ...
4346
@overload
4447
def from_url(
@@ -53,7 +56,7 @@ def from_url(
5356
def from_url(
5457
url: str,
5558
*,
56-
config: S3Config | GCSConfig | AzureConfig | None = None,
59+
config: S3ConfigInput | GCSConfigInput | AzureConfigInput | None = None,
5760
client_options: ClientConfig | None = None,
5861
retry_config: RetryConfig | None = None,
5962
**kwargs: Any,
@@ -80,6 +83,10 @@ def from_url(
8083
- `amazonaws.com` -> [`S3Store`][obstore.store.S3Store]
8184
- `r2.cloudflarestorage.com` -> [`S3Store`][obstore.store.S3Store]
8285
86+
!!! note
87+
For best static typing, use the constructors on individual store classes
88+
directly.
89+
8390
Args:
8491
url: well-known storage URL.
8592

obstore/python/obstore/store/_aws.pyi

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,84 @@ from ._retry import RetryConfig
1111
# Note: we removed `bucket` because it overlaps with an existing named arg in the
1212
# constructors
1313
class S3Config(TypedDict, total=False):
14-
"""Configuration parameters for S3Store.
14+
"""Configuration parameters returned from [S3Store.config][obstore.store.S3Store.config].
1515
16-
There are duplicates of many parameters, and parameters can be either upper or lower
17-
case. Not all parameters are required.
16+
Note that this is a strict subset of the keys allowed for _input_ into the store,
17+
see [S3ConfigInput][obstore.store.S3ConfigInput].
1818
"""
1919

20+
aws_access_key_id: str
21+
"""AWS Access Key"""
22+
aws_bucket: str
23+
"""Bucket name"""
24+
aws_checksum_algorithm: str
25+
"""
26+
Sets the [checksum algorithm] which has to be used for object integrity check during upload.
27+
28+
[checksum algorithm]: https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html
29+
"""
30+
aws_conditional_put: str
31+
"""
32+
See [`S3ConfigInput.aws_conditional_put`][obstore.store.S3ConfigInput.aws_conditional_put].
33+
"""
34+
aws_container_credentials_relative_uri: str
35+
"""
36+
See [`S3ConfigInput.aws_container_credentials_relative_uri`][obstore.store.S3ConfigInput.aws_container_credentials_relative_uri].
37+
"""
38+
aws_copy_if_not_exists: str
39+
"""
40+
See [`S3ConfigInput.aws_copy_if_not_exists`][obstore.store.S3ConfigInput.aws_copy_if_not_exists].
41+
"""
42+
aws_default_region: str
43+
"""Default region"""
44+
aws_disable_tagging: bool
45+
"""Disable tagging objects. This can be desirable if not supported by the backing store."""
46+
aws_endpoint: str
47+
"""Sets custom endpoint for communicating with AWS S3."""
48+
aws_imdsv1_fallback: str
49+
"""Fall back to ImdsV1"""
50+
aws_metadata_endpoint: str
51+
"""Set the instance metadata endpoint"""
52+
aws_region: str
53+
"""Region"""
54+
aws_request_payer: bool
55+
"""If `True`, enable operations on requester-pays buckets."""
56+
aws_s3_express: bool
57+
"""Enable Support for S3 Express One Zone"""
58+
aws_secret_access_key: str
59+
"""Secret Access Key"""
60+
aws_server_side_encryption: str
61+
"""
62+
See [`S3ConfigInput.aws_server_side_encryption`][obstore.store.S3ConfigInput.aws_server_side_encryption].
63+
"""
64+
aws_session_token: str
65+
"""Token to use for requests (passed to underlying provider)"""
66+
aws_skip_signature: bool
67+
"""If `True`, S3Store will not fetch credentials and will not sign requests."""
68+
aws_sse_bucket_key_enabled: bool
69+
"""
70+
If set to `True`, will use the bucket's default KMS key for server-side encryption.
71+
If set to `False`, will disable the use of the bucket's default KMS key for server-side encryption.
72+
"""
73+
aws_sse_customer_key_base64: str
74+
"""
75+
The base64 encoded, 256-bit customer encryption key to use for server-side
76+
encryption. If set, the server side encryption config value must be `"sse-c"`.
77+
"""
78+
aws_sse_kms_key_id: str
79+
"""
80+
The KMS key ID to use for server-side encryption.
81+
82+
If set, the server side encryption config value must be `"aws:kms"` or `"aws:kms:dsse"`.
83+
"""
84+
aws_token: str
85+
"""Token to use for requests (passed to underlying provider)"""
86+
aws_unsigned_payload: bool
87+
"""Avoid computing payload checksum when calculating signature."""
88+
aws_virtual_hosted_style_request: bool
89+
"""If virtual hosted style request has to be used."""
90+
91+
class S3ConfigInput(TypedDict, total=False):
2092
access_key_id: str
2193
"""AWS Access Key"""
2294
aws_access_key_id: str
@@ -152,6 +224,7 @@ class S3Config(TypedDict, total=False):
152224
"""Avoid computing payload checksum when calculating signature."""
153225
aws_virtual_hosted_style_request: bool
154226
"""If virtual hosted style request has to be used."""
227+
155228
bucket_name: str
156229
"""Bucket name"""
157230
checksum_algorithm: str
@@ -491,8 +564,8 @@ class S3Store:
491564
492565
All constructors will check for environment variables. All environment variables
493566
starting with `AWS_` will be evaluated. Names must match keys from
494-
[`S3Config`][obstore.store.S3Config]. Only upper-case environment variables are
495-
accepted.
567+
[`S3ConfigInput`][obstore.store.S3ConfigInput]. Only upper-case environment
568+
variables are accepted.
496569
497570
Some examples of variables extracted from environment:
498571
@@ -522,10 +595,10 @@ class S3Store:
522595
bucket: str | None = None,
523596
*,
524597
prefix: str | None = None,
525-
config: S3Config | None = None,
598+
config: S3Config | S3ConfigInput | None = None,
526599
client_options: ClientConfig | None = None,
527600
retry_config: RetryConfig | None = None,
528-
**kwargs: Unpack[S3Config],
601+
**kwargs: Unpack[S3ConfigInput],
529602
) -> None:
530603
"""Create a new S3Store.
531604
@@ -549,10 +622,10 @@ class S3Store:
549622
bucket: str | None = None,
550623
*,
551624
prefix: str | None = None,
552-
config: S3Config | None = None,
625+
config: S3Config | S3ConfigInput | None = None,
553626
client_options: ClientConfig | None = None,
554627
retry_config: RetryConfig | None = None,
555-
**kwargs: Unpack[S3Config],
628+
**kwargs: Unpack[S3ConfigInput],
556629
) -> S3Store:
557630
"""Construct a new S3Store with credentials inferred from a boto3 Session.
558631
@@ -590,10 +663,10 @@ class S3Store:
590663
cls,
591664
url: str,
592665
*,
593-
config: S3Config | None = None,
666+
config: S3Config | S3ConfigInput | None = None,
594667
client_options: ClientConfig | None = None,
595668
retry_config: RetryConfig | None = None,
596-
**kwargs: Unpack[S3Config],
669+
**kwargs: Unpack[S3ConfigInput],
597670
) -> S3Store:
598671
"""Parse available connection info from a well-known storage URL.
599672
@@ -620,3 +693,15 @@ class S3Store:
620693

621694
def __getnewargs_ex__(self): ...
622695
def __repr__(self) -> str: ...
696+
@property
697+
def prefix(self) -> str | None:
698+
"""Get the prefix applied to all operations in this store, if any."""
699+
@property
700+
def config(self) -> S3Config:
701+
"""Get the underlying S3 config parameters."""
702+
@property
703+
def client_options(self) -> ClientConfig | None:
704+
"""Get the store's client configuration."""
705+
@property
706+
def retry_config(self) -> RetryConfig | None:
707+
"""Get the store's retry configuration."""

obstore/python/obstore/store/_azure.pyi

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,62 @@ from typing import TypedDict, Unpack
33
from ._client import ClientConfig
44
from ._retry import RetryConfig
55

6+
# TODO:
7+
# azure_storage_authority_host
8+
# azure_fabric_token_service_url
9+
# azure_fabric_workload_host
10+
# "azure_fabric_session_token",
11+
# "azure_fabric_cluster_identifier",
612
class AzureConfig(TypedDict, total=False):
13+
"""Configuration parameters returned from [AzureStore.config][obstore.store.AzureStore.config].
14+
15+
Note that this is a strict subset of the keys allowed for _input_ into the store,
16+
see [AzureConfigInput][obstore.store.AzureConfigInput].
17+
"""
18+
19+
azure_storage_account_name: str
20+
"""The name of the azure storage account"""
21+
azure_storage_account_key: str
22+
"""Master key for accessing storage account"""
23+
azure_storage_client_id: str
24+
"""Service principal client id for authorizing requests"""
25+
azure_storage_client_secret: str
26+
"""Service principal client secret for authorizing requests"""
27+
azure_storage_tenant_id: str
28+
"""Tenant id used in oauth flows"""
29+
azure_storage_sas_key: str
30+
"""
31+
Shared access signature.
32+
33+
The signature is expected to be percent-encoded, `much `like they are provided in
34+
the azure storage explorer or azure portal.
35+
"""
36+
azure_storage_token: str
37+
"""Bearer token"""
38+
azure_storage_use_emulator: bool
39+
"""Use object store with azurite storage emulator"""
40+
azure_use_fabric_endpoint: bool
41+
"""Use object store with url scheme account.dfs.fabric.microsoft.com"""
42+
azure_storage_endpoint: str
43+
"""Override the endpoint used to communicate with blob storage"""
44+
azure_msi_endpoint: str
45+
"""Endpoint to request a imds managed identity token"""
46+
azure_object_id: str
47+
"""Object id for use with managed identity authentication"""
48+
azure_msi_resource_id: str
49+
"""Msi resource id for use with managed identity authentication"""
50+
azure_federated_token_file: str
51+
"""File containing token for Azure AD workload identity federation"""
52+
azure_use_azure_cli: bool
53+
"""Use azure cli for acquiring access token"""
54+
azure_skip_signature: bool
55+
"""Skip signing requests"""
56+
azure_container_name: str
57+
"""Container name"""
58+
azure_disable_tagging: bool
59+
"""Disables tagging objects"""
60+
61+
class AzureConfigInput(TypedDict, total=False):
762
"""Configuration parameters for AzureStore.
863
964
There are duplicates of many parameters, and parameters can be either upper or lower
@@ -282,7 +337,7 @@ class AzureStore:
282337
container: str | None = None,
283338
*,
284339
prefix: str | None = None,
285-
config: AzureConfig | None = None,
340+
config: AzureConfig | AzureConfigInput | None = None,
286341
client_options: ClientConfig | None = None,
287342
retry_config: RetryConfig | None = None,
288343
**kwargs: Unpack[AzureConfig],
@@ -307,7 +362,7 @@ class AzureStore:
307362
url: str,
308363
*,
309364
prefix: str | None = None,
310-
config: AzureConfig | None = None,
365+
config: AzureConfig | AzureConfigInput | None = None,
311366
client_options: ClientConfig | None = None,
312367
retry_config: RetryConfig | None = None,
313368
**kwargs: Unpack[AzureConfig],
@@ -344,3 +399,15 @@ class AzureStore:
344399

345400
def __getnewargs_ex__(self): ...
346401
def __repr__(self) -> str: ...
402+
@property
403+
def prefix(self) -> str | None:
404+
"""Get the prefix applied to all operations in this store, if any."""
405+
@property
406+
def config(self) -> AzureConfig:
407+
"""Get the underlying Azure config parameters."""
408+
@property
409+
def client_options(self) -> ClientConfig | None:
410+
"""Get the store's client configuration."""
411+
@property
412+
def retry_config(self) -> RetryConfig | None:
413+
"""Get the store's retry configuration."""

0 commit comments

Comments
 (0)