Commit a0e85010 authored by Spencer Sutton's avatar Spencer Sutton
Browse files

Adding call to partition service for multi tenant

parent e12a936b
Pipeline #70086 passed with stage
in 49 seconds
......@@ -22,6 +22,10 @@ from osdu.core.api.storage.tenant import Tenant
import boto3
from datetime import datetime, timedelta, timezone
from botocore.exceptions import ClientError, WaiterError
from osdu_api.clients.partition_client import PartitionClient
from osdu_api.providers.aws.partition_info_aws import PartitionInfoAws
try:
import ujson as json
except ImportError:
......@@ -119,6 +123,10 @@ class AwsStorage(BlobStorageBase):
]}
return UploadPolicy
def getTenantId(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
async def getCredentials(self, tenant: Tenant):
if len(self._session_token) > 2 and datetime.now(timezone.utc) < self._timestamp:
......@@ -126,13 +134,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
data_partition_id = tenant.data_partition_id
tenant_id = self.getTenantId(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(
Name=f'/osdu/{self._aws_env}/{data_partition_id}/wellbore-ddms/WellboreDDMSBucket/name',
Name=f'/osdu/{self._aws_env}/{tenant_id}/wellbore-ddms/WellboreDDMSBucket/name',
WithDecryption=True)
self._bucket_name = response['Parameter']['Value']
......
# for aws provider
boto3
botocore
--extra-index-url https://community.opengroup.org/api/v4/projects/148/packages/pypi/simple
osdu_api==0.10.1.dev203+a8daba87
\ No newline at end of file
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