gitlab-fog-azure-rm 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc0e6fc125b778bb49c22a6fbfeb0ab779d99bfffaca5496df1834d2a0f69a86
4
- data.tar.gz: 5f9ce8aa7d939260edc6047636e6fdfbebaeae6cd7fd611921aa7cc2a3c36056
3
+ metadata.gz: 26308fac90191e41fa3a0cfe59f7c02159c5ac5c846c2fc958038d1fbaa9bf34
4
+ data.tar.gz: 9b382c3381a912f1c847c7757576f467750d9fedfb08304fa47e663fb7f34ad0
5
5
  SHA512:
6
- metadata.gz: 1578489ca552ed032d47387738f1b8807f467bac75b1d2446fe0ea547ed8b96b81d44c9af7c3134d50da7bb86158e757f8bb18ce4e3e998a9badfb5ce76a55e4
7
- data.tar.gz: ff5993b7140d6e3dd0de19d776dd2666980f65a1cb0baeee5abc28ed98eb29a71386108763530f591cb768116493994fbdec1bd877a2c8939c31c6cb85535385
6
+ metadata.gz: f54b5e063064523fbb79ea1aea50ad6847a20c9ffc47a81ae95d1869d2c487b75b8205b567e7d9cf08d10ac1b0c083661003aef4df3762f81382805d2e950c02
7
+ data.tar.gz: fa98f14295c821d0d07321adc42080163fc774684a0f8e87611a1921b4a22cbd20d68e3938177840b12f2b96e30d377addd379841161657d704343602de8fcb4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 1.4.0
4
+
5
+ - Move all top-level constants and functions to Fog::AzureRM !30
6
+
3
7
  ## 1.3.0
4
8
 
5
9
  - Fix Ruby 3.0 compatibility !27
@@ -1 +1,5 @@
1
- LOCATION = 'eastus'.freeze
1
+ module Fog
2
+ module AzureRM
3
+ LOCATION = 'eastus'.freeze
4
+ end
5
+ end
@@ -1,72 +1,76 @@
1
- AZURE_RESOURCE = 'https://management.azure.com'.freeze
2
- DEFAULT_ADDRESS_PREFIXES = ['10.2.0.0/16'].freeze
3
- SUBNET = 'Subnet'.freeze
4
- PUBLIC_IP = 'Public-IP-Address'.freeze
5
- NETWORK_SECURITY_GROUP = 'Network-Security-Group'.freeze
6
- STANDARD_STORAGE = 'Standard'.freeze
7
- PREMIUM_STORAGE = 'Premium'.freeze
8
- ALLOWED_STANDARD_REPLICATION = %w[LRS ZRS GRS RAGRS].freeze
9
- API_VERSION = '2016-06-01'.freeze
10
- FAULT_DOMAIN_COUNT = 2
11
- UPDATE_DOMAIN_COUNT = 5
12
- WINDOWS = 'windows'.freeze
13
- VPN = 'Vpn'.freeze
14
- MICROSOFT_PEERING = 'MicrosoftPeering'.freeze
15
- RESOURCE_GROUP_NAME = 4
16
- RESOURCE_PROVIDER_NAMESPACE = 6
17
- RESOURCE_TYPE = 7
18
- RESOURCE_NAME = 8
19
- ENDPOINT_PREFIX = 'Microsoft.Network/trafficManagerProfiles'.freeze
20
- DISK_PREFIX = 'Microsoft.Compute/disks'.freeze
21
- SNAPSHOT_PREFIX = 'Microsoft.Compute/snapshots'.freeze
22
- AZURE_ENDPOINTS = 'azureEndpoints'.freeze
23
- EXTERNAL_ENDPOINTS = 'externalEndpoints'.freeze
24
- NESTED_ENDPOINTS = 'nestedEndpoints'.freeze
25
- GLOBAL = 'global'.freeze
26
- UPLOAD_BLOB_WORKER_THREAD_COUNT = 8
27
- VM_NAME_POSITION = 8
28
- PRIMARY_NIC_INDEX = 0
1
+ module Fog
2
+ module AzureRM
3
+ AZURE_RESOURCE = 'https://management.azure.com'.freeze
4
+ DEFAULT_ADDRESS_PREFIXES = ['10.2.0.0/16'].freeze
5
+ SUBNET = 'Subnet'.freeze
6
+ PUBLIC_IP = 'Public-IP-Address'.freeze
7
+ NETWORK_SECURITY_GROUP = 'Network-Security-Group'.freeze
8
+ STANDARD_STORAGE = 'Standard'.freeze
9
+ PREMIUM_STORAGE = 'Premium'.freeze
10
+ ALLOWED_STANDARD_REPLICATION = %w[LRS ZRS GRS RAGRS].freeze
11
+ API_VERSION = '2016-06-01'.freeze
12
+ FAULT_DOMAIN_COUNT = 2
13
+ UPDATE_DOMAIN_COUNT = 5
14
+ WINDOWS = 'windows'.freeze
15
+ VPN = 'Vpn'.freeze
16
+ MICROSOFT_PEERING = 'MicrosoftPeering'.freeze
17
+ RESOURCE_GROUP_NAME = 4
18
+ RESOURCE_PROVIDER_NAMESPACE = 6
19
+ RESOURCE_TYPE = 7
20
+ RESOURCE_NAME = 8
21
+ ENDPOINT_PREFIX = 'Microsoft.Network/trafficManagerProfiles'.freeze
22
+ DISK_PREFIX = 'Microsoft.Compute/disks'.freeze
23
+ SNAPSHOT_PREFIX = 'Microsoft.Compute/snapshots'.freeze
24
+ AZURE_ENDPOINTS = 'azureEndpoints'.freeze
25
+ EXTERNAL_ENDPOINTS = 'externalEndpoints'.freeze
26
+ NESTED_ENDPOINTS = 'nestedEndpoints'.freeze
27
+ GLOBAL = 'global'.freeze
28
+ UPLOAD_BLOB_WORKER_THREAD_COUNT = 8
29
+ VM_NAME_POSITION = 8
30
+ PRIMARY_NIC_INDEX = 0
29
31
 
30
- ENVIRONMENT_AZURE_CLOUD = 'AzureCloud'.freeze
31
- ENVIRONMENT_AZURE_CHINA_CLOUD = 'AzureChinaCloud'.freeze
32
- ENVIRONMENT_AZURE_US_GOVERNMENT = 'AzureUSGovernment'.freeze
33
- ENVIRONMENT_AZURE_GERMAN_CLOUD = 'AzureGermanCloud'.freeze
32
+ ENVIRONMENT_AZURE_CLOUD = 'AzureCloud'.freeze
33
+ ENVIRONMENT_AZURE_CHINA_CLOUD = 'AzureChinaCloud'.freeze
34
+ ENVIRONMENT_AZURE_US_GOVERNMENT = 'AzureUSGovernment'.freeze
35
+ ENVIRONMENT_AZURE_GERMAN_CLOUD = 'AzureGermanCloud'.freeze
34
36
 
35
- # MsRestAzure::AzureOperationError class Error Codes
36
- ERROR_CODE_RESOURCE_NOT_FOUND = 'ResourceNotFound'.freeze
37
- ERROR_CODE_NOT_FOUND = 'NotFound'.freeze
38
- ERROR_CODE_RESOURCE_GROUP_NOT_FOUND = 'ResourceGroupNotFound'.freeze
39
- ERROR_CODE_PARENT_RESOURCE_NOT_FOUND = 'ParentResourceNotFound'.freeze
37
+ # MsRestAzure::AzureOperationError class Error Codes
38
+ ERROR_CODE_RESOURCE_NOT_FOUND = 'ResourceNotFound'.freeze
39
+ ERROR_CODE_NOT_FOUND = 'NotFound'.freeze
40
+ ERROR_CODE_RESOURCE_GROUP_NOT_FOUND = 'ResourceGroupNotFound'.freeze
41
+ ERROR_CODE_PARENT_RESOURCE_NOT_FOUND = 'ParentResourceNotFound'.freeze
40
42
 
41
- PLATFORM_LINUX = 'linux'.freeze
43
+ PLATFORM_LINUX = 'linux'.freeze
42
44
 
43
- # State of the copy operation
44
- COPY_STATUS =
45
- {
46
- # The copy completed successfully.
47
- SUCCESS: 'success',
48
- # The copy is in progress
49
- PENDING: 'pending'
50
- }.freeze
45
+ # State of the copy operation
46
+ COPY_STATUS =
47
+ {
48
+ # The copy completed successfully.
49
+ SUCCESS: 'success',
50
+ # The copy is in progress
51
+ PENDING: 'pending'
52
+ }.freeze
51
53
 
52
- # https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
53
- # The maximum size for a block blob created via Put Blob is 64 MB. But for better performance, this size should be 32 MB.
54
- # If your blob is larger than 32 MB, you must upload it as a set of blocks.
55
- SINGLE_BLOB_PUT_THRESHOLD = 32 * 1024 * 1024
54
+ # https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx
55
+ # The maximum size for a block blob created via Put Blob is 64 MB. But for better performance, this size should be 32 MB.
56
+ # If your blob is larger than 32 MB, you must upload it as a set of blocks.
57
+ SINGLE_BLOB_PUT_THRESHOLD = 32 * 1024 * 1024
56
58
 
57
- # Block blob: https://msdn.microsoft.com/en-us/library/azure/dd135726.aspx
58
- # Page blob: https://msdn.microsoft.com/en-us/library/azure/ee691975.aspx
59
- # Each block/page can be a different size, up to a maximum of 4 MB
60
- MAXIMUM_CHUNK_SIZE = 4 * 1024 * 1024
59
+ # Block blob: https://msdn.microsoft.com/en-us/library/azure/dd135726.aspx
60
+ # Page blob: https://msdn.microsoft.com/en-us/library/azure/ee691975.aspx
61
+ # Each block/page can be a different size, up to a maximum of 4 MB
62
+ MAXIMUM_CHUNK_SIZE = 4 * 1024 * 1024
61
63
 
62
- # The hash value of 4MB empty content
63
- HASH_OF_4MB_EMPTY_CONTENT = 'b5cfa9d6c8febd618f91ac2843d50a1c'.freeze
64
- REST_CLIENT_API_VERSION = %w[2014-04-01-preview 2016-05-01].freeze
65
- AS_SKU_CLASSIC = 'Classic'.freeze
66
- AS_SKU_ALIGNED = 'Aligned'.freeze
64
+ # The hash value of 4MB empty content
65
+ HASH_OF_4MB_EMPTY_CONTENT = 'b5cfa9d6c8febd618f91ac2843d50a1c'.freeze
66
+ REST_CLIENT_API_VERSION = %w[2014-04-01-preview 2016-05-01].freeze
67
+ AS_SKU_CLASSIC = 'Classic'.freeze
68
+ AS_SKU_ALIGNED = 'Aligned'.freeze
67
69
 
68
- # The tag key and tag value for creating a temporary storage account for generalized image
69
- TEMPORARY_STORAGE_ACCOUNT_TAG_KEY = 'generalized_image'.freeze
70
- TEMPORARY_STORAGE_ACCOUNT_TAG_VALUE = 'delete'.freeze
70
+ # The tag key and tag value for creating a temporary storage account for generalized image
71
+ TEMPORARY_STORAGE_ACCOUNT_TAG_KEY = 'generalized_image'.freeze
72
+ TEMPORARY_STORAGE_ACCOUNT_TAG_VALUE = 'delete'.freeze
71
73
 
72
- HTTP_NOT_FOUND = 404
74
+ HTTP_NOT_FOUND = 404
75
+ end
76
+ end
@@ -3,6 +3,8 @@ module Fog
3
3
  class AzureRM
4
4
  # This class is giving implementation of listing containers.
5
5
  class Directories < Fog::Collection
6
+ include Fog::AzureRM::Utilities::General
7
+
6
8
  model Fog::Storage::AzureRM::Directory
7
9
 
8
10
  # List all directories(containers) in the storage account.
@@ -5,6 +5,8 @@ module Fog
5
5
  class Directory < Fog::Model
6
6
  VALID_ACLS = ['container', 'blob', 'unknown', nil].freeze
7
7
 
8
+ include Fog::AzureRM::Utilities::General
9
+
8
10
  attr_writer :acl
9
11
 
10
12
  identity :key, aliases: %w(Name name)
@@ -6,6 +6,8 @@ module Fog
6
6
  # This class is giving implementation of create/save and
7
7
  # delete/destroy for Blob.
8
8
  class File < Fog::Model
9
+ include Fog::AzureRM::Utilities::General
10
+
9
11
  identity :key, aliases: %w(Name name Key)
10
12
 
11
13
  attr_writer :body
@@ -3,6 +3,8 @@ module Fog
3
3
  class AzureRM
4
4
  # This class is giving implementation of listing blobs.
5
5
  class Files < Fog::Collection
6
+ include Fog::AzureRM::Utilities::General
7
+
6
8
  attribute :directory
7
9
  attribute :delimiter, aliases: 'Delimiter'
8
10
  attribute :marker, aliases: 'Marker'
@@ -56,7 +56,7 @@ module Fog
56
56
 
57
57
  def save_page_blob(container_name, blob_name, body, options)
58
58
  threads_num = options.delete(:worker_thread_num)
59
- threads_num = UPLOAD_BLOB_WORKER_THREAD_COUNT if threads_num.nil? || !threads_num.is_a?(Integer) || threads_num < 1
59
+ threads_num = Fog::AzureRM::UPLOAD_BLOB_WORKER_THREAD_COUNT if threads_num.nil? || !threads_num.is_a?(Integer) || threads_num < 1
60
60
 
61
61
  begin
62
62
  blob_size = Fog::Storage.get_body_size(body)
@@ -74,9 +74,9 @@ module Fog
74
74
  threads_num.times do |id|
75
75
  thread = Thread.new do
76
76
  Fog::Logger.debug "Created upload thread #{id}."
77
- while (chunk = iostream.read(MAXIMUM_CHUNK_SIZE))
77
+ while (chunk = iostream.read(Fog::AzureRM::MAXIMUM_CHUNK_SIZE))
78
78
  Fog::Logger.debug "Upload thread #{id} is uploading #{chunk.id}, start_range: #{chunk.start_range}, size: #{chunk.data.size}."
79
- put_blob_pages(container_name, blob_name, chunk.start_range, chunk.end_range, chunk.data, options) if Digest::MD5.hexdigest(chunk.data) != HASH_OF_4MB_EMPTY_CONTENT
79
+ put_blob_pages(container_name, blob_name, chunk.start_range, chunk.end_range, chunk.data, options) if Digest::MD5.hexdigest(chunk.data) != Fog::AzureRM::HASH_OF_4MB_EMPTY_CONTENT
80
80
  end
81
81
  Fog::Logger.debug "Upload thread #{id} finished."
82
82
  end
@@ -6,7 +6,7 @@ module Fog
6
6
  def wait_blob_copy_operation_to_finish(container_name, blob_name, copy_id, copy_status, timeout = nil)
7
7
  begin
8
8
  start_time = Time.new
9
- while copy_status == COPY_STATUS[:PENDING]
9
+ while copy_status == Fog::AzureRM::COPY_STATUS[:PENDING]
10
10
  blob = get_blob_properties(container_name, blob_name)
11
11
  blob_props = blob.properties
12
12
  if !copy_id.nil? && blob_props[:copy_id] != copy_id
@@ -15,7 +15,7 @@ module Fog
15
15
 
16
16
  copy_status_description = blob_props[:copy_status_description]
17
17
  copy_status = blob_props[:copy_status]
18
- break if copy_status != COPY_STATUS[:PENDING]
18
+ break if copy_status != Fog::AzureRM::COPY_STATUS[:PENDING]
19
19
 
20
20
  elapse_time = Time.new - start_time
21
21
  raise Timeout::Error.new("The copy operation cannot be finished in #{timeout} seconds") if !timeout.nil? && elapse_time >= timeout
@@ -27,7 +27,7 @@ module Fog
27
27
  sleep(interval)
28
28
  end
29
29
 
30
- if copy_status != COPY_STATUS[:SUCCESS]
30
+ if copy_status != Fog::AzureRM::COPY_STATUS[:SUCCESS]
31
31
  raise "Failed to copy to #{container_name}/#{blob_name}: \n\tcopy status: #{copy_status}\n\tcopy description: #{copy_status_description}"
32
32
  end
33
33
  rescue
@@ -79,6 +79,8 @@ module Fog
79
79
 
80
80
  # This class provides the actual implementation for service calls.
81
81
  class Real
82
+ include Fog::AzureRM::Utilities::General
83
+
82
84
  def initialize(options)
83
85
  begin
84
86
  require 'azure/storage/common'
@@ -1,195 +1,204 @@
1
1
  require File.expand_path('../../custom_fog_errors.rb', __FILE__)
2
2
 
3
- # Pick Resource Group name from Azure Resource Id(String)
4
- def get_resource_group_from_id(id)
5
- id.split('/')[4]
6
- end
7
-
8
- # Pick Virtual Network name from Subnet Resource Id(String)
9
- def get_virtual_network_from_id(subnet_id)
10
- subnet_id.split('/')[8]
11
- end
3
+ module Fog
4
+ module AzureRM
5
+ module Utilities
6
+ # General utilities mixin.
7
+ module General # rubocop:disable Metrics/ModuleLength
8
+ # Pick Resource Group name from Azure Resource Id(String)
9
+ def get_resource_group_from_id(id)
10
+ id.split('/')[4]
11
+ end
12
12
 
13
- # Pick Virtual Machine name from Virtual Machine Extension Id(String)
14
- def get_virtual_machine_from_id(vme_id)
15
- vme_id.split('/')[VM_NAME_POSITION]
16
- end
13
+ # Pick Virtual Network name from Subnet Resource Id(String)
14
+ def get_virtual_network_from_id(subnet_id)
15
+ subnet_id.split('/')[8]
16
+ end
17
17
 
18
- # Extract Endpoint type from (String)
19
- def get_end_point_type(endpoint_type)
20
- endpoint_type.split('/')[2]
21
- end
18
+ # Pick Virtual Machine name from Virtual Machine Extension Id(String)
19
+ def get_virtual_machine_from_id(vme_id)
20
+ vme_id.split('/')[VM_NAME_POSITION]
21
+ end
22
22
 
23
- def get_record_set_from_id(id)
24
- id.split('/')[8]
25
- end
23
+ # Extract Endpoint type from (String)
24
+ def get_end_point_type(endpoint_type)
25
+ endpoint_type.split('/')[2]
26
+ end
26
27
 
27
- def get_type_from_recordset_type(type)
28
- type.split('/')[2]
29
- end
28
+ def get_record_set_from_id(id)
29
+ id.split('/')[8]
30
+ end
30
31
 
31
- def get_hash_from_object(object)
32
- hash = {}
33
- object.instance_variables.each { |attr| hash[attr.to_s.delete('@')] = object.instance_variable_get(attr) }
34
- hash
35
- end
32
+ def get_type_from_recordset_type(type)
33
+ type.split('/')[2]
34
+ end
36
35
 
37
- # Extract Traffic Manager Profile Name from Endpoint id(String)
38
- def get_traffic_manager_profile_name_from_endpoint_id(endpoint_id)
39
- endpoint_id.split('/')[8]
40
- end
36
+ def get_hash_from_object(object)
37
+ hash = {}
38
+ object.instance_variables.each { |attr| hash[attr.to_s.delete('@')] = object.instance_variable_get(attr) }
39
+ hash
40
+ end
41
41
 
42
- # Pick Express Route Circuit name from Id(String)
43
- def get_circuit_name_from_id(circuit_id)
44
- circuit_id.split('/')[8]
45
- end
42
+ # Extract Traffic Manager Profile Name from Endpoint id(String)
43
+ def get_traffic_manager_profile_name_from_endpoint_id(endpoint_id)
44
+ endpoint_id.split('/')[8]
45
+ end
46
46
 
47
- def get_record_type(type)
48
- type.split('/').last
49
- end
47
+ # Pick Express Route Circuit name from Id(String)
48
+ def get_circuit_name_from_id(circuit_id)
49
+ circuit_id.split('/')[8]
50
+ end
50
51
 
51
- def raise_azure_exception(exception, msg)
52
- raise Fog::AzureRM::CustomAzureCoreHttpError.new(exception) if exception.is_a?(Azure::Core::Http::HTTPError)
53
- raise exception unless exception.is_a?(MsRestAzure::AzureOperationError)
52
+ def get_record_type(type)
53
+ type.split('/').last
54
+ end
54
55
 
55
- azure_operation_error = Fog::AzureRM::CustomAzureOperationError.new(msg, exception)
56
- azure_operation_error.print_subscription_limits_information if !azure_operation_error.request.nil? && !azure_operation_error.response.nil?
57
- raise azure_operation_error
58
- end
56
+ def raise_azure_exception(exception, msg)
57
+ raise Fog::AzureRM::CustomAzureCoreHttpError.new(exception) if exception.is_a?(Azure::Core::Http::HTTPError)
58
+ raise exception unless exception.is_a?(MsRestAzure::AzureOperationError)
59
59
 
60
- # Make sure if input_params(Hash) contains all keys present in required_params(Array)
61
- def validate_params(required_params, input_params)
62
- missing_params = required_params.select { |param| param unless input_params.key?(param) }
63
- raise(ArgumentError, "Missing Parameters: #{missing_params.join(', ')} required for this operation") if missing_params.any?
64
- end
60
+ azure_operation_error = Fog::AzureRM::CustomAzureOperationError.new(msg, exception)
61
+ azure_operation_error.print_subscription_limits_information if !azure_operation_error.request.nil? && !azure_operation_error.response.nil?
62
+ raise azure_operation_error
63
+ end
65
64
 
66
- def get_resource_from_resource_id(resource_id, position)
67
- data = resource_id.split('/') unless resource_id.nil?
65
+ # Make sure if input_params(Hash) contains all keys present in required_params(Array)
66
+ def validate_params(required_params, input_params)
67
+ missing_params = required_params.select { |param| param unless input_params.key?(param) }
68
+ raise(ArgumentError, "Missing Parameters: #{missing_params.join(', ')} required for this operation") if missing_params.any?
69
+ end
68
70
 
69
- raise 'Invalid Resource ID' if data.count < 9 && data.count != 5
71
+ def get_resource_from_resource_id(resource_id, position)
72
+ data = resource_id.split('/') unless resource_id.nil?
70
73
 
71
- data[position]
72
- end
74
+ raise 'Invalid Resource ID' if data.count < 9 && data.count != 5
73
75
 
74
- def random_string(length)
75
- (0...length).map { ('a'..'z').to_a[rand(26)] }.join
76
- end
76
+ data[position]
77
+ end
77
78
 
78
- def active_directory_service_settings(environment = ENVIRONMENT_AZURE_CLOUD)
79
- case environment
80
- when ENVIRONMENT_AZURE_CHINA_CLOUD
81
- MsRestAzure::ActiveDirectoryServiceSettings.get_azure_china_settings
82
- when ENVIRONMENT_AZURE_US_GOVERNMENT
83
- MsRestAzure::ActiveDirectoryServiceSettings.get_azure_us_government_settings
84
- when ENVIRONMENT_AZURE_GERMAN_CLOUD
85
- MsRestAzure::ActiveDirectoryServiceSettings.get_azure_german_settings
86
- else
87
- MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings
88
- end
89
- end
79
+ def random_string(length)
80
+ (0...length).map { ('a'..'z').to_a[rand(26)] }.join
81
+ end
90
82
 
91
- def resource_manager_endpoint_url(environment = ENVIRONMENT_AZURE_CLOUD)
92
- case environment
93
- when ENVIRONMENT_AZURE_CHINA_CLOUD
94
- MsRestAzure::AzureEnvironments::ChinaCloud.resource_manager_endpoint_url
95
- when ENVIRONMENT_AZURE_US_GOVERNMENT
96
- MsRestAzure::AzureEnvironments::USGovernment.resource_manager_endpoint_url
97
- when ENVIRONMENT_AZURE_GERMAN_CLOUD
98
- MsRestAzure::AzureEnvironments::GermanCloud.resource_manager_endpoint_url
99
- else
100
- MsRestAzure::AzureEnvironments::AzureCloud.resource_manager_endpoint_url
101
- end
102
- end
83
+ def active_directory_service_settings(environment = ENVIRONMENT_AZURE_CLOUD)
84
+ case environment
85
+ when ENVIRONMENT_AZURE_CHINA_CLOUD
86
+ MsRestAzure::ActiveDirectoryServiceSettings.get_azure_china_settings
87
+ when ENVIRONMENT_AZURE_US_GOVERNMENT
88
+ MsRestAzure::ActiveDirectoryServiceSettings.get_azure_us_government_settings
89
+ when ENVIRONMENT_AZURE_GERMAN_CLOUD
90
+ MsRestAzure::ActiveDirectoryServiceSettings.get_azure_german_settings
91
+ else
92
+ MsRestAzure::ActiveDirectoryServiceSettings.get_azure_settings
93
+ end
94
+ end
103
95
 
104
- # storage_endpoint_suffix is nil in ms_rest_azure 0.6.2
105
- # Reference the issue: https://github.com/Azure/azure-sdk-for-ruby/issues/603
106
- def storage_endpoint_suffix(environment = ENVIRONMENT_AZURE_CLOUD)
107
- case environment
108
- when ENVIRONMENT_AZURE_CHINA_CLOUD
109
- # MsRestAzure::AzureEnvironments::AzureChina.storage_endpoint_suffix
110
- '.core.chinacloudapi.cn'
111
- when ENVIRONMENT_AZURE_US_GOVERNMENT
112
- # MsRestAzure::AzureEnvironments::AzureUSGovernment.storage_endpoint_suffix
113
- '.core.usgovcloudapi.net'
114
- when ENVIRONMENT_AZURE_GERMAN_CLOUD
115
- # MsRestAzure::AzureEnvironments::AzureGermanCloud.storage_endpoint_suffix
116
- '.core.cloudapi.de'
117
- else
118
- # MsRestAzure::AzureEnvironments::Azure.storage_endpoint_suffix
119
- '.core.windows.net'
120
- end
121
- end
96
+ def resource_manager_endpoint_url(environment = ENVIRONMENT_AZURE_CLOUD)
97
+ case environment
98
+ when ENVIRONMENT_AZURE_CHINA_CLOUD
99
+ MsRestAzure::AzureEnvironments::ChinaCloud.resource_manager_endpoint_url
100
+ when ENVIRONMENT_AZURE_US_GOVERNMENT
101
+ MsRestAzure::AzureEnvironments::USGovernment.resource_manager_endpoint_url
102
+ when ENVIRONMENT_AZURE_GERMAN_CLOUD
103
+ MsRestAzure::AzureEnvironments::GermanCloud.resource_manager_endpoint_url
104
+ else
105
+ MsRestAzure::AzureEnvironments::AzureCloud.resource_manager_endpoint_url
106
+ end
107
+ end
122
108
 
123
- def get_blob_endpoint(storage_account_name, enable_https = false, environment = ENVIRONMENT_AZURE_CLOUD)
124
- protocol = enable_https ? 'https' : 'http'
125
- "#{protocol}://#{storage_account_name}.blob#{storage_endpoint_suffix(environment)}"
126
- end
109
+ # storage_endpoint_suffix is nil in ms_rest_azure 0.6.2
110
+ # Reference the issue: https://github.com/Azure/azure-sdk-for-ruby/issues/603
111
+ def storage_endpoint_suffix(environment = ENVIRONMENT_AZURE_CLOUD)
112
+ case environment
113
+ when ENVIRONMENT_AZURE_CHINA_CLOUD
114
+ # MsRestAzure::AzureEnvironments::AzureChina.storage_endpoint_suffix
115
+ '.core.chinacloudapi.cn'
116
+ when ENVIRONMENT_AZURE_US_GOVERNMENT
117
+ # MsRestAzure::AzureEnvironments::AzureUSGovernment.storage_endpoint_suffix
118
+ '.core.usgovcloudapi.net'
119
+ when ENVIRONMENT_AZURE_GERMAN_CLOUD
120
+ # MsRestAzure::AzureEnvironments::AzureGermanCloud.storage_endpoint_suffix
121
+ '.core.cloudapi.de'
122
+ else
123
+ # MsRestAzure::AzureEnvironments::Azure.storage_endpoint_suffix
124
+ '.core.windows.net'
125
+ end
126
+ end
127
127
 
128
- def get_blob_endpoint_with_domain(storage_account_name, enable_https = false, domain = 'blob.core.windows.net')
129
- protocol = enable_https ? 'https' : 'http'
130
- "#{protocol}://#{storage_account_name}.#{domain}"
131
- end
128
+ def get_blob_endpoint(storage_account_name, enable_https = false, environment = ENVIRONMENT_AZURE_CLOUD)
129
+ protocol = enable_https ? 'https' : 'http'
130
+ "#{protocol}://#{storage_account_name}.blob#{storage_endpoint_suffix(environment)}"
131
+ end
132
132
 
133
- def current_time
134
- time = Time.now.to_f.to_s
135
- time.split(/\W+/).join
136
- end
133
+ def get_blob_endpoint_with_domain(storage_account_name, enable_https = false, domain = 'blob.core.windows.net')
134
+ protocol = enable_https ? 'https' : 'http'
135
+ "#{protocol}://#{storage_account_name}.#{domain}"
136
+ end
137
137
 
138
- # Parse storage blob/container to a hash
139
- def parse_storage_object(object)
140
- data = {}
141
- if object.is_a? Hash
142
- object.each do |k, v|
143
- if k == 'properties'
144
- v.each do |j, l|
145
- data[j] = l
146
- end
147
- else
148
- data[k] = v
149
- end
150
- end
151
- else
152
- object.instance_variables.each do |p|
153
- kname = p.to_s.delete('@')
154
- if kname == 'properties'
155
- properties = object.instance_variable_get(p)
156
- properties.each do |k, v|
157
- data[k.to_s] = v
158
- end
159
- else
160
- data[kname] = object.instance_variable_get(p)
161
- end
162
- end
163
- end
138
+ def current_time
139
+ time = Time.now.to_f.to_s
140
+ time.split(/\W+/).join
141
+ end
164
142
 
165
- data['last_modified'] = Time.parse(data['last_modified'])
166
- data['etag'].delete!('"')
167
- data
168
- end
143
+ # Parse storage blob/container to a hash
144
+ def parse_storage_object(object)
145
+ data = {}
146
+ if object.is_a? Hash
147
+ object.each do |k, v|
148
+ if k == 'properties'
149
+ v.each do |j, l|
150
+ data[j] = l
151
+ end
152
+ else
153
+ data[k] = v
154
+ end
155
+ end
156
+ else
157
+ object.instance_variables.each do |p|
158
+ kname = p.to_s.delete('@')
159
+ if kname == 'properties'
160
+ properties = object.instance_variable_get(p)
161
+ properties.each do |k, v|
162
+ data[k.to_s] = v
163
+ end
164
+ else
165
+ data[kname] = object.instance_variable_get(p)
166
+ end
167
+ end
168
+ end
169
+
170
+ data['last_modified'] = Time.parse(data['last_modified'])
171
+ data['etag'].delete!('"')
172
+ data
173
+ end
169
174
 
170
- def resource_not_found?(azure_operation_error)
171
- is_found = false
172
- if azure_operation_error.response.status == HTTP_NOT_FOUND
173
- if azure_operation_error.body['code']
174
- is_found = azure_operation_error.body['code'] == ERROR_CODE_NOT_FOUND
175
- elsif azure_operation_error.body['error']
176
- is_found = azure_operation_error.body['error']['code'] == ERROR_CODE_NOT_FOUND ||
177
- azure_operation_error.body['error']['code'] == ERROR_CODE_RESOURCE_GROUP_NOT_FOUND ||
178
- azure_operation_error.body['error']['code'] == ERROR_CODE_RESOURCE_NOT_FOUND ||
179
- azure_operation_error.body['error']['code'] == ERROR_CODE_PARENT_RESOURCE_NOT_FOUND
180
- end
181
- end
182
- is_found
183
- end
175
+ def resource_not_found?(azure_operation_error)
176
+ is_found = false
177
+ if azure_operation_error.response.status == HTTP_NOT_FOUND
178
+ if azure_operation_error.body['code']
179
+ is_found = azure_operation_error.body['code'] == ERROR_CODE_NOT_FOUND
180
+ elsif azure_operation_error.body['error']
181
+ is_found = azure_operation_error.body['error']['code'] == ERROR_CODE_NOT_FOUND ||
182
+ azure_operation_error.body['error']['code'] == ERROR_CODE_RESOURCE_GROUP_NOT_FOUND ||
183
+ azure_operation_error.body['error']['code'] == ERROR_CODE_RESOURCE_NOT_FOUND ||
184
+ azure_operation_error.body['error']['code'] == ERROR_CODE_PARENT_RESOURCE_NOT_FOUND
185
+ end
186
+ end
187
+ is_found
188
+ end
184
189
 
185
- def get_image_name(id)
186
- id.split('/').last
187
- end
190
+ def get_image_name(id)
191
+ id.split('/').last
192
+ end
188
193
 
189
- def get_subscription_id(id)
190
- id.split('/')[2]
191
- end
194
+ def get_subscription_id(id)
195
+ id.split('/')[2]
196
+ end
192
197
 
193
- def remove_trailing_periods_from_path_segments(path)
194
- path.split('/').map { |segment| segment.gsub(/\.*$/, '') }.join('/')
198
+ def remove_trailing_periods_from_path_segments(path)
199
+ path.split('/').map { |segment| segment.gsub(/\.*$/, '') }.join('/')
200
+ end
201
+ end
202
+ end
203
+ end
195
204
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module AzureRM
3
- VERSION = '1.3.0'.freeze
3
+ VERSION = '1.4.0'.freeze
4
4
  end
5
5
  end
@@ -43,13 +43,13 @@ module ApiStub
43
43
  }
44
44
  end
45
45
 
46
- def self.blob_https_url(environment = ENVIRONMENT_AZURE_CLOUD)
46
+ def self.blob_https_url(environment = Fog::AzureRM::ENVIRONMENT_AZURE_CLOUD)
47
47
  case environment
48
- when ENVIRONMENT_AZURE_CHINA_CLOUD
48
+ when Fog::AzureRM::ENVIRONMENT_AZURE_CHINA_CLOUD
49
49
  'https://sa.blob.core.chinacloudapi.cn/test_container/test_blob'
50
- when ENVIRONMENT_AZURE_US_GOVERNMENT
50
+ when Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT
51
51
  'https://sa.blob.core.usgovcloudapi.net/test_container/test_blob'
52
- when ENVIRONMENT_AZURE_GERMAN_CLOUD
52
+ when Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD
53
53
  'https://sa.blob.core.cloudapi.de/test_container/test_blob'
54
54
  else
55
55
  'https://sa.blob.core.windows.net/test_container/test_blob'
@@ -28,10 +28,10 @@ class TestGetBlobUrl < Minitest::Test
28
28
  end
29
29
 
30
30
  def test_get_blob_url_for_china_success
31
- china_storage_account_credentials = storage_account_credentials.merge(environment: ENVIRONMENT_AZURE_CHINA_CLOUD)
31
+ china_storage_account_credentials = storage_account_credentials.merge(environment: Fog::AzureRM::ENVIRONMENT_AZURE_CHINA_CLOUD)
32
32
  service = Fog::Storage::AzureRM.new(china_storage_account_credentials)
33
33
  blob_client = service.instance_variable_get(:@blob_client)
34
- url = ApiStub::Requests::Storage::File.blob_https_url(ENVIRONMENT_AZURE_CHINA_CLOUD)
34
+ url = ApiStub::Requests::Storage::File.blob_https_url(Fog::AzureRM::ENVIRONMENT_AZURE_CHINA_CLOUD)
35
35
 
36
36
  blob_client.stub :generate_uri, url do
37
37
  assert_equal url, service.get_blob_url('test_container', 'test_blob')
@@ -42,10 +42,10 @@ class TestGetBlobUrl < Minitest::Test
42
42
  end
43
43
 
44
44
  def test_get_blob_url_for_us_success
45
- us_storage_account_credentials = storage_account_credentials.merge(environment: ENVIRONMENT_AZURE_US_GOVERNMENT)
45
+ us_storage_account_credentials = storage_account_credentials.merge(environment: Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT)
46
46
  service = Fog::Storage::AzureRM.new(us_storage_account_credentials)
47
47
  blob_client = service.instance_variable_get(:@blob_client)
48
- url = ApiStub::Requests::Storage::File.blob_https_url(ENVIRONMENT_AZURE_US_GOVERNMENT)
48
+ url = ApiStub::Requests::Storage::File.blob_https_url(Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT)
49
49
 
50
50
  blob_client.stub :generate_uri, url do
51
51
  assert_equal url, service.get_blob_url('test_container', 'test_blob')
@@ -56,10 +56,10 @@ class TestGetBlobUrl < Minitest::Test
56
56
  end
57
57
 
58
58
  def test_get_blob_url_for_german_success
59
- german_storage_account_credentials = storage_account_credentials.merge(environment: ENVIRONMENT_AZURE_GERMAN_CLOUD)
59
+ german_storage_account_credentials = storage_account_credentials.merge(environment: Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD)
60
60
  service = Fog::Storage::AzureRM.new(german_storage_account_credentials)
61
61
  blob_client = service.instance_variable_get(:@blob_client)
62
- url = ApiStub::Requests::Storage::File.blob_https_url(ENVIRONMENT_AZURE_GERMAN_CLOUD)
62
+ url = ApiStub::Requests::Storage::File.blob_https_url(Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD)
63
63
 
64
64
  blob_client.stub :generate_uri, url do
65
65
  assert_equal url, service.get_blob_url('test_container', 'test_blob')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-fog-azure-rm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaffan Chaudhry
@@ -15,10 +15,10 @@ authors:
15
15
  - Azeem Sajid
16
16
  - Maham Nazir
17
17
  - Abbas Sheikh
18
- autorequire:
18
+ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
- date: 2022-06-02 00:00:00.000000000 Z
21
+ date: 2022-11-07 00:00:00.000000000 Z
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
24
  name: codeclimate-test-reporter
@@ -176,7 +176,7 @@ dependencies:
176
176
  version: 0.12.0
177
177
  description: This is a stripped-down fork of fog-azure-rm that enables Azure Blob
178
178
  Storage to be used with CarrierWave and Fog.
179
- email:
179
+ email:
180
180
  executables: []
181
181
  extensions: []
182
182
  extra_rdoc_files:
@@ -338,8 +338,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
338
338
  - !ruby/object:Gem::Version
339
339
  version: '0'
340
340
  requirements: []
341
- rubygems_version: 3.1.6
342
- signing_key:
341
+ rubygems_version: 3.2.22
342
+ signing_key:
343
343
  specification_version: 4
344
344
  summary: Module for the 'fog' gem to support Azure Blob Storage with CarrierWave and
345
345
  Fog.