Class: Fog::Storage::AzureRM::Directory

Inherits:
Model
  • Object
show all
Includes:
AzureRM::Utilities::General
Defined in:
lib/fog/azurerm/models/storage/directory.rb

Overview

This class is giving implementation of create and delete a container.

Constant Summary collapse

VALID_ACLS =
['container', 'blob', 'unknown', nil].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AzureRM::Utilities::General

#active_directory_service_settings, #current_time, #get_blob_endpoint, #get_blob_endpoint_with_domain, #get_circuit_name_from_id, #get_end_point_type, #get_hash_from_object, #get_image_name, #get_record_set_from_id, #get_record_type, #get_resource_from_resource_id, #get_resource_group_from_id, #get_subscription_id, #get_traffic_manager_profile_name_from_endpoint_id, #get_type_from_recordset_type, #get_virtual_machine_from_id, #get_virtual_network_from_id, #parse_storage_object, #raise_azure_exception, #random_string, #remove_trailing_periods_from_path_segments, #resource_manager_endpoint_url, #resource_not_found?, #storage_endpoint_suffix, #validate_params

Instance Attribute Details

#aclString

Get the the permission

required attributes: key

Returns:

  • (String)

    Permission.



51
52
53
54
55
56
57
58
# File 'lib/fog/azurerm/models/storage/directory.rb', line 51

def acl
  requires :key

  return attributes[:acl] if attributes[:acl] != 'unknown' || !persisted?

  data = service.get_container_acl(key)
  attributes[:acl] = data[0]
end

Instance Method Details

#destroyBoolean

Destroy directory.

required attributes: key

Returns:

  • (Boolean)

    True if successful



66
67
68
69
70
# File 'lib/fog/azurerm/models/storage/directory.rb', line 66

def destroy
  requires :key

  service.delete_container(key)
end

#filesFog::Storage::AzureRM::Files

Get files under this directory. If you have set max_results or max_keys when getting this directory by directories.get, files may be incomplete. You need to use files.all to get all files under this directory.

Returns:



78
79
80
# File 'lib/fog/azurerm/models/storage/directory.rb', line 78

def files
  @files ||= Fog::Storage::AzureRM::Files.new(directory: self, service: service)
end

#persisted?Boolean

Check whether the directory is created.

Returns:

  • (Boolean)

    True if the file is created. Otherwise return false.



145
146
147
148
149
# File 'lib/fog/azurerm/models/storage/directory.rb', line 145

def persisted?
  # is_persisted is true in case of directories.get or after #save
  # last_modified is set in case of directories.all
  attributes[:is_persisted] || !attributes[:last_modified].nil?
end

#public=(new_public) ⇒ Boolean

Set the container permission to public or private

Parameters:

  • True: (Boolean)

    public(container); False: private(nil)

Returns:

  • (Boolean)

    True if public; Otherwise return false.



88
89
90
91
# File 'lib/fog/azurerm/models/storage/directory.rb', line 88

def public=(new_public)
  attributes[:acl] = new_public ? 'container' : nil
  new_public
end

#public_url(options = {}) ⇒ String

Get the public URL of the directory

required attributes: key

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • scheme (String)

    Sets which URL to get, http or https. Options: https or http. Default is https.

Returns:

  • (String)

    A public URL.



102
103
104
105
106
# File 'lib/fog/azurerm/models/storage/directory.rb', line 102

def public_url(options = {})
  requires :key

  service.get_container_url(key, options) if acl == 'container'
end

#save(options = {}) ⇒ Boolean

Create/Update the directory

required attributes: key

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • is_create (Boolean)

    Sets whether to create or update the directory. Default is true(create). Will update metadata and acl when is_create is set to false.

Returns:

  • (Boolean)

    True if successful.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/fog/azurerm/models/storage/directory.rb', line 118

def save(options = {})
  requires :key

  is_create = options.delete(:is_create)
  if is_create.nil? || is_create
    options = {}
    options[:public_access_level] = acl if acl != 'unknown'
    options[:metadata] =  if 

    container = service.create_container(key, options)
  else
    service.put_container_acl(key, acl) if acl != 'unknown'
    service.(key, ) if 
    container = service.get_container_properties(key)
  end

  attributes[:is_persisted] = true
  data = parse_storage_object(container)
  merge_attributes(data)

  true
end