Class: Google::Cloud::Storage::Bucket::Acl

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/storage/bucket/acl.rb

Overview

Bucket Access Control List

Represents a Bucket's Access Control List.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.readers.each { |reader| puts reader }

Instance Method Summary collapse

Instance Method Details

#add_owner(entity) ⇒ Object

Grants owner permission to the bucket.

Examples:

Grant access to a user by prepending "user-" to an email:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

email = "heidi@example.net"
bucket.acl.add_owner "user-#{email}"

Grant access to a group by prepending "group-" to email:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

email = "authors@example.net"
bucket.acl.add_owner "group-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId
    • user-email
    • group-groupId
    • group-email
    • domain-domain
    • project-team-projectId
    • allUsers
    • allAuthenticatedUsers


175
176
177
178
179
180
# File 'lib/google/cloud/storage/bucket/acl.rb', line 175

def add_owner entity
  gapi = @service.insert_bucket_acl @bucket, entity, "OWNER"
  entity = gapi.entity
  @owners.push entity unless @owners.nil?
  entity
end

#add_reader(entity) ⇒ Object

Grants reader permission to the bucket.

Examples:

Grant access to a user by prepending "user-" to an email:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

email = "heidi@example.net"
bucket.acl.add_reader "user-#{email}"

Grant access to a group by prepending "group-" to email:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

email = "authors@example.net"
bucket.acl.add_reader "group-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId
    • user-email
    • group-groupId
    • group-email
    • domain-domain
    • project-team-projectId
    • allUsers
    • allAuthenticatedUsers


259
260
261
262
263
264
# File 'lib/google/cloud/storage/bucket/acl.rb', line 259

def add_reader entity
  gapi = @service.insert_bucket_acl @bucket, entity, "READER"
  entity = gapi.entity
  @readers.push entity unless @readers.nil?
  entity
end

#add_writer(entity) ⇒ Object

Grants writer permission to the bucket.

Examples:

Grant access to a user by prepending "user-" to an email:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

email = "heidi@example.net"
bucket.acl.add_writer "user-#{email}"

Grant access to a group by prepending "group-" to email:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

email = "authors@example.net"
bucket.acl.add_writer "group-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId
    • user-email
    • group-groupId
    • group-email
    • domain-domain
    • project-team-projectId
    • allUsers
    • allAuthenticatedUsers


217
218
219
220
221
222
# File 'lib/google/cloud/storage/bucket/acl.rb', line 217

def add_writer entity
  gapi = @service.insert_bucket_acl @bucket, entity, "WRITER"
  entity = gapi.entity
  @writers.push entity unless @writers.nil?
  entity
end

#auth!Object Also known as: authenticatedRead!, auth_read!, authenticated!, authenticated_read!

Convenience method to apply the authenticatedRead predefined ACL rule to the bucket.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.auth!


320
321
322
# File 'lib/google/cloud/storage/bucket/acl.rb', line 320

def auth!
  update_predefined_acl! "authenticatedRead"
end

#delete(entity) ⇒ Object

Permanently deletes the entity from the bucket's access control list.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

email = "heidi@example.net"
bucket.acl.delete "user-#{email}"

Parameters:

  • entity (String)

    The entity holding the permission, in one of the following forms:

    • user-userId
    • user-email
    • group-groupId
    • group-email
    • domain-domain
    • project-team-projectId
    • allUsers
    • allAuthenticatedUsers


292
293
294
295
296
297
298
# File 'lib/google/cloud/storage/bucket/acl.rb', line 292

def delete entity
  @service.delete_bucket_acl @bucket, entity
  @owners.delete entity  unless @owners.nil?
  @writers.delete entity unless @writers.nil?
  @readers.delete entity unless @readers.nil?
  true
end

#ownersArray<String>

Lists the owners of the bucket.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.owners.each { |owner| puts owner }

Returns:

  • (Array<String>)


97
98
99
100
# File 'lib/google/cloud/storage/bucket/acl.rb', line 97

def owners
  reload! if @owners.nil?
  @owners
end

#private!Object

Convenience method to apply the private predefined ACL rule to the bucket.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.private!


341
342
343
# File 'lib/google/cloud/storage/bucket/acl.rb', line 341

def private!
  update_predefined_acl! "private"
end

#project_private!Object Also known as: projectPrivate!

Convenience method to apply the projectPrivate predefined ACL rule to the bucket.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.project_private!


358
359
360
# File 'lib/google/cloud/storage/bucket/acl.rb', line 358

def project_private!
  update_predefined_acl! "projectPrivate"
end

#public!Object Also known as: publicRead!, public_read!

Convenience method to apply the publicRead predefined ACL rule to the bucket.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.public!


376
377
378
# File 'lib/google/cloud/storage/bucket/acl.rb', line 376

def public!
  update_predefined_acl! "publicRead"
end

#public_write!Object Also known as: publicReadWrite!

Convenience method to apply the publicReadWrite predefined ACL rule to the bucket.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.public_write!


394
395
396
# File 'lib/google/cloud/storage/bucket/acl.rb', line 394

def public_write!
  update_predefined_acl! "publicReadWrite"
end

#readersArray<String>

Lists the readers of the bucket.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.readers.each { |reader| puts reader }

Returns:

  • (Array<String>)


135
136
137
138
# File 'lib/google/cloud/storage/bucket/acl.rb', line 135

def readers
  reload! if @readers.nil?
  @readers
end

#reload!Object Also known as: refresh!

Reloads all Access Control List data for the bucket.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.reload!


74
75
76
77
78
79
80
# File 'lib/google/cloud/storage/bucket/acl.rb', line 74

def reload!
  gapi = @service.list_bucket_acls @bucket
  acls = Array(gapi.items)
  @owners  = entities_from_acls acls, "OWNER"
  @writers = entities_from_acls acls, "WRITER"
  @readers = entities_from_acls acls, "READER"
end

#writersArray<String>

Lists the owners of the bucket.

Examples:

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

bucket = storage.bucket "my-bucket"

bucket.acl.writers.each { |writer| puts writer }

Returns:

  • (Array<String>)


116
117
118
119
# File 'lib/google/cloud/storage/bucket/acl.rb', line 116

def writers
  reload! if @writers.nil?
  @writers
end