class Google::Cloud::Storage::HmacKey

# HmacKey

Represents the metadata for an HMAC key, and also includes the key's secret if returned by the {Project#create_hmac_key} creation method.

@see cloud.google.com/storage/docs/migrating#migration-simple

Migrating from Amazon S3 to Cloud Storage - Simple migration

@attr_reader [String, nil] secret HMAC secret key material, or `nil` if

the key was not returned by the {Project#create_hmac_key} creation
method.

@example

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

service_account_email = "my_account@developer.gserviceaccount.com"
hmac_key = storage.create_hmac_key service_account_email
hmac_key.secret # ...

hmac_key = storage.hmac_key hmac_key.access_id
hmac_key.secret # nil

hmac_key.inactive!
hmac_key.delete

Attributes

gapi[RW]

@private The Google API Client object.

secret[R]
service[RW]

@private The Connection object.

user_project[RW]

@private A boolean value or a project ID string to indicate the project to be billed for operations.

Public Class Methods

from_gapi(gapi, service, user_project: nil) click to toggle source

@private New HmacKey from a Google::Apis::StorageV1::HmacKey object.

@param [Google::Apis::StorageV1::HmacKey] gapi

# File lib/google/cloud/storage/hmac_key.rb, line 272
def self.from_gapi gapi, service, user_project: nil
  hmac_key = from_gapi_metadata gapi.metadata,
                                service,
                                user_project: user_project
  hmac_key.tap do |f|
    f.instance_variable_set :@secret, gapi.secret
  end
end
from_gapi_metadata(gapi, service, user_project: nil) click to toggle source

@private New HmacKey from a Google::Apis::StorageV1::HmacKeyMetadata object.

@param [Google::Apis::StorageV1::HmacKeyMetadata] gapi

# File lib/google/cloud/storage/hmac_key.rb, line 288
def self.from_gapi_metadata gapi, service, user_project: nil
  new.tap do |f|
    f.gapi = gapi
    f.service = service
    f.user_project = user_project
  end
end
new() click to toggle source

@private Creates an HmacKey object.

# File lib/google/cloud/storage/hmac_key.rb, line 67
def initialize
  @bucket = nil
  @service = nil
  @gapi = nil
  @user_project = nil
end

Public Instance Methods

access_id() click to toggle source

The ID of the HMAC Key.

@return [String]

# File lib/google/cloud/storage/hmac_key.rb, line 79
def access_id
  @gapi.access_id
end
active!() click to toggle source

Updates the state of the HMAC key to `ACTIVE`.

@return [Google::Cloud::Storage::HmacKey] Returns the HMAC key for

method chaining.

@example

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

hmac_key = storage.hmac_keys.first

hmac_key.active!
hmac_key.state # "ACTIVE"
# File lib/google/cloud/storage/hmac_key.rb, line 181
def active!
  put_gapi! "ACTIVE"
  self
end
active?() click to toggle source

Whether the state of the HMAC key is `ACTIVE`.

@return [Boolean]

# File lib/google/cloud/storage/hmac_key.rb, line 161
def active?
  state == "ACTIVE"
end
api_url() click to toggle source

A URL that can be used to access the HMAC key using the REST API.

@return [String]

# File lib/google/cloud/storage/hmac_key.rb, line 88
def api_url
  @gapi.self_link
end
created_at() click to toggle source

Creation time of the HMAC key.

@return [String]

# File lib/google/cloud/storage/hmac_key.rb, line 97
def created_at
  @gapi.time_created
end
delete()
Alias for: delete!
delete!() click to toggle source

Deletes the HMAC key, and loads the new state of the HMAC key, which will be `DELETED`.

The API call to delete the HMAC key may be retried under certain conditions. See {Google::Cloud#storage} to control this behavior.

@return [Google::Cloud::Storage::HmacKey] Returns the HMAC key for

method chaining.

@example

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

hmac_key = storage.hmac_keys.first

hmac_key.inactive!.delete!
# File lib/google/cloud/storage/hmac_key.rb, line 244
def delete!
  ensure_service!
  @service.delete_hmac_key access_id,
                           project_id: project_id,
                           user_project: @user_project
  @gapi = @service.get_hmac_key access_id, project_id: project_id,
                                           user_project: @user_project
  self
end
Also aliased as: delete
deleted?() click to toggle source

Whether the state of the HMAC key is `DELETED`.

@return [Boolean]

# File lib/google/cloud/storage/hmac_key.rb, line 221
def deleted?
  state == "DELETED"
end
etag() click to toggle source

HTTP 1.1 Entity tag for the HMAC key.

@return [String]

# File lib/google/cloud/storage/hmac_key.rb, line 106
def etag
  @gapi.etag
end
id() click to toggle source

The ID of the HMAC key, including the Project ID and the Access ID.

@return [String]

# File lib/google/cloud/storage/hmac_key.rb, line 115
def id
  @gapi.id
end
inactive!() click to toggle source

Updates the state of the HMAC key to `INACTIVE`.

@return [Google::Cloud::Storage::HmacKey] Returns the HMAC key for

method chaining.

@example

require "google/cloud/storage"

storage = Google::Cloud::Storage.new

hmac_key = storage.hmac_keys.first

hmac_key.inactive!
hmac_key.state # "INACTIVE"
# File lib/google/cloud/storage/hmac_key.rb, line 211
def inactive!
  put_gapi! "INACTIVE"
  self
end
inactive?() click to toggle source

Whether the state of the HMAC key is `INACTIVE`.

@return [Boolean]

# File lib/google/cloud/storage/hmac_key.rb, line 191
def inactive?
  state == "INACTIVE"
end
project_id() click to toggle source

Project ID owning the service account to which the key authenticates.

@return [String]

# File lib/google/cloud/storage/hmac_key.rb, line 124
def project_id
  @gapi.project_id
end
refresh!()
Alias for: reload!
reload!() click to toggle source

Reloads the HMAC key with current data from the Storage service.

# File lib/google/cloud/storage/hmac_key.rb, line 258
def reload!
  ensure_service!
  @gapi = service.get_hmac_key access_id, project_id: project_id,
                                          user_project: user_project
  self
end
Also aliased as: refresh!
service_account_email() click to toggle source

The email address of the key's associated service account.

@return [String]

# File lib/google/cloud/storage/hmac_key.rb, line 133
def service_account_email
  @gapi.service_account_email
end
state() click to toggle source

The state of the key. Can be one of `ACTIVE`, `INACTIVE`, or `DELETED`.

@return [String]

# File lib/google/cloud/storage/hmac_key.rb, line 143
def state
  @gapi.state
end
updated_at() click to toggle source

Last modification time of the HMAC key metadata.

@return [String]

# File lib/google/cloud/storage/hmac_key.rb, line 152
def updated_at
  @gapi.updated
end

Protected Instance Methods

ensure_service!() click to toggle source

Raise an error unless an active service is available.

# File lib/google/cloud/storage/hmac_key.rb, line 300
def ensure_service!
  raise "Must have active connection" unless service
end
put_gapi!(new_state) click to toggle source
# File lib/google/cloud/storage/hmac_key.rb, line 304
def put_gapi! new_state
  ensure_service!
  put_gapi = @gapi.dup
  put_gapi.state = new_state
  @gapi = service.update_hmac_key access_id, put_gapi,
                                  project_id: project_id,
                                  user_project: @user_project
  self
end