gitlab-fog-azure-rm 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +7 -0
  2. data/.arclint +8 -0
  3. data/.codeclimate.yml +17 -0
  4. data/.gitignore +6 -0
  5. data/.gitlab-ci.yml +17 -0
  6. data/.hound.yml +2 -0
  7. data/.rubocop.yml +5 -0
  8. data/.rubocop_todo.yml +274 -0
  9. data/.travis.yml +49 -0
  10. data/CHANGELOG.md +414 -0
  11. data/CONTRIBUTING.md +40 -0
  12. data/CONTRIBUTORS.md +12 -0
  13. data/Gemfile +3 -0
  14. data/LICENSE.md +20 -0
  15. data/README.md +100 -0
  16. data/gitlab-fog-azure-rm.gemspec +31 -0
  17. data/lib/fog/azurerm.rb +30 -0
  18. data/lib/fog/azurerm/async_response.rb +44 -0
  19. data/lib/fog/azurerm/config.rb +1 -0
  20. data/lib/fog/azurerm/constants.rb +72 -0
  21. data/lib/fog/azurerm/credentials.rb +40 -0
  22. data/lib/fog/azurerm/custom_fog_errors.rb +52 -0
  23. data/lib/fog/azurerm/docs/storage.md +398 -0
  24. data/lib/fog/azurerm/docs/structure.md +53 -0
  25. data/lib/fog/azurerm/models/resources/azure_resource.rb +25 -0
  26. data/lib/fog/azurerm/models/resources/azure_resources.rb +40 -0
  27. data/lib/fog/azurerm/models/resources/dependency.rb +27 -0
  28. data/lib/fog/azurerm/models/resources/deployment.rb +65 -0
  29. data/lib/fog/azurerm/models/resources/deployments.rb +30 -0
  30. data/lib/fog/azurerm/models/resources/provider.rb +27 -0
  31. data/lib/fog/azurerm/models/resources/provider_resource_type.rb +22 -0
  32. data/lib/fog/azurerm/models/resources/resource_group.rb +34 -0
  33. data/lib/fog/azurerm/models/resources/resource_groups.rb +29 -0
  34. data/lib/fog/azurerm/models/storage/directories.rb +75 -0
  35. data/lib/fog/azurerm/models/storage/directory.rb +151 -0
  36. data/lib/fog/azurerm/models/storage/file.rb +265 -0
  37. data/lib/fog/azurerm/models/storage/files.rb +183 -0
  38. data/lib/fog/azurerm/models/storage/kind.rb +12 -0
  39. data/lib/fog/azurerm/models/storage/sku_name.rb +15 -0
  40. data/lib/fog/azurerm/models/storage/sku_tier.rb +12 -0
  41. data/lib/fog/azurerm/models/storage/storage_account.rb +92 -0
  42. data/lib/fog/azurerm/models/storage/storage_accounts.rb +47 -0
  43. data/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb +32 -0
  44. data/lib/fog/azurerm/requests/storage/acquire_container_lease.rb +32 -0
  45. data/lib/fog/azurerm/requests/storage/check_container_exists.rb +30 -0
  46. data/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb +30 -0
  47. data/lib/fog/azurerm/requests/storage/compare_container_blobs.rb +148 -0
  48. data/lib/fog/azurerm/requests/storage/copy_blob.rb +30 -0
  49. data/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb +30 -0
  50. data/lib/fog/azurerm/requests/storage/copy_object.rb +20 -0
  51. data/lib/fog/azurerm/requests/storage/create_block_blob.rb +108 -0
  52. data/lib/fog/azurerm/requests/storage/create_container.rb +40 -0
  53. data/lib/fog/azurerm/requests/storage/create_disk.rb +62 -0
  54. data/lib/fog/azurerm/requests/storage/create_page_blob.rb +31 -0
  55. data/lib/fog/azurerm/requests/storage/delete_blob.rb +32 -0
  56. data/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb +39 -0
  57. data/lib/fog/azurerm/requests/storage/delete_container.rb +31 -0
  58. data/lib/fog/azurerm/requests/storage/delete_disk.rb +36 -0
  59. data/lib/fog/azurerm/requests/storage/delete_object_url.rb +30 -0
  60. data/lib/fog/azurerm/requests/storage/get_blob.rb +163 -0
  61. data/lib/fog/azurerm/requests/storage/get_blob_http_url.rb +39 -0
  62. data/lib/fog/azurerm/requests/storage/get_blob_https_url.rb +39 -0
  63. data/lib/fog/azurerm/requests/storage/get_blob_properties.rb +55 -0
  64. data/lib/fog/azurerm/requests/storage/get_blob_url.rb +28 -0
  65. data/lib/fog/azurerm/requests/storage/get_container_acl.rb +30 -0
  66. data/lib/fog/azurerm/requests/storage/get_container_properties.rb +41 -0
  67. data/lib/fog/azurerm/requests/storage/get_container_url.rb +34 -0
  68. data/lib/fog/azurerm/requests/storage/get_object_url.rb +21 -0
  69. data/lib/fog/azurerm/requests/storage/list_blobs.rb +168 -0
  70. data/lib/fog/azurerm/requests/storage/list_containers.rb +73 -0
  71. data/lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb +110 -0
  72. data/lib/fog/azurerm/requests/storage/put_blob_block.rb +30 -0
  73. data/lib/fog/azurerm/requests/storage/put_blob_https_url.rb +39 -0
  74. data/lib/fog/azurerm/requests/storage/put_blob_metadata.rb +31 -0
  75. data/lib/fog/azurerm/requests/storage/put_blob_pages.rb +30 -0
  76. data/lib/fog/azurerm/requests/storage/put_blob_properties.rb +31 -0
  77. data/lib/fog/azurerm/requests/storage/put_container_acl.rb +31 -0
  78. data/lib/fog/azurerm/requests/storage/put_container_metadata.rb +31 -0
  79. data/lib/fog/azurerm/requests/storage/put_object_url.rb +30 -0
  80. data/lib/fog/azurerm/requests/storage/release_blob_lease.rb +30 -0
  81. data/lib/fog/azurerm/requests/storage/release_container_lease.rb +30 -0
  82. data/lib/fog/azurerm/requests/storage/save_page_blob.rb +111 -0
  83. data/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb +56 -0
  84. data/lib/fog/azurerm/storage.rb +126 -0
  85. data/lib/fog/azurerm/utilities/general.rb +186 -0
  86. data/lib/fog/azurerm/utilities/logger_messages.yml +19 -0
  87. data/lib/fog/azurerm/version.rb +5 -0
  88. data/rake-script.sh +10 -0
  89. data/rakefile +29 -0
  90. data/test/api_stub.rb +147 -0
  91. data/test/api_stub/models/storage/directory.rb +178 -0
  92. data/test/api_stub/models/storage/file.rb +181 -0
  93. data/test/api_stub/requests/storage/directory.rb +89 -0
  94. data/test/api_stub/requests/storage/file.rb +252 -0
  95. data/test/integration/README.md +14 -0
  96. data/test/integration/blob.rb +297 -0
  97. data/test/integration/container.rb +160 -0
  98. data/test/integration/credentials/azure.yml +5 -0
  99. data/test/integration/storage_account.rb +135 -0
  100. data/test/models/storage/test_directories.rb +74 -0
  101. data/test/models/storage/test_directory.rb +178 -0
  102. data/test/models/storage/test_file.rb +294 -0
  103. data/test/models/storage/test_files.rb +234 -0
  104. data/test/requests/storage/test_acquire_blob_lease.rb +36 -0
  105. data/test/requests/storage/test_acquire_container_lease.rb +36 -0
  106. data/test/requests/storage/test_check_container_exists.rb +18 -0
  107. data/test/requests/storage/test_commit_blob_blocks.rb +34 -0
  108. data/test/requests/storage/test_compare_container_blobs.rb +36 -0
  109. data/test/requests/storage/test_copy_blob.rb +39 -0
  110. data/test/requests/storage/test_copy_blob_from_uri.rb +36 -0
  111. data/test/requests/storage/test_create_block_blob.rb +80 -0
  112. data/test/requests/storage/test_create_container.rb +36 -0
  113. data/test/requests/storage/test_create_disk.rb +70 -0
  114. data/test/requests/storage/test_create_page_blob.rb +34 -0
  115. data/test/requests/storage/test_delete_blob.rb +42 -0
  116. data/test/requests/storage/test_delete_blob_https_url.rb +32 -0
  117. data/test/requests/storage/test_delete_container.rb +42 -0
  118. data/test/requests/storage/test_delete_disk.rb +30 -0
  119. data/test/requests/storage/test_get_blob.rb +141 -0
  120. data/test/requests/storage/test_get_blob_http_url.rb +30 -0
  121. data/test/requests/storage/test_get_blob_https_url.rb +32 -0
  122. data/test/requests/storage/test_get_blob_properties.rb +47 -0
  123. data/test/requests/storage/test_get_blob_url.rb +75 -0
  124. data/test/requests/storage/test_get_container_acl.rb +37 -0
  125. data/test/requests/storage/test_get_container_properties.rb +45 -0
  126. data/test/requests/storage/test_get_container_url.rb +33 -0
  127. data/test/requests/storage/test_list_blobs.rb +77 -0
  128. data/test/requests/storage/test_list_containers.rb +54 -0
  129. data/test/requests/storage/test_multipart_save_block_blob.rb +105 -0
  130. data/test/requests/storage/test_put_blob_block.rb +34 -0
  131. data/test/requests/storage/test_put_blob_https_url.rb +32 -0
  132. data/test/requests/storage/test_put_blob_metadata.rb +36 -0
  133. data/test/requests/storage/test_put_blob_pages.rb +34 -0
  134. data/test/requests/storage/test_put_blob_properties.rb +39 -0
  135. data/test/requests/storage/test_put_container_acl.rb +34 -0
  136. data/test/requests/storage/test_put_container_metadata.rb +36 -0
  137. data/test/requests/storage/test_release_blob_lease.rb +34 -0
  138. data/test/requests/storage/test_release_container_lease.rb +34 -0
  139. data/test/requests/storage/test_save_page_blob.rb +115 -0
  140. data/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb +148 -0
  141. data/test/smoke_tests/compute/test_resource_group_smoke.rb +37 -0
  142. data/test/test_credentials.rb +63 -0
  143. data/test/test_helper.rb +846 -0
  144. metadata +352 -0
@@ -0,0 +1,25 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ # This class is giving implementation of create/save and
5
+ # delete/destroy for resources.
6
+ class AzureResource < Fog::Model
7
+ attribute :id
8
+ attribute :name
9
+ attribute :type
10
+ attribute :location
11
+ attribute :tags
12
+
13
+ def self.parse(resource)
14
+ hash = {}
15
+ hash['id'] = resource.id
16
+ hash['name'] = resource.name
17
+ hash['type'] = resource.type
18
+ hash['location'] = resource.location
19
+ hash['tags'] = resource.tags
20
+ hash
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,40 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ # This class is giving implementation of all/list and get.
5
+ class AzureResources < Fog::Collection
6
+ attribute :tag_name
7
+ attribute :tag_value
8
+ model Fog::Resources::AzureRM::AzureResource
9
+
10
+ def all
11
+ unless tag_name.nil? && tag_value.nil?
12
+ resources = []
13
+ service.list_tagged_resources(tag_name, tag_value).each do |resource|
14
+ resources << Fog::Resources::AzureRM::AzureResource.parse(resource)
15
+ end
16
+ resources.inspect
17
+ return load(resources)
18
+ end
19
+ nil
20
+ end
21
+
22
+ def get(resource_id)
23
+ all.find { |f| f.id == resource_id }
24
+ end
25
+
26
+ def check_azure_resource_exists(resource_id, api_version)
27
+ service.check_azure_resource_exists(resource_id, api_version)
28
+ end
29
+
30
+ def list_resources_in_resource_group(resource_group_name)
31
+ resources = []
32
+ service.list_resources_in_resource_group(resource_group_name).each do |resource|
33
+ resources.push(Fog::Resources::AzureRM::AzureResource.parse(resource))
34
+ end
35
+ load(resources)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ # Dependency model class
5
+ class Dependency < Fog::Model
6
+ attribute :id
7
+ attribute :resource_name
8
+ attribute :resource_type
9
+ attribute :depends_on
10
+
11
+ def self.parse(dependency)
12
+ hash = {}
13
+ hash['id'] = dependency.id
14
+ hash['resource_name'] = dependency.resource_name
15
+ hash['resource_type'] = dependency.resource_type
16
+
17
+ hash['depends_on'] = []
18
+ dependency.depends_on.each do |sub_dependency|
19
+ dependency_obj = Fog::Resources::AzureRM::Dependency.new
20
+ hash['depends_on'] << dependency_obj.merge_attributes(Fog::Resources::AzureRM::Dependency.parse(sub_dependency))
21
+ end if dependency.respond_to?('depends_on')
22
+ hash
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,65 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ # This class is giving implementation of create/save and
5
+ # delete/destroy for Deployment model.
6
+ class Deployment < Fog::Model
7
+ identity :name
8
+ attribute :id
9
+ attribute :resource_group
10
+ attribute :correlation_id
11
+ attribute :timestamp
12
+ attribute :outputs
13
+ attribute :providers
14
+ attribute :dependencies
15
+ attribute :template_link
16
+ attribute :parameters_link
17
+ attribute :mode
18
+ attribute :debug_setting
19
+ attribute :content_version
20
+ attribute :provisioning_state
21
+
22
+ def self.parse(deployment)
23
+ hash = {}
24
+ hash['name'] = deployment.name
25
+ hash['id'] = deployment.id
26
+ hash['resource_group'] = get_resource_from_resource_id(deployment.id, RESOURCE_GROUP_NAME)
27
+ hash['correlation_id'] = deployment.properties.correlation_id
28
+ hash['timestamp'] = deployment.properties.timestamp
29
+ hash['outputs'] = deployment.properties.outputs
30
+
31
+ hash['providers'] = []
32
+ deployment.properties.providers.each do |provider|
33
+ provider_obj = Fog::Resources::AzureRM::Provider.new
34
+ hash['providers'] << provider_obj.merge_attributes(Fog::Resources::AzureRM::Provider.parse(provider))
35
+ end
36
+
37
+ hash['dependencies'] = []
38
+ deployment.properties.dependencies.each do |dependency|
39
+ dependency_obj = Fog::Resources::AzureRM::Dependency.new
40
+ hash['dependencies'] << dependency_obj.merge_attributes(Fog::Resources::AzureRM::Dependency.parse(dependency))
41
+ end
42
+
43
+ hash['template_link'] = deployment.properties.template_link.uri
44
+ hash['parameters_link'] = deployment.properties.parameters_link.uri
45
+ hash['content_version'] = deployment.properties.template_link.content_version
46
+ hash['mode'] = deployment.properties.mode
47
+ hash['debug_setting'] = deployment.properties.debug_setting.detail_level unless deployment.properties.debug_setting.nil?
48
+ hash['provisioning_state'] = deployment.properties.provisioning_state
49
+ hash
50
+ end
51
+
52
+ def save
53
+ requires :name, :resource_group, :template_link, :parameters_link
54
+
55
+ deployment = service.create_deployment(resource_group, name, template_link, parameters_link)
56
+ merge_attributes(Fog::Resources::AzureRM::Deployment.parse(deployment))
57
+ end
58
+
59
+ def destroy
60
+ service.delete_deployment(resource_group, name)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ # Deployments collection class
5
+ class Deployments < Fog::Collection
6
+ attribute :resource_group
7
+ model Fog::Resources::AzureRM::Deployment
8
+
9
+ def all
10
+ requires :resource_group
11
+ deployments = []
12
+ service.list_deployments(resource_group).each do |deployment|
13
+ deployments << Fog::Resources::AzureRM::Deployment.parse(deployment)
14
+ end
15
+ load(deployments)
16
+ end
17
+
18
+ def get(resource_group_name, deployment_name)
19
+ deployment = service.get_deployment(resource_group_name, deployment_name)
20
+ deployment_fog = Fog::Resources::AzureRM::Deployment.new(service: service)
21
+ deployment_fog.merge_attributes(Fog::Resources::AzureRM::Deployment.parse(deployment))
22
+ end
23
+
24
+ def check_deployment_exists(resource_group_name, deployment_name)
25
+ service.check_deployment_exists(resource_group_name, deployment_name)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ # Provider model class
5
+ class Provider < Fog::Model
6
+ attribute :id
7
+ attribute :namespace
8
+ attribute :registration_state
9
+ attribute :resource_types
10
+
11
+ def self.parse(provider)
12
+ hash = {}
13
+ hash['id'] = provider.id
14
+ hash['namespace'] = provider.namespace
15
+ hash['registration_state'] = provider.registration_state if provider.respond_to?('registration_state')
16
+
17
+ hash['resource_types'] = []
18
+ provider.resource_types.each do |provider_resource_type|
19
+ provider_resource_type_obj = Fog::Resources::AzureRM::ProviderResourceType.new
20
+ hash['resource_types'] << provider_resource_type_obj.merge_attributes(Fog::Resources::AzureRM::ProviderResourceType.parse(provider_resource_type))
21
+ end
22
+ hash
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,22 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ # ProviderResourceType model class
5
+ class ProviderResourceType < Fog::Model
6
+ attribute :resource_type
7
+ attribute :locations
8
+ attribute :api_versions
9
+ attribute :properties
10
+
11
+ def self.parse(provider_resource_type)
12
+ hash = {}
13
+ hash['resource_type'] = provider_resource_type.resource_type
14
+ hash['locations'] = provider_resource_type.locations
15
+ hash['api_versions'] = provider_resource_type.api_versions if provider_resource_type.respond_to?('api_versions')
16
+ hash['properties'] = provider_resource_type.properties if provider_resource_type.respond_to?('properties')
17
+ hash
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ # This class is giving implementation of create/save and
5
+ # delete/destroy for resource group.
6
+ class ResourceGroup < Fog::Model
7
+ identity :name
8
+ attribute :id
9
+ attribute :location
10
+ attribute :tags
11
+
12
+ def self.parse(resource_group)
13
+ hash = {}
14
+ hash['id'] = resource_group.id
15
+ hash['name'] = resource_group.name
16
+ hash['location'] = resource_group.location
17
+ hash['tags'] = resource_group.tags
18
+ hash
19
+ end
20
+
21
+ def save
22
+ requires :name
23
+ requires :location
24
+ resource_group = service.create_resource_group(name, location, tags)
25
+ merge_attributes(Fog::Resources::AzureRM::ResourceGroup.parse(resource_group))
26
+ end
27
+
28
+ def destroy
29
+ service.delete_resource_group(name)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ module Fog
2
+ module Resources
3
+ class AzureRM
4
+ # This class is giving implementation of all/list, get and
5
+ # check name availability for resource groups.
6
+ class ResourceGroups < Fog::Collection
7
+ model Fog::Resources::AzureRM::ResourceGroup
8
+
9
+ def all
10
+ resource_groups = []
11
+ service.list_resource_groups.each do |resource_group|
12
+ resource_groups.push(Fog::Resources::AzureRM::ResourceGroup.parse(resource_group))
13
+ end
14
+ load(resource_groups)
15
+ end
16
+
17
+ def get(resource_group_name)
18
+ resource_group = service.get_resource_group(resource_group_name)
19
+ resource_group_fog = Fog::Resources::AzureRM::ResourceGroup.new(service: service)
20
+ resource_group_fog.merge_attributes(Fog::Resources::AzureRM::ResourceGroup.parse(resource_group))
21
+ end
22
+
23
+ def check_resource_group_exists(resource_group_name)
24
+ service.check_resource_group_exists(resource_group_name)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,75 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class is giving implementation of listing containers.
5
+ class Directories < Fog::Collection
6
+ model Fog::Storage::AzureRM::Directory
7
+
8
+ # List all directories(containers) in the storage account.
9
+ #
10
+ # @return [Fog::Storage::AzureRM::Directories]
11
+ #
12
+ def all
13
+ containers = service.list_containers
14
+ data = []
15
+ containers.each do |container|
16
+ c = parse_storage_object(container)
17
+ c[:acl] = 'unknown'
18
+ data << c
19
+ end
20
+ load(data)
21
+ end
22
+
23
+ # Get a directory with files(blobs) under this directory.
24
+ # You can set max_keys to 1 if you do not want to return all files under this directory.
25
+ #
26
+ # @param identity [String] Name of directory
27
+ # @param options [Hash]
28
+ # @option options [String] max_keys or
29
+ # max_results Sets the maximum number of files to return.
30
+ # @option options [String] delimiter Sets to cause that the operation returns a BlobPrefix element in the response body that acts
31
+ # as a placeholder for all files whose names begin with the same substring up to the appearance
32
+ # of the delimiter character. The delimiter may be a single character or a string.
33
+ # @option options [String] marker Sets the identifier that specifies the portion of the list to be returned.
34
+ # @option options [String] prefix Sets filters the results to return only files whose name begins with the specified prefix.
35
+ #
36
+ # @return [Fog::Storage::AzureRM::Directory] A directory. Return nil if the directory does not exist.
37
+ #
38
+ def get(identity, options = {})
39
+ remap_attributes(options, max_keys: :max_results)
40
+
41
+ container = service.get_container_properties(identity)
42
+ data = parse_storage_object(container)
43
+ data[:acl] = 'unknown'
44
+
45
+ directory = new(key: identity, is_persisted: true)
46
+ directory.merge_attributes(data)
47
+
48
+ data = service.list_blobs(identity, options)
49
+
50
+ new_options = options.merge(next_marker: data[:next_marker])
51
+ directory.files.merge_attributes(new_options)
52
+
53
+ blobs = []
54
+ data[:blobs].each do |blob|
55
+ blobs << parse_storage_object(blob)
56
+ end
57
+ directory.files.load(blobs)
58
+ directory
59
+ rescue Exception => error
60
+ return nil if error.message == 'NotFound'
61
+ raise error
62
+ end
63
+
64
+ def delete_temporary_container(storage_account_name, access_key, container_name)
65
+ storage_data = Fog::Storage::AzureRM.new(azure_storage_account_name: storage_account_name, azure_storage_access_key: access_key)
66
+ storage_data.delete_container(container_name)
67
+ end
68
+
69
+ def check_container_exists(name)
70
+ service.check_container_exists(name)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,151 @@
1
+ module Fog
2
+ module Storage
3
+ class AzureRM
4
+ # This class is giving implementation of create and delete a container.
5
+ class Directory < Fog::Model
6
+ VALID_ACLS = ['container', 'blob', 'unknown', nil].freeze
7
+
8
+ attr_writer :acl
9
+
10
+ identity :key, aliases: %w(Name name)
11
+ attribute :etag, aliases: %w(Etag ETag)
12
+ attribute :last_modified, aliases: %w(Last-Modified LastModified), type: 'time'
13
+ attribute :lease_duration, aliases: %w(Lease-Duration LeaseDuration)
14
+ attribute :lease_state, aliases: %w(Lease-State LeaseState)
15
+ attribute :lease_status, aliases: %w(Lease-Status LeaseStatus)
16
+
17
+ attribute :metadata
18
+
19
+ # Set the the permission
20
+ #
21
+ # @param new_acl [String] permission. Options: container, blob or nil. unknown is for internal usage.
22
+ # container: Full public read access. Container and blob data can be read via anonymous request.
23
+ # Clients can enumerate blobs within the container via anonymous request, but cannot
24
+ # enumerate containers within the storage account.
25
+ # blob: Public read access for blobs only. Blob data within this container can be read via
26
+ # anonymous request, but container data is not available. Clients cannot enumerate blobs
27
+ # within the container via anonymous request.
28
+ # nil: No public read access. Container and blob data can be read by the account owner only.
29
+ # unknown: Internal usage in fog-azure-rm.
30
+ #
31
+ # @return [String] Permission.
32
+ #
33
+ # @exception ArgumentError Raised when new_acl is not 'container', 'blob', nil or 'unknown'.
34
+ #
35
+ # Reference: https://msdn.microsoft.com/en-us/library/azure/dd179391.aspx
36
+ #
37
+ def acl=(new_acl)
38
+ raise ArgumentError.new("acl must be one of [#{VALID_ACLS.join(', ')}nil]") unless VALID_ACLS.include?(new_acl)
39
+
40
+ attributes[:acl] = new_acl
41
+ end
42
+
43
+ # Get the the permission
44
+ #
45
+ # required attributes: key
46
+ #
47
+ # @return [String] Permission.
48
+ #
49
+ def acl
50
+ requires :key
51
+
52
+ return attributes[:acl] if attributes[:acl] != 'unknown' || !persisted?
53
+
54
+ data = service.get_container_acl(key)
55
+ attributes[:acl] = data[0]
56
+ end
57
+
58
+ # Destroy directory.
59
+ #
60
+ # required attributes: key
61
+ #
62
+ # @return [Boolean] True if successful
63
+ #
64
+ def destroy
65
+ requires :key
66
+
67
+ service.delete_container(key)
68
+ end
69
+
70
+ # Get files under this directory.
71
+ # If you have set max_results or max_keys when getting this directory by directories.get,
72
+ # files may be incomplete. You need to use files.all to get all files under this directory.
73
+ #
74
+ # @return [Fog::Storage::AzureRM::Files] Files.
75
+ #
76
+ def files
77
+ @files ||= Fog::Storage::AzureRM::Files.new(directory: self, service: service)
78
+ end
79
+
80
+ # Set the container permission to public or private
81
+ #
82
+ # @param [Boolean] True: public(container); False: private(nil)
83
+ #
84
+ # @return [Boolean] True if public; Otherwise return false.
85
+ #
86
+ def public=(new_public)
87
+ attributes[:acl] = new_public ? 'container' : nil
88
+ new_public
89
+ end
90
+
91
+ # Get the public URL of the directory
92
+ #
93
+ # required attributes: key
94
+ #
95
+ # @param options [Hash]
96
+ # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https.
97
+ #
98
+ # @return [String] A public URL.
99
+ #
100
+ def public_url(options = {})
101
+ requires :key
102
+
103
+ service.get_container_url(key, options) if acl == 'container'
104
+ end
105
+
106
+ # Create/Update the directory
107
+ #
108
+ # required attributes: key
109
+ #
110
+ # @param options [Hash]
111
+ # @option options [Boolean] is_create Sets whether to create or update the directory. Default is true(create).
112
+ # Will update metadata and acl when is_create is set to false.
113
+ #
114
+ # @return [Boolean] True if successful.
115
+ #
116
+ def save(options = {})
117
+ requires :key
118
+
119
+ is_create = options.delete(:is_create)
120
+ if is_create.nil? || is_create
121
+ options = {}
122
+ options[:public_access_level] = acl if acl != 'unknown'
123
+ options[:metadata] = metadata if metadata
124
+
125
+ container = service.create_container(key, options)
126
+ else
127
+ service.put_container_acl(key, acl) if acl != 'unknown'
128
+ service.put_container_metadata(key, metadata) if metadata
129
+ container = service.get_container_properties(key)
130
+ end
131
+
132
+ attributes[:is_persisted] = true
133
+ data = parse_storage_object(container)
134
+ merge_attributes(data)
135
+
136
+ true
137
+ end
138
+
139
+ # Check whether the directory is created.
140
+ #
141
+ # @return [Boolean] True if the file is created. Otherwise return false.
142
+ #
143
+ def persisted?
144
+ # is_persisted is true in case of directories.get or after #save
145
+ # last_modified is set in case of directories.all
146
+ attributes[:is_persisted] || !attributes[:last_modified].nil?
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end