-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add generate_upload_policy #2998
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
Conversation
for key, value in policy.items() | ||
) | ||
|
||
upload_form = ( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
import six | ||
|
||
from google.cloud._helpers import _rfc3339_to_datetime | ||
from google.cloud._helpers import ( | ||
_NOW, _rfc3339_to_datetime, _datetime_to_rfc3339) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
:type expiration: datetime | ||
:param expiration: Optional expiration in UTC. If not specified, the | ||
policy will expire in 1 hour. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
if not isinstance(credentials, google.auth.credentials.Signing): | ||
auth_uri = ('http://google-cloud-python.readthedocs.io/en/latest/' | ||
'google-cloud-auth.html#setting-up-a-service-account') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
conditions = conditions + [ | ||
{'bucket': self.name} | ||
] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
policy_document = { | ||
'expiration': _datetime_to_rfc3339(expiration), | ||
'conditions': conditions |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
encoded_policy_document = base64.b64encode( | ||
json.dumps(policy_document).encode('utf-8')) | ||
signature = base64.b64encode( | ||
credentials.sign_bytes(encoded_policy_document)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
'bucket': self.name, | ||
'GoogleAccessId': credentials.signer_email, | ||
'policy': encoded_policy_document.decode('utf-8'), | ||
'signature': signature.decode('utf-8') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
bucket = self._make_one(client=client, name=name) | ||
|
||
conditions = [ | ||
['starts-with', '$key', '']] |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
import json | ||
|
||
credentials = _create_signing_credentials() | ||
credentials.signer_email = mock.sentinel.signer_email |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
(Travis is finally green) |
for key, value in policy.items() | ||
) | ||
|
||
upload_form = ( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
`policy documents`_ documentation. | ||
|
||
:type client: :class:`~google.cloud.storage.client.Client` or | ||
`NoneType`` |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
:rtype: dict | ||
:returns: A dictionary of (form field name, form field value) of form | ||
fields that should be added to your HTML upload form in order | ||
to attach the signature. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
if not isinstance(credentials, google.auth.credentials.Signing): | ||
auth_uri = ('http://google-cloud-python.readthedocs.io/en/latest/' | ||
'google-cloud-auth.html#setting-up-a-service-account') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
encoded_policy_document = base64.b64encode( | ||
json.dumps(policy_document).encode('utf-8')) | ||
signature = base64.b64encode( | ||
credentials.sign_bytes(encoded_policy_document)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@dhermes LGTY? |
Yup. But CircleCI is failing? |
CircleCI is failing because you haven't rebased on master since #3002 |
4c5d439
to
1327323
Compare
@dhermes good eye, rebased. Will merge once all is green. |
Resolves #2861