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

Add generate_upload_policy #2998

Merged
merged 7 commits into from Feb 16, 2017
Merged

Conversation

theacodes
Copy link
Contributor

Resolves #2861

@theacodes theacodes added the api: storage Issues related to the Cloud Storage API. label Feb 11, 2017
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 11, 2017
for key, value in policy.items()
)

upload_form = (

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

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.


: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.


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.

This comment was marked as spam.

This comment was marked as spam.


conditions = conditions + [
{'bucket': self.name}
]

This comment was marked as spam.

This comment was marked as spam.


policy_document = {
'expiration': _datetime_to_rfc3339(expiration),
'conditions': conditions

This comment was marked as spam.

This comment was marked as spam.

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.

This comment was marked as spam.

'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.

bucket = self._make_one(client=client, name=name)

conditions = [
['starts-with', '$key', '']]

This comment was marked as spam.

This comment was marked as spam.

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.

@theacodes
Copy link
Contributor Author

(Travis is finally green)

for key, value in policy.items()
)

upload_form = (

This comment was marked as spam.

`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.

: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.


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.

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.

@theacodes
Copy link
Contributor Author

@dhermes LGTY?

@dhermes
Copy link
Contributor

dhermes commented Feb 16, 2017

Yup. But CircleCI is failing?

@dhermes
Copy link
Contributor

dhermes commented Feb 16, 2017

CircleCI is failing because you haven't rebased on master since #3002

@theacodes
Copy link
Contributor Author

@dhermes good eye, rebased. Will merge once all is green.

@theacodes theacodes merged commit 0a311f7 into googleapis:master Feb 16, 2017
@theacodes theacodes deleted the storage-policy branch February 16, 2017 21:11
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants