Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRMDR-914 new IAM service for pre-sign url #374

Merged
merged 10 commits into from
Jun 12, 2024
Merged

PRMDR-914 new IAM service for pre-sign url #374

merged 10 commits into from
Jun 12, 2024

Conversation

NogaNHS
Copy link
Contributor

@NogaNHS NogaNHS commented Jun 7, 2024

No description provided.

@@ -30,7 +30,8 @@

class CreateDocumentReferenceService:
def __init__(self):
self.s3_service = S3Service()
create_document_aws_role_arn = os.getenv("PRE_SIGN_ASSUME_ROLE")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better to add this new env var to the handler's decorator, so that in case this is missing we are notified

self.custom_client = None
if custom_aws_role:
iam_service = IAMService()
print(iam_service)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably don't need this print anymore :)

Comment on lines 37 to 38
create_document_aws_role_arn = os.getenv("PRE_SIGN_ASSUME_ROLE")
self.s3_service = S3Service(custom_aws_role=create_document_aws_role_arn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
create_document_aws_role_arn = os.getenv("PRE_SIGN_ASSUME_ROLE")
self.s3_service = S3Service(custom_aws_role=create_document_aws_role_arn)
presign_url_aws_role_arn = os.getenv("PRE_SIGN_ASSUME_ROLE")
self.s3_service = S3Service(custom_aws_role=presign_url_aws_role_arn)

suggest to rename as here the role isn't for creating document

@@ -12,41 +13,49 @@
class S3Service:
_instance = None

def __new__(cls):
def __new__(cls, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for the args/kwargs addition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__new__ is run before __init__ and all the args are passed into both. So I need to be able to pass the custom role into __init__

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When new() returns an instance of cls it automatically invokes the [init()] method of that instance with the arguments passed to it.(https://www.codecademy.com/resources/docs/python/dunder-methods/new)

iam_service = IAMService()
self.custom_client = iam_service.assume_role(
custom_aws_role, "s3", config=config
)

# S3 Location should be a minimum of a s3_object_key but can also be a directory location in the form of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if we still need this comment? I know it's not part of your work but seems a bit unnecessary to me?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do. It's not clear without it.

@NogaNHS NogaNHS merged commit 4cba113 into main Jun 12, 2024
7 checks passed
@NogaNHS NogaNHS deleted the PRMDR-914 branch June 12, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants