Created
August 14, 2023 16:08
-
-
Save wthorp/0e088024475d646f1faf1e0d3e472d1a to your computer and use it in GitHub Desktop.
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
import requests | |
from uplink_python.uplink import Uplink | |
from uplink_python.module_classes import Permission, SharePrefix | |
API_KEY = "..." | |
ENC_PASSWORD = "..." | |
SATELLITE_HOST = "12EayRS2V1kEsWESU9QMRseFhdxYxKicsiFmxrsLZHeLUtdps3S@us1.storj.io:7777" | |
CUSTOMER_NAME = "clientA" | |
BUCKET = "client-data" | |
# create a new master access for this | |
ul = Uplink() | |
access = ul.request_access_with_passphrase(SATELLITE_HOST, API_KEY, ENC_PASSWORD) | |
#make sure our client-data bucket exists | |
project = access.open_project() | |
bucket = project.ensure_bucket(BUCKET) | |
project.close() | |
# set permissions for customer access | |
permissions = Permission(allow_list=True, allow_delete=True, allow_upload=True, allow_download=True) | |
# limit customer access to their particular path | |
shared_prefix = [SharePrefix(bucket=BUCKET, prefix=CUSTOMER_NAME)] | |
# create derived access grant with restricted priviledges for customer | |
new_access = access.share(permissions, shared_prefix).serialize() | |
# register access grant with S3, returning new S3 credentials | |
# these credentials may be stored and reused for each customer | |
params = {'access_grant': new_access, 'public': False } | |
response = requests.post('https://auth.storjshare.io/v1/access', json = params) | |
jsonResponse = response.json() | |
print(jsonResponse) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment