Comments (3)
For GCS and S3 we have avoided storing credentials in the spec or context spec as that seems more prone to leaking than using a credentials file. The credentials file seems like the best approach, as then you can store the credentials in the same way for the aws cli and tensorstore. You could use one credentials file specific to each user then use the filename/profile of the aws_credentials object as part of the spec.
https://google.github.io/tensorstore/kvstore/s3/index.html#json-Context.aws_credentials
from tensorstore.
Thanks @laramiel.
For other people who might be interested in this, I wrote a helper that creates a temporary profile file to be used with tensorstore:
from functools import lru_cache
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Self
import tensorstore
class AWSCredentialManager:
entries: dict[int, tuple[str, str]]
temp_dir: TemporaryDirectory[str]
credentials_file_path: Path
@classmethod
@lru_cache
def singleton(cls) -> "Self":
return cls()
def __init__(self) -> None:
self.entries = {}
self.temp_dir = TemporaryDirectory()
self.credentials_file_path = Path(self.temp_dir.name) / "aws_credentials"
self.credentials_file_path.touch()
def _dump_credentials(self) -> None:
self.credentials_file_path.write_text(
"\n".join(
[
f"[profile-{key_hash}]\naws_access_key_id = {access_key_id}\naws_secret_access_key = {secret_access_key}\n"
for key_hash, (
access_key_id,
secret_access_key,
) in self.entries.items()
]
)
)
def add(self, access_key_id: str, secret_access_key: str) -> dict[str, str]:
key_tuple = (access_key_id, secret_access_key)
key_hash = hash(key_tuple)
self.entries[key_hash] = key_tuple
self._dump_credentials()
return {
"profile": f"profile-{key_hash}",
"filename": str(self.credentials_file_path),
"metadata_endpoint": "",
}
aws_credential_manager = AWSCredentialManager.singleton()
spec = {
"driver": "s3",
"bucket": "...",
"path": "...",
"endpoint": "https://s3.eu-central-1.amazonaws.com",
"aws_credentials": aws_credential_manager.add("AKIA...", "...")
}
array = tensorstore.open({"driver": "zarr", "kvstore": spec}).result()
data = array[:, :, :].read().result()
from tensorstore.
Just a note about your spec: you should be able to use "aws_region": "eu-central-1"
rather than setting "endpoint"
.
from tensorstore.
Related Issues (20)
- consider looking in `/etc/pki/ca-trust/extracted` for CA certificates? HOT 3
- question about writing parallel and group handling HOT 39
- Slow random read performance HOT 8
- Segfault/Mutex Error HOT 13
- Does zarr_sharding_indexed exist? HOT 1
- Incorrect writes using int array indexing, affected by chunk layout HOT 1
- Zstd compression does not encode content size in header HOT 2
- Falied to acquire lock on file HOT 1
- Metric suggestions HOT 6
- Parallel write handling in Zarr HOT 1
- zarr3 shard user block / offset
- Windows: NotImplementedError: CopyRange not supported #1048 HOT 5
- Please allow compile-time evaluation of `DataType::id()` (constexpr), platform-independently HOT 1
- Support installation to enable reuse/packaging HOT 5
- Tensorstore C++ Integration: How to Avoid Driver Registry Conflict HOT 6
- Segmentation fault when using tensorstore with multiple workers in pytorch dataloader HOT 1
- Tensorstore key value store driver not Retrying on 429 Responses with S3 API HOT 7
- Read speeds decrease 2x when reading with fewer processes HOT 7
- Writing Neuroglancer Precomputed data with png compression not working correctly
- Build issues with latest version (73da2a2) HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tensorstore.