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

storage: add getSignedPolicy function to generate a signed policy #502

Closed
wants to merge 10 commits into from

Conversation

mziccard
Copy link
Contributor

Added a function to generate a signed policy for POST requests.
So far it supports several conditions (according to the docs):

  • Equality: ["eq", "$<field>", "<value>"]
  • Starts with: ["starts-with", "$<field>", "<value>"]
  • Content length: ["content-length-range", <min_range>, <max_range>]
  • Bucket: {"bucket": "<bucket_name>"}
  • Acl: {"acl": "<acl_name>"}
  • Success redirect: {"success_action_redirect": "<url>"}
  • Success status: {"success_action_status": "<status>"}

Documentation is provided describing function arguments.
Unit tests are added.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 15, 2015
* *[Reference](http://goo.gl/JWJEkG).*
*
* @throws {Error} if an expiration timestamp from the past is given or
* option parameter does not respect

This comment was marked as spam.

This comment was marked as spam.

assert(signedPolicy.string.indexOf(conditionString) > -1);
done();
});
});

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

All looks good to me. Thanks for adding this @mziccard!

@ryanseys anything left to resolve before merge? I'll handle the small style issues, so we don't bug him with that :)

@mziccard
Copy link
Contributor Author

@stephenplusplus Feel free to bug me:)

BTW, I think it is still open for discussion whether to move this method to Bucket (allowing signed policies not associated to a specific filename) or not.

Adding a regression test might be useful as well.

var conditions = [];

// Populate eq conditions
if (options.equals && options.equals instanceof Array) {

This comment was marked as spam.

… equality and prefix conditions as 1D array. Docs updated accordingly. Added tests.
@mziccard
Copy link
Contributor Author

Should be ok now, even the boring stuff :)
Both

file.getSignedPolicy({
  equals: ['$Content-Type', 'image/jpeg']
  // ...

and

file.getSignedPolicy({
  equals: [['$Content-Type', 'image/jpeg']]
  // ...

are now supported if only one condition is specified. (also for startsWith condition).

conditions.push(['eq', condition[0], condition[1]]);
});
}
}

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

Thank you very much!

@mziccard
Copy link
Contributor Author

Everything ok on my side, are there any more thoughts?

expiration: expiration,
startsWith: [['$<field>', '<value>']]
}, function(err, signedPolicy) {
console.log(signedPolicy);

This comment was marked as spam.

@ryanseys
Copy link
Contributor

Just a couple console.logs left in the tests, but otherwise looks ready for merge! :)

sofisl pushed a commit that referenced this pull request Oct 13, 2022
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/7a1b0b96-8ddb-4836-a1a2-d2f73b7e6ffe/targets

- [ ] To automatically regenerate this PR, check this box.
sofisl pushed a commit that referenced this pull request Nov 9, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this pull request Nov 10, 2022
This PR was generated using Autosynth. 🌈

Synth log will be available here:
https://source.cloud.google.com/results/invocations/541df317-e090-4c6d-88b9-3f79f53b8d13/targets

- [ ] To automatically regenerate this PR, check this box.

Source-Link: googleapis/synthtool@57c23fa
sofisl pushed a commit that referenced this pull request Nov 11, 2022
sofisl pushed a commit that referenced this pull request Nov 11, 2022
…e in region tag (#502)

* docs(samples): add auto-generated samples for Node with api short name in region tag

PiperOrigin-RevId: 399287285

Source-Link: googleapis/googleapis@1575986

Source-Link: googleapis/googleapis-gen@b27fff6
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjI3ZmZmNjIzYTVkOGQ1ODZiNzAzYjVlNDkxOTg1NmFiZTdjMmViMyJ9

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this pull request Nov 17, 2022
Co-authored-by: gcf-merge-on-green[bot] <60162190+gcf-merge-on-green[bot]@users.noreply.github.com>

Source-Author: F. Hinkelmann <franziska.hinkelmann@gmail.com>
Source-Date: Wed Sep 30 14:13:57 2020 -0400
Source-Repo: googleapis/synthtool
Source-Sha: 079dcce498117f9570cebe6e6cff254b38ba3860
Source-Link: googleapis/synthtool@079dcce
sofisl pushed a commit that referenced this pull request Nov 18, 2022
* chore(main): release 6.3.0

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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