google-api-ruby-client icon indicating copy to clipboard operation
google-api-ruby-client copied to clipboard

Unable to update a permission with expiry date

Open vamsipavanmahesh opened this issue 5 years ago • 3 comments

Environment details

  • OS: macOS Catalina 10.15.5
  • Ruby version: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin19]
  • Gem version: 0.51.0

Steps to reproduce

  1. create a file
  2. create permission
  3. update permission with an expiration date

Expected: Updated permission should have an expiration date

Code example

drive = Google::Apis::DriveV2::DriveService.new
drive.authorization = client

metadata = Google::Apis::DriveV2::File.new(title: 'check permissions', copy_requires_writer_permission: true)
file = drive.insert_file(metadata, upload_source: "tmp/foo.mp4", content_type: 'video/mp4')
permission2 = Google::Apis::DriveV2::Permission.new(role: "writer", type: "user", value: "[email protected]", email_address: "[email protected]")
server_permission = drive.insert_permission(file.id, permission2)
permission2.expiration_date =  (DateTime.current.utc+5.minutes).rfc3339
drive.update_permission(file.id, server_permission.id, permission2)

output of update permission

drive.update_permission(file.id, server_permission.id, permission2)
Sending HTTP put https://www.googleapis.com/drive/v2/files/1YPRe4NVaFh4_zsvRub7hs180651MezQ5/permissions/09144568628734991651?
200
#<HTTP::Message:0x00007feb9afa63c8 @http_header=#<HTTP::Message::Headers:0x00007feb9afa63a0 @http_version="1.1", @body_size=0, @chunked=false, @request_method="PUT", @request_uri=#<Addressable::URI:0x3ff5cd7d3f40 URI:https://www.googleapis.com/drive/v2/files/1YPRe4NVaFh4_zsvRub7hs180651MezQ5/permissions/09144568628734991651?>, @request_query=nil, @request_absolute_uri=nil, @status_code=200, @reason_phrase="OK", @body_type=nil, @body_charset=nil, @body_date=nil, @body_encoding=#<Encoding:UTF-8>, @is_request=false, @header_item=[["Cache-Control", "no-cache, no-store, max-age=0, must-revalidate"], ["Pragma", "no-cache"], ["Expires", "Mon, 01 Jan 1990 00:00:00 GMT"], ["Date", "Tue, 15 Dec 2020 11:25:55 GMT"], ["ETag", "\"GB5K0nP_lpMg2gXYRx_Dj0Nb6Gw\""], ["Vary", "Origin"], ["Vary", "X-Origin"], ["Content-Type", "application/json; charset=UTF-8"], ["Content-Encoding", "gzip"], ["X-Content-Type-Options", "nosniff"], ["X-Frame-Options", "SAMEORIGIN"], ["Content-Security-Policy", "frame-ancestors 'self'"], ["X-XSS-Protection", "1; mode=block"], ["Server", "GSE"], ["Alt-Svc", "h3-29=\":443\"; ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""], ["Transfer-Encoding", "chunked"]], @dumped=false>, @peer_cert=#<OpenSSL::X509::Certificate: subject=#<OpenSSL::X509::Name CN=upload.video.google.com,O=Google LLC,L=Mountain View,ST=California,C=US>, issuer=#<OpenSSL::X509::Name CN=GTS CA 1O1,O=Google Trust Services,C=US>, serial=#<OpenSSL::BN:0x00007feb9b315bf8>, not_before=2020-11-10 14:39:49 UTC, not_after=2021-02-02 14:39:48 UTC>, @http_body=#<HTTP::Message::Body:0x00007feb9afa6300 @body="{\n \"kind\": \"drive#permission\",\n \"etag\": \"\\\"GB5K0nP_lpMg2gXYRx_Dj0Nb6Gw\\\"\",\n \"id\": \"09144568628734991651\",\n \"selfLink\": \"https://www.googleapis.com/drive/v2/files/1YPRe4NVaFh4_zsvRub7hs180651MezQ5/permissions/09144568628734991651\",\n \"name\": \"vamsi g\",\n \"emailAddress\": \"[email protected]\",\n \"domain\": \"gmail.com\",\n \"role\": \"writer\",\n \"type\": \"user\",\n \"deleted\": false\n}\n", @size=0, @positions=nil, @chunk_size=nil>, @previous=nil>
Success - #<Google::Apis::DriveV2::Permission:0x00007feb9afeca08
 @deleted=false,
 @domain="gmail.com",
 @email_address="[email protected]",
 @etag="\"GB5K0nP_lpMg2gXYRx_Dj0Nb6Gw\"",
 @id="09144568628734991651",
 @kind="drive#permission",
 @name="vamsi g",
 @role="writer",
 @self_link=
  "https://www.googleapis.com/drive/v2/files/1YPRe4NVaFh4_zsvRub7hs180651MezQ5/permissions/09144568628734991651",
 @type="user">

=> #<Google::Apis::DriveV2::Permission:0x00007feb9afeca08
 @deleted=false,
 @domain="gmail.com",
 @email_address="[email protected]",
 @etag="\"GB5K0nP_lpMg2gXYRx_Dj0Nb6Gw\"",
 @id="09144568628734991651",
 @kind="drive#permission",
 @name="vamsi g",
 @role="writer",
 @self_link=
  "https://www.googleapis.com/drive/v2/files/1YPRe4NVaFh4_zsvRub7hs180651MezQ5/permissions/09144568628734991651",
 @type="user">

vamsipavanmahesh avatar Dec 15 '20 11:12 vamsipavanmahesh

Hi! Unfortunately, this repo is just an open-source client for Google APIs. We're not the product team, and we generally can't provide support for the services themselves. The only thing I can suggest here is to try updating the expiration date on the server_permission object (i.e. the one passed back to you from the insert call) and send that back in the update call. (Maybe update is getting confused by the ID not being present in that object.) If that doesn't work, then I'd suggest contacting support (if you have a support contract with Google) or see the suggestions at https://developers.google.com/drive/api/v2/support

dazuma avatar Dec 22 '20 07:12 dazuma

We're not the product team, and we generally can't provide support for the services themselves

Then you folks have done a marvelous job in creating this library. Initially, it was confusing but once I understood every param is an object, it was a breeze to work with and the documentation in every class is superb. I will take this as inspiration if I have to create something like this in the future

vamsipavanmahesh avatar Dec 23 '20 01:12 vamsipavanmahesh

BTW, the suggested workaround did not work. So you might want to reclassify it as a bug, unless you were able to reproduce this and it was working for you. What we ended up doing was, delete the permission after a few hours by starting a background job

vamsipavanmahesh avatar Dec 23 '20 01:12 vamsipavanmahesh