Commit 0787df01 authored by Spencer Sutton's avatar Spencer Sutton
Browse files

Merge branch 'multi-tenant' into 'master'

Adding caching and using ssm prefix instead of tenant id

See merge request !5
parents bef20923 27c042be
Pipeline #72378 failed with stages
in 1 minute and 24 seconds
......@@ -22,6 +22,7 @@ from import Tenant
import boto3
from datetime import datetime, timedelta, timezone
from botocore.exceptions import ClientError, WaiterError
from functools import lru_cache
from osdu_api.clients.partition.partition_client import PartitionClient
from import PartitionInfoAws
......@@ -123,10 +124,12 @@ class AwsStorage(BlobStorageBase):
return UploadPolicy
def getTenantId(self, data_partition_id: str) -> str:
def getTenantSSMPrefix(self, data_partition_id: str) -> str:
partition_client = PartitionClient(data_partition_id=data_partition_id)
partition_info_aws = partition_client.get_partition(data_partition_id)
return partition_info_aws.tenant_id
return partition_info_aws.tenant_ssm_prefix
async def getCredentials(self, tenant: Tenant):
if len(self._session_token) > 2 and < self._timestamp:
......@@ -134,13 +137,13 @@ class AwsStorage(BlobStorageBase):
""" get credentials to access s3 bucket for tenant's folder """
# all tenants in one bucket(self._bucket_name). Each tenant.bucket_name is in fact, a folder in self._bucket_name
folder = tenant.bucket_name
tenant_id = self.getTenantId(tenant.data_partition_id)
tenant_ssm_prefix = self.getTenantSSMPrefix(tenant.data_partition_id)
ssm = boto3.client('ssm', region_name=self._region)
if(self._bucket_name == ""):
# get bucket name from ssm
response = ssm.get_parameter(
self._bucket_name = response['Parameter']['Value']
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment