-
Notifications
You must be signed in to change notification settings - Fork 5
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
Forward all presigned_attributes instead of trying to choose which ones to forward #90
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,40 @@ | ||
""" | ||
Felt API s3 upload parameters | ||
""" | ||
|
||
from dataclasses import dataclass | ||
from typing import ( | ||
Optional, | ||
Dict | ||
) | ||
from typing import Dict | ||
|
||
|
||
@dataclass | ||
class S3UploadParameters: | ||
""" | ||
Encapsulates parameters for uploading to S3 | ||
Encapsulates parameters for uploading to S3, including all presigned | ||
attributes | ||
""" | ||
|
||
aws_access_key_id: Optional[str] | ||
acl: Optional[str] | ||
key: Optional[str] | ||
policy: Optional[str] | ||
signature: Optional[str] | ||
success_action_status: Optional[str] | ||
x_amz_meta_features_flags: Optional[str] | ||
x_amz_meta_file_count: Optional[str] | ||
x_amz_security_token: Optional[str] | ||
url: Optional[str] | ||
layer_id: Optional[str] | ||
type: Optional[str] | ||
url: str | ||
layer_id: str | ||
type: str | ||
_presigned_attributes: Dict[str, str] | ||
|
||
def to_form_fields(self) -> Dict: | ||
""" | ||
Returns the form fields required for the upload | ||
Returns all form fields including the presigned attributes required | ||
for the upload | ||
Presigned attributes must be returned in the same order they | ||
appeared in the original JSON | ||
""" | ||
return { | ||
'AWSAccessKeyId': self.aws_access_key_id, | ||
'key': self.key, | ||
'policy': self.policy, | ||
'signature': self.signature, | ||
'success_action_status': self.success_action_status, | ||
'x-amz-meta-feature-flags': self.x_amz_meta_features_flags, | ||
'x-amz-meta-file-count': self.x_amz_meta_file_count, | ||
'x-amz-security-token': self.x_amz_security_token, | ||
} | ||
return {**self._presigned_attributes} | ||
|
||
@staticmethod | ||
def from_json(res: str) -> 'S3UploadParameters': | ||
def from_json(res: Dict[str, str]) -> 'S3UploadParameters': | ||
""" | ||
Creates upload parameters from a JSON string | ||
Creates upload parameters from a JSON response, capturing all | ||
presigned attributes | ||
""" | ||
return S3UploadParameters( | ||
type=res.get('data', {}).get('type'), | ||
aws_access_key_id=res.get('presigned_attributes', {}).get( | ||
'AWSAccessKeyId'), | ||
acl=res.get('presigned_attributes', {}).get('acl'), | ||
key=res.get('presigned_attributes', {}).get('key'), | ||
policy=res.get('presigned_attributes', {}).get('policy'), | ||
signature=res.get('presigned_attributes', {}).get('signature'), | ||
success_action_status=res.get('presigned_attributes', {}).get( | ||
'success_action_status'), | ||
x_amz_meta_features_flags=res.get('presigned_attributes', {}).get( | ||
'x-amz-meta-feature-flags'), | ||
x_amz_meta_file_count=res.get('presigned_attributes', {}).get( | ||
'x-amz-meta-file-count'), | ||
x_amz_security_token=res.get('presigned_attributes', {}).get( | ||
'x-amz-security-token'), | ||
url=res.get('url'), | ||
layer_id=res.get('layer_id'), | ||
type=res.get('data', {}).get('type'), | ||
_presigned_attributes=res.get('presigned_attributes', {}) | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this guaranteed to preserve the order of attributes that we received from the server? If the ordering changes then the signature will be invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah it should preserve order although it would be nice if it were spelled out more explicitly. I added a comment at least.