gitlab-fog-azure-rm-1.9.1/0000755000004100000410000000000014615741124015332 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/rake-script.sh0000644000004100000410000000031414615741124020110 0ustar www-datawww-data#!/bin/bash rake cc_coverage R=$? export CODECLIMATE_REPO_TOKEN="b1401494baa004d90402414cb33a7fc6420fd3693e60c677a120ddefd7d84cfd" codeclimate-test-reporter if [ $R == 1 ]; then exit 1 else exit 0 fi gitlab-fog-azure-rm-1.9.1/rakefile0000644000004100000410000000271214615741124017041 0ustar www-datawww-datarequire 'rake/testtask' require 'bundler/gem_tasks' task default: :cc_coverage task :test do ENV['COVERAGE'] = nil ENV['CODECLIMATE_REPO_TOKEN'] = nil Dir.glob('test/test_*.rb').each { |file| require File.expand_path file, __dir__ } Dir.glob('test/models/**/test_*.rb').each { |file| require File.expand_path file, __dir__ } Dir.glob('test/requests/**/test_*.rb').each { |file| require File.expand_path file, __dir__ } end task :integration do Dir.glob('test/integration/*.rb').each { |file| require File.expand_path file, __dir__ } end desc 'Generates a coverage report for minitest-cases using simple-cov' task :coverage do ENV['CODECLIMATE_REPO_TOKEN'] = nil ENV['COVERAGE'] = 'true' Dir.glob('test/test_*.rb').each { |file| require File.expand_path file, __dir__ } Dir.glob('test/models/**/test_*.rb').each { |file| require File.expand_path file, __dir__ } Dir.glob('test/requests/**/test_*.rb').each { |file| require File.expand_path file, __dir__ } end desc 'Generates a coverage report for minitest-cases using code-climate' task :cc_coverage do ENV['COVERAGE'] = nil ENV['CODECLIMATE_REPO_TOKEN'] = 'b1401494baa004d90402414cb33a7fc6420fd3693e60c677a120ddefd7d84cfd' Dir.glob('test/test_*.rb').each { |file| require File.expand_path file, __dir__ } Dir.glob('test/models/**/test_*.rb').each { |file| require File.expand_path file, __dir__ } Dir.glob('test/requests/**/test_*.rb').each { |file| require File.expand_path file, __dir__ } end gitlab-fog-azure-rm-1.9.1/.gitlab-ci.yml0000644000004100000410000000116114615741124017765 0ustar www-datawww-datainclude: - component: gitlab.com/gitlab-org/components/gem-release/gem-release@~latest default: image: "ruby:${RUBY_VERSION}" cache: paths: - vendor/ruby before_script: - ruby -v - bundle install -j $(nproc) --path vendor test: script: - bundle exec rake test parallel: matrix: - RUBY_VERSION: [ "2.7", "3.0", "3.1", "3.2" ] rubocop: script: - bundle exec rubocop variables: RUBY_VERSION: "2.7" integration: services: - alias: azurite name: mcr.microsoft.com/azure-storage/azurite script: - bundle exec rake integration variables: RUBY_VERSION: "3.2" gitlab-fog-azure-rm-1.9.1/.gitignore0000644000004100000410000000007014615741124017317 0ustar www-datawww-data.idea Gemfile.lock .arcconfig coverage */.DS_Store *.gemgitlab-fog-azure-rm-1.9.1/CONTRIBUTING.md0000644000004100000410000000322414615741124017564 0ustar www-datawww-data## Getting Involved New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another. For structure information of fog click [here](https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/docs/structure.md) ### Coding * Pick a task: * Offer feedback on open [pull requests](https://github.com/fog/fog-azure-rm/pulls). * Review open [issues](https://github.com/fog/fog-azure-rm/issues) for things to help on. * [Create an issue](https://github.com/fog/fog-azure-rm/issues/new) to start a discussion on additions or features. * Fork the project, add your changes and tests to cover them in a topic branch. * [Fork](https://github.com/fog/fog-azure-rm/fork) * Create your feature branch (`git checkout -b my-new-feature`) * Commit your changes (`git commit -am 'Add some feature'`) * Push to the branch (`git push origin my-new-feature`) * Create a new pull request * Commit your changes and rebase against `fog/fog-azure-rm` to ensure everything is up to date. * [Submit a pull request](https://github.com/fog/fog-azure-rm/compare/). ### Non-Coding * Offer feedback on open [issues](https://github.com/fog/fog-azure-rm/issues). * Organize or volunteer at events. * Write and help edit [documentation](https://github.com/fog/fog-azure-rm/tree/master/lib/fog/azurerm/docs). ## Testing You can run `Minitest` tests by running this command in the root directory. ```shell $ rake test ``` ## Code Coverage We are using Simplecov Gem for code coverage. You can see the report of Code Coverage by running this command in the root directory. ```shell $ rake coverage ``` gitlab-fog-azure-rm-1.9.1/.codeclimate.yml0000644000004100000410000000037614615741124020412 0ustar www-datawww-dataengines: rubocop: enabled: true duplication: enabled: true config: languages: - ruby checks: Similar code: enabled: false Identical code: enabled: false ratings: paths: - lib/** - test/** gitlab-fog-azure-rm-1.9.1/lib/0000755000004100000410000000000014615741124016100 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/lib/fog/0000755000004100000410000000000014615741124016653 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/lib/fog/azurerm.rb0000644000004100000410000000112014615741124020657 0ustar www-datawww-datarequire 'azure/core/http/http_error' require 'erb' require 'fog/azurerm/config' require 'fog/azurerm/constants' require 'fog/azurerm/utilities/general' require 'fog/azurerm/version' require 'fog/core' require 'fog/json' require 'fog/azurerm/models/storage/sku_name' require 'fog/azurerm/models/storage/sku_tier' require 'fog/azurerm/models/storage/kind' module Fog # Main AzureRM fog Provider Module module AzureRM extend Fog::Provider # Autoload Module for Storage autoload :Storage, File.expand_path('azurerm/storage', __dir__) service(:storage, 'Storage') end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/0000755000004100000410000000000014615741124020340 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/async_response.rb0000644000004100000410000000215214615741124023720 0ustar www-datawww-datamodule Fog module AzureRM # class for Async Response class AsyncResponse def initialize(model, promise, delete_extra_resource = false, post_method_execute = nil) @fog_model = model @promise = promise @delete_extra_resource = delete_extra_resource @post_method_execute = post_method_execute end def value response = @promise.value.body @fog_model.merge_attributes(@fog_model.class.parse(response)) @fog_model.delete_extra_resources if @delete_extra_resource # This code block will execute the method mentioned in post_method_execute after getting the response unless @post_method_execute.nil? @fog_model.public_send(@post_method_execute) if @fog_model.respond_to? @post_method_execute end @fog_model end def state @promise.state end def reason @promise.reason end def pending? @promise.pending? end def fulfilled? @promise.fulfilled? end def rejected? @promise.rejected? end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/storage.rb0000644000004100000410000001407314615741124022336 0ustar www-datawww-datamodule Fog module AzureRM # This class registers models, requests and collections class Storage < Fog::Service # Recognizes when creating data client recognizes :azure_storage_account_name recognizes :azure_storage_access_key recognizes :azure_storage_token_signer recognizes :azure_storage_endpoint recognizes :azure_storage_domain recognizes :environment recognizes :debug request_path 'fog/azurerm/requests/storage' # Azure Storage Container requests request :create_container request :release_container_lease request :acquire_container_lease request :delete_container request :list_containers request :put_container_metadata request :get_container_properties request :get_container_acl request :put_container_acl request :get_container_url request :check_container_exists # Azure Storage Blob requests request :list_blobs request :put_blob_metadata request :put_blob_properties request :get_blob_properties request :copy_blob request :copy_object request :copy_blob_from_uri request :compare_container_blobs request :acquire_blob_lease request :release_blob_lease request :get_blob request :get_blob_url request :get_object request :get_object_url request :get_blob_http_url request :get_blob_https_url request :create_block_blob request :put_blob_block request :put_blob_http_url request :put_blob_https_url request :put_object_url request :delete_blob request :delete_blob_https_url request :delete_object_url request :delete_object request :commit_blob_blocks request :create_page_blob request :put_blob_pages request :wait_blob_copy_operation_to_finish request :save_page_blob model_path 'fog/azurerm/models/storage' model :directory collection :directories model :file collection :files # This class provides the mock implementation for unit tests. class Mock def initialize(_options = {}) begin require 'azure/storage/common' require 'azure/storage/blob' rescue LoadError => e retry if require('rubygems') raise e.message end end end # This class provides the actual implementation for service calls. class Real include Fog::AzureRM::Utilities::General def initialize(options) begin require 'azure/storage/common' require 'azure/storage/blob' require 'securerandom' @debug = ENV['DEBUG'] || options[:debug] require 'azure/core/http/debug_filter' if @debug require 'fog/azurerm/identity_encoding_filter' rescue LoadError => e retry if require('rubygems') raise e.message end return unless @azure_storage_account_name != options[:azure_storage_account_name] || @azure_storage_access_key != options[:azure_storage_access_key] || @azure_storage_token_signer != options[:azure_storage_token_signer] @azure_storage_account_name = options[:azure_storage_account_name] @azure_storage_access_key = options[:azure_storage_access_key] @azure_storage_token_signer = options[:azure_storage_token_signer] @azure_storage_endpoint = options[:azure_storage_endpoint] @azure_storage_domain = options[:azure_storage_domain] options[:environment] = 'AzureCloud' if options[:environment].nil? @environment = options[:environment] storage_blob_host = @azure_storage_endpoint || if @azure_storage_domain.nil? || @azure_storage_domain.empty? get_blob_endpoint(@azure_storage_account_name, true, @environment) else get_blob_endpoint_with_domain(@azure_storage_account_name, true, @azure_storage_domain) end azure_client = Azure::Storage::Common::Client.create({ storage_account_name: @azure_storage_account_name, storage_access_key: @azure_storage_access_key, signer: @azure_storage_token_signer }.compact) azure_client.storage_blob_host = storage_blob_host @blob_client = Azure::Storage::Blob::BlobService.new(client: azure_client) @blob_client.with_filter(Fog::AzureRM::IdentityEncodingFilter.new) @blob_client.with_filter(Azure::Storage::Common::Core::Filter::ExponentialRetryPolicyFilter.new) @blob_client.with_filter(Azure::Core::Http::DebugFilter.new) if @debug end private def signature_client(requested_expiry) access_key = @azure_storage_access_key.to_s user_delegation_key = user_delegation_key(requested_expiry) # invalidate cache when the delegation key changes unless @signature_client_delegation_key == user_delegation_key @signature_client_delegation_key = user_delegation_key @signature_client = nil end @signature_client ||= Azure::Storage::Common::Core::Auth::SharedAccessSignature.new( @azure_storage_account_name, access_key, user_delegation_key ) end def user_delegation_key(requested_expiry) return nil unless @azure_storage_token_signer @user_delegation_key_mutex ||= Mutex.new @user_delegation_key_mutex.synchronize do if @user_delegation_key_expiry.nil? || @user_delegation_key_expiry < requested_expiry start = Time.now expiry = start + Azure::Storage::Blob::BlobConstants::MAX_USER_DELEGATION_KEY_SECONDS @user_delegation_key = @blob_client.get_user_delegation_key( start, expiry ) @user_delegation_key_expiry = expiry end end @user_delegation_key end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/0000755000004100000410000000000014615741124022213 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/0000755000004100000410000000000014615741124023657 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_container_properties.rb0000644000004100000410000000241114615741124031277 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def get_container_properties(name, options = {}) options[:request_id] = SecureRandom.uuid msg = "Getting container properties: #{name}, options: #{options}." Fog::Logger.debug msg begin container = @blob_client.get_container_properties(name, options) rescue Azure::Core::Http::HTTPError => ex raise 'NotFound' if ex.message.include?('(404)') raise_azure_exception(ex, msg) end Fog::Logger.debug "Getting properties of container #{name} successfully." container end end # This class provides the mock implementation for unit tests. class Mock def get_container_properties(*) { 'name' => 'test_container', 'public_access_level' => nil, 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available' } } end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb0000644000004100000410000000441614615741124033327 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def wait_blob_copy_operation_to_finish(container_name, blob_name, copy_id, copy_status, timeout = nil) begin start_time = Time.new while copy_status == Fog::AzureRM::COPY_STATUS[:PENDING] blob = get_blob_properties(container_name, blob_name) blob_props = blob.properties if !copy_id.nil? && blob_props[:copy_id] != copy_id raise "The progress of copying to #{container_name}/#{blob_name} was interrupted by other copy operations." end copy_status_description = blob_props[:copy_status_description] copy_status = blob_props[:copy_status] break if copy_status != Fog::AzureRM::COPY_STATUS[:PENDING] elapse_time = Time.new - start_time raise Timeout::Error.new("The copy operation cannot be finished in #{timeout} seconds") if !timeout.nil? && elapse_time >= timeout copied_bytes, total_bytes = blob_props[:copy_progress].split('/').map(&:to_i) interval = copied_bytes.zero? ? 5 : (total_bytes - copied_bytes).to_f / copied_bytes * elapse_time interval = 30 if interval > 30 interval = 1 if interval < 1 sleep(interval) end if copy_status != Fog::AzureRM::COPY_STATUS[:SUCCESS] raise "Failed to copy to #{container_name}/#{blob_name}: \n\tcopy status: #{copy_status}\n\tcopy description: #{copy_status_description}" end rescue # Abort the copy & reraise begin delete_blob(container_name, blob_name) rescue => ex Fog::Logger.debug "Cannot delete the blob: #{container_name}/#{blob_name} after the copy operation failed. #{ex.inspect}" end raise end Fog::Logger.debug "Successfully copied the blob: #{container_name}/#{blob_name}." true end end # This class provides the mock implementation for unit tests. class Mock def wait_blob_copy_operation_to_finish(*) true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/put_blob_pages.rb0000644000004100000410000000172214615741124027173 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def put_blob_pages(container_name, blob_name, start_range, end_range, data, options = {}) options[:request_id] = SecureRandom.uuid msg = "put_blob_pages [#{start_range}-#{end_range}] / #{blob_name} to the container #{container_name}. options: #{options}" Fog::Logger.debug msg begin @blob_client.put_blob_pages(container_name, blob_name, start_range, end_range, data, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "[#{start_range}-#{end_range}] / #{blob_name} is uploaded successfully." true end end # This class provides the mock implementation. class Mock def put_blob_pages(*) true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_object.rb0000644000004100000410000000076614615741124026322 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real def get_object(...) blob, body = get_blob(...) blob[:body] = body blob end end # This class provides the mock implementation for unit tests. class Mock def get_object(...) blob, body = get_blob(...) blob[:body] = body blob end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/put_blob_http_url.rb0000644000004100000410000000255014615741124027735 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Generate a pre-signed URL for create an object in an Azure blob storage # # @param container_name [String] Name of container containing blob # @param blob_name [String] Name of blob to get expiring url for # @param expires [Time] An expiry time for this url # # @return [String] - https url for blob # # @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob # def put_blob_http_url(container_name, blob_name, expires) relative_path = "#{container_name}/#{blob_name}" params = { service: 'b', resource: 'b', permissions: 'c', expiry: expires.utc.iso8601 } token = signature_client(expires).generate_service_sas_token(relative_path, params) uri = @blob_client.generate_uri(relative_path, {}, { encode: true }) url = "#{uri}?#{token}" url.sub('https:', 'http:') end end # This class provides the mock implementation for unit tests. class Mock def put_blob_http_url(*) 'http://mockaccount.blob.core.windows.net/test_container/test_blob?token' end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/put_blob_properties.rb0000644000004100000410000000177214615741124030275 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real def put_blob_properties(container_name, name, options = {}) options[:request_id] = SecureRandom.uuid msg = "Set Blob #{name} properties #{options} in container #{container_name}." Fog::Logger.debug msg begin @blob_client.set_blob_properties(container_name, name, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Setting properties of blob #{name} successfully." true end end # This class provides the mock implementation for unit tests. class Mock def put_blob_properties(container_name, name, options = {}) Fog::Logger.debug "Set Blob #{name} properties #{options} in a container #{container_name} successfully." true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_container_url.rb0000644000004100000410000000206214615741124027707 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Get a public container url from Azure storage container # # @param container_name [String] Name of container # # @return [String] - url for container # def get_container_url(container_name, options = {}) query = { 'comp' => 'list', 'restype' => 'container' } uri = @blob_client.generate_uri(container_name, query, { encode: true }) if options[:scheme] == 'http' uri.to_s.gsub('https:', 'http:') else uri.to_s end end end # This class provides the mock implementation for unit tests. class Mock def get_container_url(_container_name, options = {}) url = 'https://mockaccount.blob.core.windows.net/test_container?comp=list&restype=container' url.sub!('https:', 'http:') if options[:scheme] == 'http' url end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_blob_http_url.rb0000644000004100000410000000276114615741124027710 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Get an expiring http blob url from Azure blob storage # # @param container_name [String] Name of container containing blob # @param blob_name [String] Name of blob to get expiring url for # @param expires [Time] An expiry time for this url # # @return [String] - http url for blob # # @see https://msdn.microsoft.com/en-us/library/azure/mt584140.aspx # def get_blob_http_url(container_name, blob_name, expires, options = {}) relative_path = "#{container_name}/#{blob_name}" relative_path = remove_trailing_periods_from_path_segments(relative_path) params = { service: 'b', resource: 'b', permissions: 'r', expiry: expires.utc.iso8601, content_disposition: options[:content_disposition] } token = signature_client(expires).generate_service_sas_token(relative_path, params) uri = @blob_client.generate_uri(relative_path, {}, { encode: true }) url = "#{uri}?#{token}" url.sub('https:', 'http:') end end # This class provides the mock implementation for unit tests. class Mock def get_blob_http_url(*) 'http://mockaccount.blob.core.windows.net/test_container/test_blob?token' end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/put_container_acl.rb0000644000004100000410000000163414615741124027701 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def put_container_acl(name, acl, options = {}) options[:request_id] = SecureRandom.uuid msg = "Setting Container #{name} acl #{acl.nil? ? 'nil' : acl}. options: #{options}" Fog::Logger.debug msg begin @blob_client.set_container_acl(name, acl, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Setting acl of container #{name} successfully." true end end # This class provides the mock implementation for unit tests. class Mock def put_container_acl(*) Fog::Logger.debug 'Set Container testcontainer1 acl successfully.' true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_container_acl.rb0000644000004100000410000000165414615741124027652 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def get_container_acl(container_name, options = {}) options[:request_id] = SecureRandom.uuid msg = "Get container ACL: #{container_name}. options: #{options}" Fog::Logger.debug msg begin container, signed_identifiers = @blob_client.get_container_acl(container_name, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Getting ACL of container #{container_name} successfully." [container.public_access_level, signed_identifiers] end end # This class provides the mock implementation for unit tests. class Mock def get_container_acl(*) ['container', {}] end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/acquire_container_lease.rb0000644000004100000410000000155314615741124031054 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def acquire_container_lease(name, options = {}) options[:request_id] = SecureRandom.uuid msg = "Leasing container: #{name} options: #{options}" Fog::Logger.debug msg begin lease_id = @blob_client.acquire_container_lease(name, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Container #{name} leased successfully." lease_id end end # This class provides the mock implementation for unit tests. class Mock def acquire_container_lease(*) { 'leaseId' => 'abc123' } end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/delete_blob_https_url.rb0000644000004100000410000000253714615741124030557 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Get a pre-signed URL to delete an object in Azure blob storage # # @param container_name [String] Name of container containing blob # @param blob_name [String] Name of blob to get expiring url for # @param expires [Time] An expiry time for this url # # @return [String] - https url for blob # # @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-blob # def delete_blob_https_url(container_name, blob_name, expires) relative_path = "#{container_name}/#{blob_name}" params = { service: 'b', resource: 'b', permissions: 'd', expiry: expires.utc.iso8601, protocol: 'https' } token = signature_client(expires).generate_service_sas_token(relative_path, params) uri = @blob_client.generate_uri(relative_path, {}, { encode: true }) "#{uri}?#{token}" end end # This class provides the mock implementation for unit tests. class Mock def delete_blob_https_url(*) 'https://mockaccount.blob.core.windows.net/test_container/test_blob?token' end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/copy_object.rb0000644000004100000410000000112714615741124026505 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. # This is to make this library compatible with CarrierWave. class Real def copy_object(source_container, source_blob, target_container, target_blob, options = {}) copy_blob(target_container, target_blob, source_container, source_blob, options) end end # This class provides the mock implementation for unit tests. class Mock def copy_object(*args) copy_blob(*args) end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/commit_blob_blocks.rb0000644000004100000410000000164414615741124030034 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def commit_blob_blocks(container_name, blob_name, blocks, options = {}) options[:request_id] = SecureRandom.uuid msg = "commit_blob_blocks: Complete uploading #{blob_name} to the container #{container_name}. options: #{options}" Fog::Logger.debug msg begin @blob_client.commit_blob_blocks(container_name, blob_name, blocks, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Block blob #{blob_name} is uploaded successfully." true end end # This class provides the mock implementation for unit tests. class Mock def commit_blob_blocks(*) true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/put_blob_metadata.rb0000644000004100000410000000203714615741124027654 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def put_blob_metadata(container_name, name, metadata, options = {}) options[:request_id] = SecureRandom.uuid msg = "Setting Blob #{name} metadata in a container #{container_name}. options: #{options}" Fog::Logger.debug msg begin @blob_client.set_blob_metadata(container_name, name, metadata, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Setting metadata of blob #{name} successfully." true end end # This class provides the mock implementation for unit tests. class Mock def put_blob_metadata(container_name, name, metadata, _options = {}) Fog::Logger.debug "Set Blob #{name} metadata #{metadata} in a container #{container_name} successfully." true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/create_container.rb0000644000004100000410000000223314615741124027511 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def create_container(name, options = {}) options[:request_id] = SecureRandom.uuid msg = "Creating container: #{name}. options: #{options}" Fog::Logger.debug msg begin container = @blob_client.create_container(name, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Container #{name} created successfully." container end end # This class provides the mock implementation for unit tests. class Mock def create_container(*) { 'name' => 'test_container', 'public_access_level' => nil, 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available' } } end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/release_container_lease.rb0000644000004100000410000000154314615741124031042 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def release_container_lease(name, lease_id, options={}) options[:request_id] = SecureRandom.uuid msg = "Releasing container: #{name} having lease_id #{lease_id} options: #{options}" Fog::Logger.debug msg begin @blob_client.release_container_lease(name, lease_id, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Container #{name} released successfully." true end end # This class provides the mock implementation for unit tests. class Mock def release_container_lease(*) true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/check_container_exists.rb0000644000004100000410000000143714615741124030727 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def check_container_exists(name) msg = "Checking container #{name}." Fog::Logger.debug msg begin get_container_properties(name) Fog::Logger.debug "Container #{name} exists." true rescue Exception => e if e.message.include? 'NotFound' Fog::Logger.debug "The specified container #{name} does not exist." false end end end end # This class provides the mock implementation for unit tests. class Mock def check_container_exists(*) true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/copy_blob.rb0000644000004100000410000000205714615741124026160 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def copy_blob(destination_container, destination_blob, source_container, source_blob, options = {}) options[:request_id] = SecureRandom.uuid msg = "Copying blob: #{source_blob} from container #{source_container} to container #{destination_container} options: #{options}" Fog::Logger.debug msg begin copy_id, copy_status = @blob_client.copy_blob(destination_container, destination_blob, source_container, source_blob, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Copying blob: x-ms-copy-id: #{copy_id}, x-ms-copy-status: #{copy_status}" [copy_id, copy_status] end end # This class provides the mock implementation for unit tests. class Mock def copy_blob(*) %w(abc123 pending) end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_blob_url.rb0000644000004100000410000000155114615741124026645 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Get a public blob url from Azure blob storage def get_blob_url(container_name, blob_name, options = {}) uri = @blob_client.generate_uri("#{container_name}/#{blob_name}", {}, { encode: true }) if options[:scheme] == 'http' uri.to_s.gsub('https:', 'http:') else uri.to_s end end end # This class provides the mock implementation for unit tests. class Mock def get_blob_url(_container_name, _blob_name, options = {}) url = 'https://mockaccount.blob.core.windows.net/test_container/test_blob' url.sub!('https:', 'http:') if options[:scheme] == 'http' url end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/put_container_metadata.rb0000644000004100000410000000165214615741124030722 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def put_container_metadata(name, metadata, options = {}) options[:request_id] = SecureRandom.uuid msg = "Setting Container #{name} metadata. options: #{options}" Fog::Logger.debug msg begin @blob_client.set_container_metadata(name, metadata, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Setting metadata of container #{name} successfully." true end end # This class provides the mock implementation for unit tests. class Mock def put_container_metadata(*) Fog::Logger.debug 'Set Container testcontainer1 metadata successfully.' true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/list_containers.rb0000644000004100000410000000461414615741124027411 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. # https://msdn.microsoft.com/en-us/library/azure/dd179352.aspx class Real def list_containers options = { metadata: true } containers = [] msg = nil begin loop do options[:request_id] = SecureRandom.uuid msg = "Listing containers. options: #{options}" Fog::Logger.debug msg temp = @blob_client.list_containers(options) # Workaround for the issue https://github.com/Azure/azure-storage-ruby/issues/37 raise temp unless temp.instance_of?(Azure::Storage::Common::Service::EnumerationResults) containers += temp unless temp.empty? break if temp.continuation_token.nil? || temp.continuation_token.empty? options[:marker] = temp.continuation_token end rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug 'Listing containers successfully.' containers end end # This class provides the mock implementation for unit tests. class Mock def list_containers [ { 'name' => 'test_container1', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available' } }, { 'name' => 'test_container2', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:01:08 GMT', 'etag' => '0x8D29C92176C8352', 'lease_status' => 'unlocked', 'lease_state' => 'available' } }, { 'name' => 'test_container3', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 01 Sep 2015 05:15:36 GMT', 'etag' => '0x8D2B28C5EB36458', 'lease_status' => 'unlocked', 'lease_state' => 'available' } } ] end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/put_blob_block.rb0000644000004100000410000000162614615741124027171 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def put_blob_block(container_name, blob_name, block_id, data, options = {}) options[:request_id] = SecureRandom.uuid msg = "put_blob_block block_id: #{block_id} / #{blob_name} to the container #{container_name}. options: #{options}" Fog::Logger.debug msg begin @blob_client.put_blob_block(container_name, blob_name, block_id, data, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "block_id #{block_id} is uploaded successfully." true end end # This class provides the mock implementation. class Mock def put_blob_block(*) true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/put_object_url.rb0000644000004100000410000000200314615741124027217 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Generate a pre-signed URL for create an object in an Azure blob storage # This is to make this library compatible with CarrierWave. # # @param container_name [String] Name of container containing blob # @param blob_name [String] Name of blob to get expiring url for # @param expires [Time] An expiry time for this url # # @return [String] - https url for blob # # @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob # def put_object_url(bucket_name, object_name, expire_at, _upload_options) put_blob_https_url(bucket_name, object_name, expire_at) end end # This class provides the mock implementation for unit tests. class Mock def put_object_url(*args) put_blob_https_url(*args) end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_object_url.rb0000644000004100000410000000130414615741124027171 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Get a public blob url from Azure blob storage # This is to make this library compatible with CarrierWave. def get_object_url(container_name, blob_name, expires, options = {}) get_blob_https_url(container_name, blob_name, expires, options) end end # This class provides the mock implementation for unit tests. class Mock def get_object_url(container_name, blob_name, expires, options = {}) get_blob_https_url(container_name, blob_name, expires, options) end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/save_page_blob.rb0000644000004100000410000000746014615741124027143 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real # This class is used to store chunk data for page blob before uploading. class BlobChunk attr_reader :id # For debug attr_reader :start_range attr_reader :data def initialize(id, start_range, data) @id = id @start_range = start_range @data = data end def end_range @start_range + @data.size - 1 end end # This class is a stream to read chunk data. class BlobFileStream def initialize(body) if body.respond_to?(:read) if body.respond_to?(:rewind) begin body.rewind rescue => ex Fog::Logger.debug "save_page_blob - body responds to :rewind but throws an exception when calling :rewind: #{ex.inspect}" end end @stream = body else @stream = StringIO.new(body) end @mutex = Mutex.new @count = 0 end def read(size) data = nil id = 0 start_range = 0 @mutex.synchronize do start_range = @stream.pos data = @stream.read(size) return nil if data.nil? @count += 1 id = @count end BlobChunk.new(id, start_range, data) end end def save_page_blob(container_name, blob_name, body, options) threads_num = options.delete(:worker_thread_num) threads_num = Fog::AzureRM::UPLOAD_BLOB_WORKER_THREAD_COUNT if threads_num.nil? || !threads_num.is_a?(Integer) || threads_num < 1 begin blob_size = Fog::Storage.get_body_size(body) raise "The page blob size must be aligned to a 512-byte boundary. But the file size is #{blob_size}." if (blob_size % 512).nonzero? # Initiate the upload Fog::Logger.debug "Creating the page blob #{container_name}/#{blob_name}. options: #{options}" create_page_blob(container_name, blob_name, blob_size, options) options.delete(:content_md5) # Uploading content iostream = BlobFileStream.new(body) threads = [] threads_num.times do |id| thread = Thread.new do Fog::Logger.debug "Created upload thread #{id}." while (chunk = iostream.read(Fog::AzureRM::MAXIMUM_CHUNK_SIZE)) Fog::Logger.debug "Upload thread #{id} is uploading #{chunk.id}, start_range: #{chunk.start_range}, size: #{chunk.data.size}." 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 end Fog::Logger.debug "Upload thread #{id} finished." end thread.abort_on_exception = true threads << thread end threads.each(&:join) rescue # Abort the upload & reraise begin delete_blob(container_name, blob_name) rescue => ex Fog::Logger.debug "Cannot delete the blob: #{container_name}/#{blob_name} after save_page_blob failed. #{ex.inspect}" end raise end Fog::Logger.debug "Successfully save the page blob: #{container_name}/#{blob_name}." true end end # This class provides the mock implementation for unit tests. class Mock def save_page_blob(*) true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_blob.rb0000644000004100000410000001471614615741124025772 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real BLOCK_SIZE = 32 * 1024 * 1024 # 32 MB def get_blob_with_block_given(container_name, blob_name, options, &block) options[:request_id] = SecureRandom.uuid msg = "get_blob_with_block_given: blob #{blob_name} in the container #{container_name}. options: #{options}" Fog::Logger.debug msg begin blob = @blob_client.get_blob_properties(container_name, blob_name, options) rescue Azure::Core::Http::HTTPError => ex raise 'NotFound' if ex.message.include?('(404)') raise_azure_exception(ex, msg) end content_length = blob.properties[:content_length] if content_length.zero? block.call('', 0, 0) return [blob, ''] end start_range = 0 end_range = content_length - 1 start_range = options[:start_range] if options[:start_range] end_range = options[:end_range] if options[:end_range] raise ArgumentError.new(':end_range MUST be greater than :start_range') if start_range > end_range if start_range == end_range block.call('', 0, 0) return [blob, ''] end buffer_size = BLOCK_SIZE buffer_size = options[:block_size] if options[:block_size] buffer_start_range = start_range total_bytes = end_range - start_range + 1 params = options.dup while buffer_start_range < end_range buffer_end_range = [end_range, buffer_start_range + buffer_size - 1].min params[:start_range] = buffer_start_range params[:end_range] = buffer_end_range params[:request_id] = SecureRandom.uuid begin msg = "get_blob_with_block_given: blob #{blob_name} in the container #{container_name}. options: #{params}" Fog::Logger.debug msg _, content = @blob_client.get_blob(container_name, blob_name, params) rescue Azure::Core::Http::HTTPError => ex raise 'NotFound' if ex.message.include?('(404)') raise_azure_exception(ex, msg) end block.call(content, end_range - buffer_end_range, total_bytes) buffer_start_range += buffer_size end # No need to return content when block is given. [blob, ''] end def get_blob(container_name, blob_name, options = {}, &block) if block_given? get_blob_with_block_given(container_name, blob_name, options, &block) else options[:request_id] = SecureRandom.uuid msg = "get_blob blob #{blob_name} in the container #{container_name}. options: #{options}" Fog::Logger.debug msg begin blob, content = @blob_client.get_blob(container_name, blob_name, options) Fog::Logger.debug "Get blob #{blob_name} successfully." [blob, content] rescue Azure::Core::Http::HTTPError => ex raise 'NotFound' if ex.message.include?('(404)') raise_azure_exception(ex, msg) end end end end # This class provides the mock implementation for unit tests. class Mock def get_blob(_container_name, _blob_name, _options = {}, &block) Fog::Logger.debug 'get_blob successfully.' unless block_given? return [ { 'name' => 'test_blob', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 09:30:31 GMT', 'etag' => '0x8D3A3EDD7C2B777', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'lease_duration' => nil, 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/testblob/4m?snapshot=2016-02-04T08%3A35%3A50.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, 'content' ] end data = StringIO.new('content') remaining = total_bytes = data.length while remaining > 0 chunk = data.read([remaining, 2].min) block.call(chunk, remaining, total_bytes) remaining -= 2 end [ { 'name' => 'test_blob', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 09:30:31 GMT', 'etag' => '0x8D3A3EDD7C2B777', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'lease_duration' => nil, 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/testblob/4m?snapshot=2016-02-04T08%3A35%3A50.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, '' ] end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_blob_https_url.rb0000644000004100000410000000303414615741124030065 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Get an expiring https blob url from Azure blob storage # # @param container_name [String] Name of container containing blob # @param blob_name [String] Name of blob to get expiring url for # @param expires [Time] An expiry time for this url # # @return [String] - https url for blob # # @see https://msdn.microsoft.com/en-us/library/azure/mt584140.aspx # def get_blob_https_url(container_name, blob_name, expires, options = {}) relative_path = "#{container_name}/#{blob_name}" relative_path = remove_trailing_periods_from_path_segments(relative_path) params = { service: 'b', resource: 'b', permissions: 'r', expiry: expires.utc.iso8601, protocol: 'https', content_disposition: options[:content_disposition], content_type: options[:content_type] } token = signature_client(expires).generate_service_sas_token(relative_path, params) uri = @blob_client.generate_uri(relative_path, {}, { encode: true }) "#{uri}?#{token}" end end # This class provides the mock implementation for unit tests. class Mock def get_blob_https_url(*) 'https://mockaccount.blob.core.windows.net/test_container/test_blob?token' end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/create_block_blob.rb0000644000004100000410000000615514615741124027626 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def create_block_blob(container_name, blob_name, body, options = {}) options[:request_id] = SecureRandom.uuid msg = "create_block_blob #{blob_name} to the container #{container_name}. options: #{options}" Fog::Logger.debug msg @blob_client.create_block_blob(container_name, blob_name, body, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end end # This class provides the mock implementation for unit tests. class Mock def create_block_blob(_container_name, _blob_name, body, _options = {}) Fog::Logger.debug 'Blob created successfully.' if body.nil? { 'name' => 'test_blob', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => nil, 'lease_state' => nil, 'content_length' => 0, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => nil, 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'BlockBlob', 'copy_id' => nil, 'copy_status' => nil, 'copy_source' => nil, 'copy_progress' => nil, 'copy_completion_time' => nil, 'copy_status_description' => nil, 'accept_ranges' => 0 } } else { 'name' => 'test_blob', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'BlockBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3256874Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } } end end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/put_blob_https_url.rb0000644000004100000410000000253714615741124030125 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Generate a pre-signed URL for create an object in an Azure blob storage # # @param container_name [String] Name of container containing blob # @param blob_name [String] Name of blob to get expiring url for # @param expires [Time] An expiry time for this url # # @return [String] - https url for blob # # @see https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob # def put_blob_https_url(container_name, blob_name, expires) relative_path = "#{container_name}/#{blob_name}" params = { service: 'b', resource: 'b', permissions: 'c', expiry: expires.utc.iso8601, protocol: 'https' } token = signature_client(expires).generate_service_sas_token(relative_path, params) uri = @blob_client.generate_uri(relative_path, {}, { encode: true }) "#{uri}?#{token}" end end # This class provides the mock implementation for unit tests. class Mock def put_blob_https_url(*) 'https://mockaccount.blob.core.windows.net/test_container/test_blob?token' end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/compare_container_blobs.rb0000644000004100000410000001442514615741124031063 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def compare_container_blobs(container1, container2) msg = "Comparing blobs from container #{container1} to container #{container2}" Fog::Logger.debug msg begin identical_blobs = get_identical_blobs_from_containers(container1, container2) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end identical_blobs end private def get_identical_blobs_from_containers(container1, container2) container1_blobs = list_blobs(container1) container2_blobs = list_blobs(container2) identical_blobs = [] container1_blobs[:blobs].each do |container1_blob| container2_blobs[:blobs].each do |container2_blob| if container1_blob.name == container2_blob.name && container1_blob.properties[:content_md5] == container2_blob.properties[:content_md5] identical_blobs.push(container1_blob) end end end identical_blobs end end # This class provides the mock implementation for unit tests. class Mock def compare_container_blobs(*) [ { 'name' => 'test_blob1', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3256874Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob2', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '0x8D29C92173526C8', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob3', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '0x8D29C92173526C8', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob4', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '0x8D29C92173526C8', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } } ] end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/delete_blob.rb0000644000004100000410000000171214615741124026445 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def delete_blob(container_name, blob_name, options = {}) options[:request_id] = SecureRandom.uuid msg = "Deleting blob: #{blob_name} in container #{container_name}. options: #{options}" Fog::Logger.debug msg begin @blob_client.delete_blob(container_name, blob_name, options) rescue Azure::Core::Http::HTTPError => ex return true if ex.message.include?('(404)') raise_azure_exception(ex, msg) end Fog::Logger.debug "Blob #{blob_name} deleted successfully." true end end # This class provides the mock implementation for unit tests. class Mock def delete_blob(*) Fog::Logger.debug 'Blob deleted successfully.' true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/create_page_blob.rb0000644000004100000410000000174014615741124027443 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def create_page_blob(container_name, blob_name, blob_size, options = {}) options[:request_id] = SecureRandom.uuid msg = "create_page_blob #{blob_name} to the container #{container_name}. blob_size: #{blob_size}, options: #{options}" Fog::Logger.debug msg begin @blob_client.create_page_blob(container_name, blob_name, blob_size, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Page blob #{blob_name} created successfully." true end end # This class provides the mock implementation for unit tests. class Mock def create_page_blob(*) Fog::Logger.debug 'Page blob created successfully.' true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/acquire_blob_lease.rb0000644000004100000410000000162114615741124030004 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def acquire_blob_lease(container_name, name, options = {}) options[:request_id] = SecureRandom.uuid msg = "Leasing blob: #{name} of container #{container_name} options: #{options}" Fog::Logger.debug msg begin lease_id = @blob_client.acquire_blob_lease(container_name, name, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Blob #{name} leased successfully." lease_id end end # This class provides the mock implementation for unit tests. class Mock def acquire_blob_lease(*) { 'leaseId' => 'abc123' } end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/delete_object_url.rb0000644000004100000410000000176614615741124027670 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implemention for service calls. class Real # Get a pre-signed URL to delete an object in Azure blob storage # This is to make this library compatible with CarrierWave. # # @param container_name [String] Name of container containing blob # @param blob_name [String] Name of blob to get expiring url for # @param expires [Time] An expiry time for this url # # @return [String] - https url for blob # # @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-blob # def delete_object_url(container_name, blob_name, expires) delete_blob_https_url(container_name, blob_name, expires) end end # This class provides the mock implementation for unit tests. class Mock def delete_object_url(*args) delete_blob_https_url(*args) end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/delete_container.rb0000644000004100000410000000151414615741124027511 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def delete_container(name) options = { request_id: SecureRandom.uuid } msg = "Deleting container: #{name}. options: #{options}" Fog::Logger.debug msg begin @blob_client.delete_container(name, options) rescue Azure::Core::Http::HTTPError => ex return true if ex.message.include?('(404)') raise_azure_exception(ex, msg) end Fog::Logger.debug "Container #{name} deleted successfully." true end end # This class provides the mock implementation for unit tests. class Mock def delete_container(*) true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/list_blobs.rb0000644000004100000410000001625514615741124026351 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. # https://msdn.microsoft.com/en-us/library/azure/dd135734.aspx class Real def list_blobs(container_name, options = {}) options = options.dup options[:metadata] = true next_marker = nil blobs = [] msg = nil max_results = -1 max_results = options[:max_results].to_i if options[:max_results] begin loop do options[:request_id] = SecureRandom.uuid msg = "Listing blobs in container: #{container_name}, options: #{options}" Fog::Logger.debug msg temp = @blob_client.list_blobs(container_name, options) # Workaround for the issue https://github.com/Azure/azure-storage-ruby/issues/37 raise temp unless temp.instance_of?(Azure::Storage::Common::Service::EnumerationResults) blobs += temp unless temp.empty? break if temp.continuation_token.nil? || temp.continuation_token.empty? options[:marker] = temp.continuation_token next if max_results == -1 options[:max_results] = max_results - blobs.size if options[:max_results].zero? next_marker = temp.continuation_token break end end rescue Azure::Core::Http::HTTPError => ex raise 'NotFound' if ex.message.include?('(404)') raise_azure_exception(ex, msg) end Fog::Logger.debug "Listing blobs in container: #{container_name} successfully." { next_marker: next_marker, blobs: blobs } end end # This class provides the mock implementation for unit tests. class Mock def list_blobs(*) Fog::Logger.debug 'Listing blobs in container successfully.' { next_marker: 'marker', blobs: [ { 'name' => 'test_blob1', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3256874Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob2', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '0x8D29C92173526C8', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob3', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '0x8D29C92173526C8', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob4', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '0x8D29C92173526C8', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } } ] } end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/delete_object.rb0000644000004100000410000000052414615741124026775 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real alias delete_object delete_blob end # This class provides the mock implementation for unit tests. class Mock alias delete_object delete_blob end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb0000644000004100000410000000201714615741124030056 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def copy_blob_from_uri(destination_container, destination_blob, source_blob_uri, options = {}) options[:request_id] = SecureRandom.uuid msg = "Copying blob: #{source_blob_uri} to container #{destination_container} options: #{options}" Fog::Logger.debug msg begin copy_id, copy_status = @blob_client.copy_blob_from_uri(destination_container, destination_blob, source_blob_uri, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Copying blob: x-ms-copy-id: #{copy_id}, x-ms-copy-status: #{copy_status}" [copy_id, copy_status] end end # This class provides the mock implementation for unit tests. class Mock def copy_blob_from_uri(*) %w(abc123 pending) end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/release_blob_lease.rb0000644000004100000410000000161314615741124027774 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def release_blob_lease(container_name, name, lease_id, options = {}) options[:request_id] = SecureRandom.uuid msg = "Releasing blob: #{name} of container #{container_name} having lease_id #{lease_id} options: #{options}" Fog::Logger.debug msg begin @blob_client.release_blob_lease(container_name, name, lease_id, options) rescue Azure::Core::Http::HTTPError => ex raise_azure_exception(ex, msg) end Fog::Logger.debug "Blob #{name} released successfully." true end end # This class provides the mock implementation for unit tests. class Mock def release_blob_lease(*) true end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/requests/storage/get_blob_properties.rb0000644000004100000410000000402214615741124030233 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class provides the actual implementation for service calls. class Real def get_blob_properties(container_name, name, options = {}) options[:request_id] = SecureRandom.uuid msg = "Get Blob #{name} properties in container #{container_name}, options: #{options}." Fog::Logger.debug msg begin blob = @blob_client.get_blob_properties(container_name, name, options) rescue Azure::Core::Http::HTTPError => ex raise 'NotFound' if ex.message.include?('(404)') raise_azure_exception(ex, msg) end Fog::Logger.debug "Getting properties of blob #{name} successfully." blob end end # This class provides the mock implementation for unit tests. class Mock def get_blob_properties(*) blob = Azure::Storage::Blob::Blob.new blob.name = 'test_blob' blob.metadata = {} blob.properties = { last_modified: 'Mon, 04 Jul 2016 09:30:31 GMT', etag: '0x8D3A3EDD7C2B777', lease_status: 'unlocked', lease_state: 'available', lease_duration: nil, content_length: 4_194_304, content_type: 'application/octet-stream', content_encoding: nil, content_language: nil, content_disposition: nil, content_md5: 'tXAohIyxuu/t94Lp/ujeRw==', cache_control: nil, sequence_number: 0, blob_type: 'PageBlob', copy_id: '095adc3b-e277-4c3d-97e0-0abca881f60c', copy_status: 'success', copy_source: 'https://testaccount.blob.core.windows.net/testblob/4m?snapshot=2016-02-04T08%3A35%3A50.3157696Z', copy_progress: '4194304/4194304', copy_completion_time: 'Thu, 04 Feb 2016 08:35:52 GMT', copy_status_description: nil, accept_ranges: 0 } blob end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/identity_encoding_filter.rb0000644000004100000410000000044114615741124025730 0ustar www-datawww-datamodule Fog module AzureRM # This filter prevents Net::HTTP from inflating compressed response bodies class IdentityEncodingFilter def call(request, next_filter) request.headers['Accept-Encoding'] ||= 'identity' next_filter.call end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/config.rb0000644000004100000410000000010514615741124022126 0ustar www-datawww-datamodule Fog module AzureRM LOCATION = 'eastus'.freeze end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/utilities/0000755000004100000410000000000014615741124022353 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/utilities/logger_messages.yml0000644000004100000410000000246414615741124026252 0ustar www-datawww-datanetwork: express_route_circuit_authentication: message: create: Creating/updating Express Route Circuit Authorization 'NAME' in Resource Group 'RESOURCE_GROUP'. delete: Deleting Express Route Circuit Authorization 'NAME' from Resource Group 'RESOURCE_GROUP'. get: Getting Express Route Circuit Authorization 'NAME' from Resource Group 'RESOURCE_GROUP'. list: Getting list of Express Route Circuit Authorizations from Resource Group 'RESOURCE_GROUP'. local_network_gateway: message: create: Creating/Updating Local Network Gateway 'NAME' in Resource Group 'RESOURCE_GROUP'. delete: Deleting Local Network Gateway 'NAME' in Resource Group 'RESOURCE_GROUP'. get: Getting Local Network Gateway 'NAME' in Resource Group 'RESOURCE_GROUP'. list: Getting list of Local Network Gateways in Resource Group 'RESOURCE_GROUP'. virtual_network_gateway_connection: message: create: Creating/Updating Virtual Network Gateway Connection 'NAME' in Resource Group 'RESOURCE_GROUP'. delete: Deleting Virtual Network Gateway Connection 'NAME' in Resource Group 'RESOURCE_GROUP'. get: Getting Virtual Network Gateway Connection 'NAME' in Resource Group 'RESOURCE_GROUP'. list: Getting list of Virtual Network Gateway Connections in Resource Group 'RESOURCE_GROUP'.gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/utilities/general.rb0000755000004100000410000001133014615741124024316 0ustar www-datawww-datarequire File.expand_path('../../custom_fog_errors.rb', __FILE__) module Fog module AzureRM module Utilities # General utilities mixin. module General # rubocop:disable Metrics/ModuleLength # Pick Resource Group name from Azure Resource Id(String) def get_resource_group_from_id(id) id.split('/')[4] end # Pick Virtual Network name from Subnet Resource Id(String) def get_virtual_network_from_id(subnet_id) subnet_id.split('/')[8] end # Pick Virtual Machine name from Virtual Machine Extension Id(String) def get_virtual_machine_from_id(vme_id) vme_id.split('/')[VM_NAME_POSITION] end # Extract Endpoint type from (String) def get_end_point_type(endpoint_type) endpoint_type.split('/')[2] end def get_record_set_from_id(id) id.split('/')[8] end def get_type_from_recordset_type(type) type.split('/')[2] end def get_hash_from_object(object) hash = {} object.instance_variables.each { |attr| hash[attr.to_s.delete('@')] = object.instance_variable_get(attr) } hash end # Extract Traffic Manager Profile Name from Endpoint id(String) def get_traffic_manager_profile_name_from_endpoint_id(endpoint_id) endpoint_id.split('/')[8] end # Pick Express Route Circuit name from Id(String) def get_circuit_name_from_id(circuit_id) circuit_id.split('/')[8] end def get_record_type(type) type.split('/').last end def raise_azure_exception(exception, _msg) raise Fog::AzureRM::CustomAzureCoreHttpError.new(exception) if exception.is_a?(Azure::Core::Http::HTTPError) raise exception end # Make sure if input_params(Hash) contains all keys present in required_params(Array) def validate_params(required_params, input_params) missing_params = required_params.select { |param| param unless input_params.key?(param) } raise(ArgumentError, "Missing Parameters: #{missing_params.join(', ')} required for this operation") if missing_params.any? end def get_resource_from_resource_id(resource_id, position) data = resource_id.split('/') unless resource_id.nil? raise 'Invalid Resource ID' if data.count < 9 && data.count != 5 data[position] end def random_string(length) (0...length).map { ('a'..'z').to_a[rand(26)] }.join end def storage_endpoint_suffix(environment = ENVIRONMENT_AZURE_CLOUD) case environment when ENVIRONMENT_AZURE_CHINA_CLOUD '.core.chinacloudapi.cn' when ENVIRONMENT_AZURE_US_GOVERNMENT '.core.usgovcloudapi.net' when ENVIRONMENT_AZURE_GERMAN_CLOUD '.core.cloudapi.de' else '.core.windows.net' end end def get_blob_endpoint(storage_account_name, enable_https = false, environment = ENVIRONMENT_AZURE_CLOUD) protocol = enable_https ? 'https' : 'http' "#{protocol}://#{storage_account_name}.blob#{storage_endpoint_suffix(environment)}" end def get_blob_endpoint_with_domain(storage_account_name, enable_https = false, domain = 'blob.core.windows.net') protocol = enable_https ? 'https' : 'http' "#{protocol}://#{storage_account_name}.#{domain}" end # Parse storage blob/container to a hash def parse_storage_object(object) data = {} if object.is_a? Hash object.each do |k, v| if k == 'properties' v.each do |j, l| data[j] = l end else data[k] = v end end else object.instance_variables.each do |p| kname = p.to_s.delete('@') if kname == 'properties' properties = object.instance_variable_get(p) properties.each do |k, v| data[k.to_s] = v end else data[kname] = object.instance_variable_get(p) end end end data['last_modified'] = Time.parse(data['last_modified']) data['etag'].delete!('"') data end def get_image_name(id) id.split('/').last end def get_subscription_id(id) id.split('/')[2] end def remove_trailing_periods_from_path_segments(path) path.split('/').map { |segment| segment.gsub(/\.*$/, '') }.join('/') end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/0000755000004100000410000000000014615741124021623 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/0000755000004100000410000000000014615741124023267 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/kind.rb0000644000004100000410000000031514615741124024540 0ustar www-datawww-datamodule Fog module ARM module Storage module Models module Kind Storage = 'Storage'.freeze BlobStorage = 'BlobStorage'.freeze end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/directory.rb0000644000004100000410000001331114615741124025617 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class is giving implementation of create and delete a container. class Directory < Fog::Model VALID_ACLS = ['container', 'blob', 'unknown', nil].freeze include Fog::AzureRM::Utilities::General attr_writer :acl identity :key, aliases: %w(Name name) attribute :etag, aliases: %w(Etag ETag) attribute :last_modified, aliases: %w(Last-Modified LastModified), type: 'time' attribute :lease_duration, aliases: %w(Lease-Duration LeaseDuration) attribute :lease_state, aliases: %w(Lease-State LeaseState) attribute :lease_status, aliases: %w(Lease-Status LeaseStatus) attribute :metadata # Set the the permission # # @param new_acl [String] permission. Options: container, blob or nil. unknown is for internal usage. # container: Full public read access. Container and blob data can be read via anonymous request. # Clients can enumerate blobs within the container via anonymous request, but cannot # enumerate containers within the storage account. # blob: Public read access for blobs only. Blob data within this container can be read via # anonymous request, but container data is not available. Clients cannot enumerate blobs # within the container via anonymous request. # nil: No public read access. Container and blob data can be read by the account owner only. # unknown: Internal usage in fog-azure-rm. # # @return [String] Permission. # # @exception ArgumentError Raised when new_acl is not 'container', 'blob', nil or 'unknown'. # # Reference: https://msdn.microsoft.com/en-us/library/azure/dd179391.aspx # def acl=(new_acl) raise ArgumentError.new("acl must be one of [#{VALID_ACLS.join(', ')}nil]") unless VALID_ACLS.include?(new_acl) attributes[:acl] = new_acl end # Get the the permission # # required attributes: key # # @return [String] Permission. # def acl requires :key return attributes[:acl] if attributes[:acl] != 'unknown' || !persisted? data = service.get_container_acl(key) attributes[:acl] = data[0] end # Destroy directory. # # required attributes: key # # @return [Boolean] True if successful # def destroy requires :key service.delete_container(key) end # 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. # # @return [Fog::AzureRM::Storage::Files] Files. # def files @files ||= Fog::AzureRM::Storage::Files.new(directory: self, service: service) end # Set the container permission to public or private # # @param [Boolean] True: public(container); False: private(nil) # # @return [Boolean] True if public; Otherwise return false. # def public=(new_public) attributes[:acl] = new_public ? 'container' : nil new_public end # Get the public URL of the directory # # required attributes: key # # @param options [Hash] # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https. # # @return [String] A public URL. # def public_url(options = {}) requires :key service.get_container_url(key, options) if acl == 'container' end # Create/Update the directory # # required attributes: key # # @param options [Hash] # @option options [Boolean] is_create Sets whether to create or update the directory. Default is true(create). # Will update metadata and acl when is_create is set to false. # # @return [Boolean] True if successful. # 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] = metadata if metadata container = service.create_container(key, options) else service.put_container_acl(key, acl) if acl != 'unknown' service.put_container_metadata(key, metadata) if metadata container = service.get_container_properties(key) end attributes[:is_persisted] = true data = parse_storage_object(container) merge_attributes(data) true end # Check whether the directory is created. # # @return [Boolean] True if the file is created. Otherwise return false. # 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 end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/storage_accounts.rb0000644000004100000410000000347214615741124027165 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class is giving implementation of all/list, get and # check name availability for storage account. class StorageAccounts < Fog::Collection model Fog::AzureRM::Storage::StorageAccount attribute :resource_group def all accounts = [] if !resource_group.nil? requires :resource_group hash_of_storage_accounts = service.list_storage_account_for_rg(resource_group) else hash_of_storage_accounts = service.list_storage_accounts end hash_of_storage_accounts.each do |account| accounts << Fog::AzureRM::Storage::StorageAccount.parse(account) end load(accounts) end def get(resource_group_name, storage_account_name) storage_account = service.get_storage_account(resource_group_name, storage_account_name) storage_account_fog = Fog::AzureRM::Storage::StorageAccount.new(service: service) storage_account_fog.merge_attributes(Fog::AzureRM::Storage::StorageAccount.parse(storage_account)) end def check_name_availability(name, type = 'Microsoft.Storage/storageAccounts') service.check_storage_account_name_availability(name, type) end def delete_storage_account_from_tag(resource_group_name, tag_key, tag_value) storage_accounts = service.storage_accounts(resource_group: resource_group_name) storage_accounts.each do |account| account.destroy if account.tags[tag_key].eql? tag_value end end def check_storage_account_exists(resource_group_name, storage_account_name) service.check_storage_account_exists(resource_group_name, storage_account_name) end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/files.rb0000644000004100000410000001506214615741124024722 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class is giving implementation of listing blobs. class Files < Fog::Collection include Fog::AzureRM::Utilities::General attribute :directory attribute :delimiter, aliases: 'Delimiter' attribute :marker, aliases: 'Marker' attribute :max_results, aliases: %w(max-results MaxResults max_keys MaxKeys max-keys) attribute :next_marker, aliases: %w(NextMarker next-marker) attribute :prefix, aliases: 'Prefix' model Fog::AzureRM::Storage::File # List all files(blobs) under the directory. # # required attributes: directory # # @param options [Hash] # @option options [String] max_keys or # max_results Sets the maximum number of files to return. # @option options [String] delimiter Sets to cause that the operation returns a BlobPrefix element in the response body that acts # as a placeholder for all files whose names begin with the same substring up to the appearance # of the delimiter character. The delimiter may be a single character or a string. # @option options [String] marker Sets the identifier that specifies the portion of the list to be returned. # @option options [String] prefix Sets filters the results to return only files whose name begins with the specified prefix. # # @return [Fog::AzureRM::Storage::Files] Return nil if the directory does not exist. # def all(options = {}) requires :directory options = { max_results: max_results, delimiter: delimiter, marker: marker, prefix: prefix }.merge!(options) options = options.reject { |_key, value| value.nil? || value.to_s.empty? } merge_attributes(options) parent = directory.collection.get( directory.key, options ) return nil unless parent merge_attributes(parent.files.attributes) load(parent.files.map(&:attributes)) end # Enumerate every file under the directory if block_given? # # @return [Fog::AzureRM::Storage::Files] # alias each_file_this_page each def each if block_given? subset = dup.all subset.each_file_this_page { |f| yield f } while subset.next_marker subset = subset.all(marker: subset.next_marker) subset.each_file_this_page { |f| yield f } end end self end # Get the file(blob) with full content as :body with the given name. # # required attributes: directory # # @param key [String] Name of file # @param options [Hash] # @option options [String] block_size Sets buffer size when block_given? is true. Default is 32 MB # # @return [Fog::AzureRM::Storage::File] A file. Return nil if the file does not exist. # def get(key, options = {}, &block) requires :directory blob, content = service.get_blob(directory.key, key, options, &block) data = parse_storage_object(blob) file_data = data.merge( body: content, key: key ) new(file_data) rescue => error return nil if error.message == 'NotFound' raise error end # Get the URL of the file(blob) with the given name. # # required attributes: directory # # @param key [String] Name of file # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format. # @param options [Hash] # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https. # # @return [String] A URL. # def get_url(key, expires, options = {}) requires :directory if options[:scheme] == 'http' get_http_url(key, expires, options) else get_https_url(key, expires, options) end end # Get the http URL of the file(blob) with the given name. # # required attributes: directory # # @param key [String] Name of file # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format. # @param options [Hash] Unused. To keep same interface as other providers. # # @return [String] A http URL. # def get_http_url(key, expires, options = {}) requires :directory service.get_blob_http_url(directory.key, key, expires, options) end # Get the https URL of the file(blob) with the given name. # # required attributes: directory # # @param key [String] Name of file # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format. # @param options [Hash] Unused. To keep same interface as other providers. # # @return [String] A https URL. # def get_https_url(key, expires, options = {}) requires :directory service.get_blob_https_url(directory.key, key, expires, options) end # Get the file(blob) without content with the given name. # # required attributes: directory # # @param key [String] Name of file # @param options [Hash] # # @return [Fog::AzureRM::Storage::File] A file. Return nil if the file does not exist. # def head(key, options = {}) requires :directory blob = service.get_blob_properties(directory.key, key, options) data = parse_storage_object(blob) file_data = data.merge(key: key) new(file_data) rescue => error return nil if error.message == 'NotFound' raise error end # Create a new file. # # required attributes: directory # # @return [Fog::AzureRM::Storage::File] A file. You need to use File.save to upload this new file. # def new(attributes = {}) requires :directory super({ directory: directory }.merge!(attributes)) end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/storage_account.rb0000644000004100000410000000624114615741124026777 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class is giving implementation of create/save and # delete/destroy for storage account. class StorageAccount < Fog::Model identity :name attribute :id attribute :location attribute :resource_group attribute :sku_name attribute :replication attribute :encryption attribute :tags def self.parse(storage_account) hash = {} hash['id'] = storage_account.id hash['name'] = storage_account.name hash['location'] = storage_account.location hash['resource_group'] = get_resource_group_from_id(storage_account.id) hash['sku_name'] = storage_account.sku.name.split('_').first hash['replication'] = storage_account.sku.name.split('_').last hash['encryption'] = storage_account.encryption.services.blob.enabled unless storage_account.encryption.nil? hash['tags'] = storage_account.tags hash end def save requires :name requires :location requires :resource_group # Create a model for new storage account. self.sku_name = STANDARD_STORAGE if sku_name.nil? self.replication = ALLOWED_STANDARD_REPLICATION.first if replication.nil? validate_sku_name! storage_account = service.create_storage_account(storage_account_params) merge_attributes(Fog::AzureRM::Storage::StorageAccount.parse(storage_account)) end def storage_account_params { resource_group: resource_group, name: name, sku_name: sku_name, location: location, replication: replication, encryption: encryption, tags: tags } end def update(storage_account_params) validate_input(storage_account_params) storage_account_params = merge_attributes(storage_account_params).all_attributes storage_account = service.update_storage_account(storage_account_params) merge_attributes(Fog::AzureRM::Storage::StorageAccount.parse(storage_account)) end def validate_sku_name! case sku_name when STANDARD_STORAGE raise 'Standard Replications can only be LRS, ZRS, GRS or RAGRS.' unless ALLOWED_STANDARD_REPLICATION.include?(replication) when PREMIUM_STORAGE raise 'Premium Replication can only be LRS.' if replication != 'LRS' else raise 'Account Type can only be Standard or Premium' end end def get_access_keys(options = {}) service.get_storage_access_keys(resource_group, name, options) end def destroy service.delete_storage_account(resource_group, name) end private def validate_input(attr_hash) invalid_attr = [:resource_group, :name, :location, :id] result = invalid_attr & attr_hash.keys raise 'Cannot modify the given attribute' unless result.empty? end private :storage_account_params, :validate_sku_name! end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/file.rb0000644000004100000410000002704114615741124024537 0ustar www-datawww-datarequire 'mime/types' module Fog module AzureRM class Storage # This class is giving implementation of create/save and # delete/destroy for Blob. class File < Fog::Model include Fog::AzureRM::Utilities::General identity :key, aliases: %w(Name name Key) attr_writer :body attribute :directory attribute :accept_ranges, aliases: %w(Accept-Ranges AcceptRanges) attribute :content_length, aliases: %w(Content-Length Size), type: :integer attribute :content_type, aliases: %w(Content-Type ContentType) attribute :content_md5, aliases: %w(Content-MD5 ContentMD5) attribute :content_encoding, aliases: %w(Content-Encoding ContentEncoding) attribute :content_language, aliases: %w(Content-Language ContentLanguage) attribute :cache_control, aliases: %w(Cache-Control CacheControl) attribute :content_disposition, aliases: %w(Content-Disposition ContentDisposition) attribute :copy_completion_time, aliases: %w(Copy-Completion-Time CopyCompletionTime) attribute :copy_status, aliases: %w(Copy-Status CopyStatus) attribute :copy_status_description, aliases: %w(Copy-Status-Description CopyStatusDescription) attribute :copy_id, aliases: %w(Copy-Id CopyId) attribute :copy_progress, aliases: %w(Copy-Progress CopyProgress) attribute :copy_source, aliases: %w(Copy-Source CopySource) attribute :etag, aliases: %w(Etag ETag) attribute :last_modified, aliases: %w(Last-Modified LastModified), type: 'time' attribute :lease_duration, aliases: %w(Lease-Duration LeaseDuration) attribute :lease_state, aliases: %w(Lease-State LeaseState) attribute :lease_status, aliases: %w(Lease-Status LeaseStatus) attribute :sequence_number, aliases: %w(Sequence-Number SequenceNumber) attribute :blob_type, aliases: %w(Blob-Type BlobType) attribute :metadata # Save the file to the directory in Azure storage. # TODO: Support snapshots. # # required attributes: body(Only if update_body is true), directory, key # # @param identity [String] Name of directory # @param options [Hash] # @option options [Boolean] update_body Sets whether to upload the body of the file. Default is true. # Will update metadata and properties when update_body is set to false. # @option options [Integer] worker_thread_num Sets how many threads will be used to upload the body. Default is 8. # @option options [String] blob_type or # Blob-Type Sets blob type for the file. Options: 'BlockBlob' or 'PageBlob'. Default is 'BlockBlob'. # @option options [String] content_type or # Content-Type Sets content type for the file. For example, 'text/plain'. # @option options [String] content_md5 or # Content-MD5 Sets content MD5 hash for the file. Only for store. # When a block file whose size <= 32 MB, Azure will verify the integrity of the blob during transport. # Please reference this issue: https://github.com/Azure/azure-storage-ruby/issues/64 # @option options [String] content_encoding or # Content-Encoding Sets content encoding for the file. For example, 'x-gzip'. # @option options [String] content_language or # Content-Language Sets the natural languages used by the file. # @option options [String] cache_control or # Cache-Control Sets content encoding for the file. For example, 'No-cache'. # @option options [String] content_disposition or # Content-Disposition Sets content disposition for the file. For exampple, 'attachment; filename=testing.txt'. # @option options [Hash] metadata Sets custom metadata values to store with the file. # # @return [Boolean] # def save(options = {}) update_body = options.delete(:update_body) update_body = true if update_body.nil? requires :directory, :key raise ArgumentError.new('body is required when update_body is true') if update_body && attributes[:body].nil? remap_attributes( options, 'Blob-Type' => :blob_type, 'Content-Type' => :content_type, 'Content-MD5' => :content_md5, 'Content-Encoding' => :content_encoding, 'Content-Language' => :content_language, 'Cache-Control' => :cache_control, 'Content-Disposition' => :content_disposition ) options = { blob_type: blob_type, content_type: content_type, content_md5: content_md5, content_encoding: content_encoding, content_language: content_language, cache_control: cache_control, content_disposition: content_disposition, metadata: metadata }.merge!(options) options = options.reject { |_key, value| value.nil? || value.to_s.empty? } if update_body blob = save_blob(options) data = parse_storage_object(blob) merge_attributes(data) attributes[:content_length] = Fog::Storage.get_body_size(body) attributes[:content_type] ||= Fog::Storage.get_content_type(body) else service.put_blob_metadata(directory.key, key, options[:metadata]) if options[:metadata] options.delete(:metadata) service.put_blob_properties(directory.key, key, options) blob = service.get_blob_properties(directory.key, key) data = parse_storage_object(blob) merge_attributes(data) end true end # Get file's body if exists, else ''. # # @return [File || String] # def body return attributes[:body] if attributes[:body] return '' unless last_modified file = collection.get(identity) if file.nil? attributes[:body] = '' return '' end attributes[:body] = file.body end # Set body attribute. # # @param new_body [File || String] # # @return [File || String] # def body=(new_body) attributes[:body] = new_body end # Copy object from one container to other container. # # required attributes: directory, key # # @param target_directory_key [String] # @param target_file_key [String] # @param options [Hash] options for copy_object method # @option options [Integer] timeout Sets to raise a TimeoutError if the copy does not finish in timeout seconds. # # @return [Fog::AzureRM::Storage::File] New File. # def copy(target_directory_key, target_file_key, options = {}) requires :directory, :key timeout = options.delete(:timeout) copy_id, copy_status = service.copy_blob(target_directory_key, target_file_key, directory.key, key, options) service.wait_blob_copy_operation_to_finish(target_directory_key, target_file_key, copy_id, copy_status, timeout) target_directory = service.directories.new(key: target_directory_key) target_directory.files.head(target_file_key) end # Copy object from a uri. # # required attributes: directory, key # # @param source_uri [String] # @param options [Hash] options for copy_object method # @option options [Integer] timeout Sets to raise a TimeoutError if the copy does not finish in timeout seconds. # # @return [Boolean] # def copy_from_uri(source_uri, options = {}) requires :directory, :key timeout = options.delete(:timeout) copy_id, copy_status = service.copy_blob_from_uri(directory.key, key, source_uri, options) service.wait_blob_copy_operation_to_finish(directory.key, key, copy_id, copy_status, timeout) blob = service.get_blob_properties(directory.key, key) data = parse_storage_object(blob) merge_attributes(data) true end # Destroy file. # # required attributes: directory, key # # @param options [Hash] # @option options versionId [] # # @return [Boolean] true if successful # def destroy(options = {}) requires :key requires :directory attributes[:body] = nil service.delete_blob(directory.key, key, options) true end # Get whether the file can be accessed by anonymous. # # @return [Boolean] # def public? requires :directory # TBD: The blob can be accessed if read permision is set in one access policy of the container. directory.acl == 'container' || directory.acl == 'blob' end # Get publicly accessible url. # # required attributes: directory, key # # @param options [Hash] # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https. # # @return [String] A public url. # def public_url(options = {}) requires :directory, :key options[:scheme] == 'https' if options[:scheme].nil? @service.get_blob_url(directory.key, key, options) if public? end # Get a url for file. # # required attributes: key # # @param expires [Time] The time at which the shared access signature becomes invalid, in a UTC format. # @param options [Hash] # @option options [String] scheme Sets which URL to get, http or https. Options: https or http. Default is https. # # @return [String] A public url which will expire after the specified time. # def url(expires, options = {}) requires :key collection.get_url(key, expires, normalize_options(options)) end private def normalize_options(options) # AWS S3 and Google Cloud Storage pass response-content-disposition # as a query string, while Azure needs the content_disposition parameter # to generate a SAS token. options = options.dup options[:content_disposition] ||= options.dig(:query, 'response-content-disposition') options[:content_type] ||= options.dig(:query, 'response-content-type') options.delete(:query) options end # Upload blob def save_blob(options) if options[:blob_type].nil? || options[:blob_type] == 'BlockBlob' service.create_block_blob(directory.key, key, body, options) else service.save_page_blob(directory.key, key, body, options) service.get_blob_properties(directory.key, key) end end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/sku_name.rb0000644000004100000410000000054614615741124025423 0ustar www-datawww-datamodule Fog module ARM module Storage module Models module SkuName StandardLRS = 'Standard_LRS'.freeze StandardGRS = 'Standard_GRS'.freeze StandardRAGRS = 'Standard_RAGRS'.freeze StandardZRS = 'Standard_ZRS'.freeze PremiumLRS = 'Premium_LRS'.freeze end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/directories.rb0000644000004100000410000000607714615741124026142 0ustar www-datawww-datamodule Fog module AzureRM class Storage # This class is giving implementation of listing containers. class Directories < Fog::Collection include Fog::AzureRM::Utilities::General model Fog::AzureRM::Storage::Directory # List all directories(containers) in the storage account. # # @return [Fog::AzureRM::Storage::Directories] # def all containers = service.list_containers data = [] containers.each do |container| c = parse_storage_object(container) c[:acl] = 'unknown' data << c end load(data) end # Get a directory with files(blobs) under this directory. # You can set max_keys to 1 if you do not want to return all files under this directory. # # @param identity [String] Name of directory # @param options [Hash] # @option options [String] max_keys or # max_results Sets the maximum number of files to return. # @option options [String] delimiter Sets to cause that the operation returns a BlobPrefix element in the response body that acts # as a placeholder for all files whose names begin with the same substring up to the appearance # of the delimiter character. The delimiter may be a single character or a string. # @option options [String] marker Sets the identifier that specifies the portion of the list to be returned. # @option options [String] prefix Sets filters the results to return only files whose name begins with the specified prefix. # # @return [Fog::AzureRM::Storage::Directory] A directory. Return nil if the directory does not exist. # def get(identity, options = {}) remap_attributes(options, max_keys: :max_results) container = service.get_container_properties(identity) data = parse_storage_object(container) data[:acl] = 'unknown' directory = new(key: identity, is_persisted: true) directory.merge_attributes(data) data = service.list_blobs(identity, options) new_options = options.merge(next_marker: data[:next_marker]) directory.files.merge_attributes(new_options) blobs = [] data[:blobs].each do |blob| blobs << parse_storage_object(blob) end directory.files.load(blobs) directory rescue Exception => error return nil if error.message == 'NotFound' raise error end def delete_temporary_container(storage_account_name, access_key, container_name) storage_data = Fog::AzureRM::Storage.new(azure_storage_account_name: storage_account_name, azure_storage_access_key: access_key) storage_data.delete_container(container_name) end def check_container_exists(name) service.check_container_exists(name) end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/models/storage/sku_tier.rb0000644000004100000410000000031214615741124025435 0ustar www-datawww-datamodule Fog module ARM module Storage module Models module SkuTier Standard = 'Standard'.freeze Premium = 'Premium'.freeze end end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/docs/0000755000004100000410000000000014615741124021270 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/docs/structure.md0000644000004100000410000000542714615741124023662 0ustar www-datawww-data# Fog Whether you need compute, dns, storage, or a multitude of other services, fog provides an accessible entry point and facilitates cross service compatibility. Fog delivers the knowledge of cloud experts to you, helping you to bootstrap your cloud usage and guiding you as your own expertise develops. By coding with fog from the start you avoid vendor lock-in and give yourself more flexibility to provide value. Whether you are writing a library, designing a software as a service product or just hacking on the weekend this flexibility is a huge boon. # Structure fog is the Ruby cloud computing library, top to bottom: - Collections provide a simplified interface, making clouds easier to work with and switch between. - Requests allow power users to get the most out of the features of each individual cloud. - Mocks make testing and integrating a breeze. #### Collections Some collections are available across multiple providers: - dns providers have `zones` and `records` - compute providers have `images` and `servers` Collections share basic CRUD type operations, such as: - **all** - fetch every object of that type from the provider. - **get** - fetch a single object by it’s identity from the provider. #### Models Many of the collection methods return individual objects, which also provide common methods: - **destroy** - will destroy the persisted object from the provider. - **save** - persist the object to the provider. #### Requests Requests allow you to dive deeper when the models just can’t cut it. You can see a list of available requests by calling `requests` on the connection object. #### Mocks As you might imagine, testing code using fog can be slow and expensive, constantly turning on and shutting down instances. Mocking allows skipping this overhead by providing an in-memory representation resources as you make requests. # Fog Provider Directory Structure ```sh Plugin Root |--- lib |--- fog |--- azurerm.rb #registers provider |--- azurerm |--- compute.rb #registers all models, collections and requests |--- dns.rb #registers all models, collections and requests |--- storage.rb #registers all models, collections and requests |--- models #models and collections |--- compute #models and collections for compute |--- dns |--- storage |--- requests #requests - includes Real and Mock Classes |--- compute #requests for compute |--- dns |--- storage ``` For more information about fog structure [Click Here](http://fog.io/about/structure.html) gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/docs/storage.md0000644000004100000410000001721514615741124023264 0ustar www-datawww-data# Storage This document explains how to get started using Azure Storage Service with Fog. With this gem you can create, update, list or delete storage accounts. ## Usage First of all, you need to require the Fog library by executing: ```ruby require 'fog/azurerm' ``` ## Create Connection If you only want to manage the storage data, you can create the connection without the Azure subscription information: ```ruby fog_storage_service = Fog::AzureRM::Storage.new( azure_storage_account_name: '', # Name of an Azure Storage Account azure_storage_access_key: '', # Key of an Azure Storage Account environment: '' # Azure cloud environment. Default is AzureCloud. ) ``` ## Check Storage Container Existence ```ruby fog_storage_service.directories.check_container_exists('') ``` ## Create a storage container Create a storage container in the current storage account. ```ruby directory = fog_storage_service.directories.create( key: '', public: ) puts directory.key ``` ## List storage containers List all the storage containers in the current storage accounts. ```ruby fog_storage_service.directories.each do |directory| puts directory.key end ``` ## Get the access control level of the storage container Get the permissions for the specified container. The permissions indicate whether container data may be accessed publicly. ```ruby directory = fog_storage_service.directories.get('', max_keys: ) puts directory.acl ``` ## Set the access control level of the storage container Set the permissions for the specified container. The permissions indicate whether container data may be accessed publicly. The container permissions provide the following options for managing container access: - ###### Container Full public read access. Container and blob data can be read via anonymous request. Clients can enumerate blobs within the container via anonymous request, but cannot enumerate containers within the storage account. - ###### Blob Public read access for blobs only. Blob data within this container can be read via anonymous request, but container data is not available. Clients cannot enumerate blobs within the container via anonymous request. - ###### Nil No public read access. Container and blob data can be read by the account owner only. ```ruby directory = fog_storage_service.directories.get('', max_keys: ) directory.acl = '' directory.save(is_create: ) ``` ## Delete the storage container Mark the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection. ```ruby directory = fog_storage_service.directories.get('', max_keys: ) puts directory.destroy ``` ## Upload data as a block blob ```ruby directory = fog_storage_service.directories.get('', max_keys: ) options = { key: '', body: '' } new_block_blob = directory.files.create(options) puts new_block_blob.inspect ``` ## Upload a local file as a block blob ```ruby directory = fog_storage_service.directories.get('', max_keys: ) File.open('') do |file| options = { key: '', body: file } new_block_blob = directory.files.create(options) puts new_block_blob.inspect end ``` ## Upload VHD data as a page blob ```ruby directory = fog_storage_service.directories.get('', max_keys: ) options = { key: '', body: '', blob_type: '' } new_page_blob = directory.files.create(options) puts new_page_blob.inspect ``` ## Upload a local VHD as a page blob ```ruby directory = fog_storage_service.directories.get('', max_keys: ) File.open('') do |file| options = { key: '', body: file, blob_type: '' } new_page_blob = directory.files.create(options) puts new_page_blob.inspect end ``` ## Copy Blob from one container to another ```ruby directory = fog_storage_service.directories.get('', max_keys: ) copied_blob = directory.files.head('').copy('', '') puts copied_blob.inspect ``` ## Copy Blob from one uri to self ```ruby directory = fog_storage_service.directories.get('', max_keys: ) copied_blob = directory.files.new(key: '') copied_blob.copy_from_uri('') puts copied_blob.inspect ``` ## Download a small blob to a local file ```ruby directory = fog_storage_service.directories.get('', max_keys: ) blob = directory.files.get('') File.open('', 'wb') do |file| file.write(blob.body) end puts "File Size: #{::File.size }" ``` ## Download a large blob to a local file ```ruby directory = fog_storage_service.directories.get('', max_keys: ) File.open('', 'wb') do |file| directory.files.get('') do |chunk, remaining_bytes, total_bytes| puts "remaining_bytes: #{remaining_bytes}, total_bytes: #{total_bytes}" file.write(chunk) end end puts "File Size: #{::File.size }" ``` ## Delete the storage blob Mark the specified blob for deletion. The blob is later deleted during garbage collection. ```ruby directory = fog_storage_service.directories.get('', max_keys: ) blob = directory.files.head('') puts blob.destroy ``` ## Set storage blob properties Set the storage blob properties. ```ruby directory = fog_storage_service.directories.get('', max_keys: ) blob = directory.files.head('') blob.content_language = '' blob.content_disposition = '' blob.save(update_body: ) ``` ## Metadata Metadata allows us to provide descriptive information about specific containers or blobs. This is simply providing name/value pairs of data we want to set on the container or blob. ### Get Blob Metadata ```ruby directory = fog_storage_service.directories.get('', max_keys: ) blob = directory.files.head('') puts blob.metadata ``` ### Set Blob Metadata ```ruby directory = fog_storage_service.directories.get('', max_keys: ) blob = directory.files.head('') blob.metadata = { Category: '', Resolution: '' } blob.save(update_body: ) ``` ### Get Container Metadata ```ruby directory = fog_storage_service.directories.get('', max_keys: ) puts directory.metadata ``` ### Set Container Metadata ```ruby directory = fog_storage_service.directories.get('', max_keys: ) directory.metadata = { CreatedBy: '', SourceMachine: '', category: '', docType: '' } directory.save(is_create: ) ``` ## Support and Feedback Your feedback is appreciated! If you have specific issues with the fog ARM, you should file an issue via Github. gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/custom_fog_errors.rb0000644000004100000410000000053714615741124024433 0ustar www-datawww-data# This file contains any or all custom Fog errors that we create module Fog module AzureRM # This is a custom Fog exception inherited from Azure::Core::Http::HTTPError class CustomAzureCoreHttpError < Azure::Core::Http::HTTPError def initialize(azure_exception) super(azure_exception.http_response) end end end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/version.rb0000755000004100000410000000010314615741124022347 0ustar www-datawww-datamodule Fog module AzureRM VERSION = '1.9.1'.freeze end end gitlab-fog-azure-rm-1.9.1/lib/fog/azurerm/constants.rb0000755000004100000410000000532214615741124022706 0ustar www-datawww-datamodule Fog module AzureRM AZURE_RESOURCE = 'https://management.azure.com'.freeze DEFAULT_ADDRESS_PREFIXES = ['10.2.0.0/16'].freeze SUBNET = 'Subnet'.freeze PUBLIC_IP = 'Public-IP-Address'.freeze NETWORK_SECURITY_GROUP = 'Network-Security-Group'.freeze STANDARD_STORAGE = 'Standard'.freeze PREMIUM_STORAGE = 'Premium'.freeze ALLOWED_STANDARD_REPLICATION = %w[LRS ZRS GRS RAGRS].freeze API_VERSION = '2016-06-01'.freeze FAULT_DOMAIN_COUNT = 2 UPDATE_DOMAIN_COUNT = 5 WINDOWS = 'windows'.freeze VPN = 'Vpn'.freeze MICROSOFT_PEERING = 'MicrosoftPeering'.freeze RESOURCE_GROUP_NAME = 4 RESOURCE_PROVIDER_NAMESPACE = 6 RESOURCE_TYPE = 7 RESOURCE_NAME = 8 ENDPOINT_PREFIX = 'Microsoft.Network/trafficManagerProfiles'.freeze DISK_PREFIX = 'Microsoft.Compute/disks'.freeze SNAPSHOT_PREFIX = 'Microsoft.Compute/snapshots'.freeze AZURE_ENDPOINTS = 'azureEndpoints'.freeze EXTERNAL_ENDPOINTS = 'externalEndpoints'.freeze NESTED_ENDPOINTS = 'nestedEndpoints'.freeze GLOBAL = 'global'.freeze UPLOAD_BLOB_WORKER_THREAD_COUNT = 8 VM_NAME_POSITION = 8 PRIMARY_NIC_INDEX = 0 ENVIRONMENT_AZURE_CLOUD = 'AzureCloud'.freeze ENVIRONMENT_AZURE_CHINA_CLOUD = 'AzureChinaCloud'.freeze ENVIRONMENT_AZURE_US_GOVERNMENT = 'AzureUSGovernment'.freeze ENVIRONMENT_AZURE_GERMAN_CLOUD = 'AzureGermanCloud'.freeze PLATFORM_LINUX = 'linux'.freeze # State of the copy operation COPY_STATUS = { # The copy completed successfully. SUCCESS: 'success', # The copy is in progress PENDING: 'pending' }.freeze # https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx # The maximum size for a block blob created via Put Blob is 64 MB. But for better performance, this size should be 32 MB. # If your blob is larger than 32 MB, you must upload it as a set of blocks. SINGLE_BLOB_PUT_THRESHOLD = 32 * 1024 * 1024 # Block blob: https://msdn.microsoft.com/en-us/library/azure/dd135726.aspx # Page blob: https://msdn.microsoft.com/en-us/library/azure/ee691975.aspx # Each block/page can be a different size, up to a maximum of 4 MB MAXIMUM_CHUNK_SIZE = 4 * 1024 * 1024 # The hash value of 4MB empty content HASH_OF_4MB_EMPTY_CONTENT = 'b5cfa9d6c8febd618f91ac2843d50a1c'.freeze REST_CLIENT_API_VERSION = %w[2014-04-01-preview 2016-05-01].freeze AS_SKU_CLASSIC = 'Classic'.freeze AS_SKU_ALIGNED = 'Aligned'.freeze # The tag key and tag value for creating a temporary storage account for generalized image TEMPORARY_STORAGE_ACCOUNT_TAG_KEY = 'generalized_image'.freeze TEMPORARY_STORAGE_ACCOUNT_TAG_VALUE = 'delete'.freeze HTTP_NOT_FOUND = 404 end end gitlab-fog-azure-rm-1.9.1/test/0000755000004100000410000000000014615741124016311 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/requests/0000755000004100000410000000000014615741124020164 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/requests/storage/0000755000004100000410000000000014615741124021630 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/requests/storage/test_save_page_blob.rb0000644000004100000410000000753614615741124026157 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestSavePageBlob < Minitest::Test # This class posesses the test cases for the requests of saving storage page blob. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) end def test_save_page_blob_success body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024 @service.stub :create_page_blob, true do @service.stub :put_blob_pages, true do assert @service.save_page_blob('test_container', 'test_blob', body, worker_thread_num: 6, content_md5: 'oafL1+HS78x65+e39PGIIg==') end end end def test_save_page_blob_with_file_handle_success data_length = 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024 i = 0 multiple_values = lambda do |*| i += 1 return 'd' * 4 * 1024 * 1024 if i == 1 return 'd' * 1 * 1024 * 1024 if i == 2 return nil end temp_file = '/dev/null' File.open(temp_file, 'r') do |file_handle| file_handle.stub :read, multiple_values do file_handle.stub :size, data_length do file_handle.stub :rewind, nil do @service.stub :create_page_blob, true do @service.stub :put_blob_pages, true do assert @service.save_page_blob('test_container', 'test_blob', file_handle, worker_thread_num: 0) end end end end end end end def test_save_page_blob_with_file_handle_do_not_support_rewind_success data_length = 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024 i = 0 multiple_values = lambda do |*| i += 1 return 'd' * 4 * 1024 * 1024 if i == 1 return 'd' * 1 * 1024 * 1024 if i == 2 return nil end temp_file = '/dev/null' exception = ->(*) { raise 'do not support rewind' } File.open(temp_file, 'r') do |file_handle| file_handle.stub :read, multiple_values do file_handle.stub :size, data_length do file_handle.stub :rewind, exception do @service.stub :create_page_blob, true do @service.stub :put_blob_pages, true do assert @service.save_page_blob('test_container', 'test_blob', file_handle, worker_thread_num: 'invalid') end end end end end end end def test_save_page_blob_http_exception body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024 http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @service.stub :create_page_blob, http_exception do @service.stub :delete_blob, true do assert_raises(Azure::Core::Http::HTTPError) do @service.save_page_blob('test_container', 'test_blob', body, {}) end end end end def test_save_page_blob_invalid_size_exception body = 'd' * 1025 # The page blob size must be aligned to a 512-byte boundary. @service.stub :delete_blob, true do assert_raises(RuntimeError) do @service.save_page_blob('test_container', 'test_blob', body, {}) end end end def test_save_page_blob_fail_when_delete_blob_http_exception body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024 http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @service.stub :create_page_blob, http_exception do @service.stub :delete_blob, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.save_page_blob('test_container', 'test_blob', body, {}) end end end end def test_save_page_blob_mock assert @mock_service.save_page_blob('test_container', 'test_blob', 'content', {}) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_create_block_blob.rb0000644000004100000410000000472314615741124026635 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestCreateBlockBlob < Minitest::Test # This class posesses the test cases for the requests of creating block blob. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @block_blob = ApiStub::Requests::Storage::File.block_blob @emtpy_block_blob = ApiStub::Requests::Storage::File.emtpy_block_blob end def test_create_block_blob_success @blob_client.stub :create_block_blob, @block_blob do assert_equal @block_blob, @service.create_block_blob('test_container', 'test_blob', 'data') end end def test_create_block_blob_without_content_success @blob_client.stub :create_block_blob, @emtpy_block_blob do assert_equal @emtpy_block_blob, @service.create_block_blob('test_container', 'test_blob', nil) end end def test_create_block_blob_with_file_handle_success temp_file = '/dev/null' File.open(temp_file, 'r') do |body| body.stub :read, 'data' do body.stub :rewind, nil do @blob_client.stub :create_block_blob, @block_blob do assert_equal @block_blob, @service.create_block_blob('test_container', 'test_blob', body) end end end end exception = ->(*) { raise 'do not support rewind' } File.open(temp_file, 'r') do |body| body.stub :read, 'data' do body.stub :rewind, exception do @blob_client.stub :create_block_blob, @block_blob do assert_equal @block_blob, @service.create_block_blob('test_container', 'test_blob', body) end end end end end def test_create_block_blob_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :create_block_blob, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.create_block_blob('test_container', 'test_blob', nil) end end end def test_create_block_blob_mock assert_equal @block_blob, @mock_service.create_block_blob('test_container', 'test_blob', 'data') end def test_create_block_blob_without_content_mock assert_equal @emtpy_block_blob, @mock_service.create_block_blob('test_container', 'test_blob', nil) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_list_blobs.rb0000644000004100000410000000472414615741124025357 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestListBlobs < Minitest::Test # This class posesses the test cases for the requests of listing blobs in storage containers. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @blob_list = ApiStub::Requests::Storage::File.blob_list @blobs1 = Azure::Storage::Common::Service::EnumerationResults.new @blobs1.continuation_token = 'marker' @blobs1.push(@blob_list[0]) @blobs1.push(@blob_list[1]) @blobs2 = Azure::Storage::Common::Service::EnumerationResults.new @blobs2.push(@blob_list[2]) @blobs2.push(@blob_list[3]) end def test_list_blobs_success multiple_values = lambda do |_container_name, options| return @blobs2 if options[:marker] == 'marker' return @blobs1 end @blob_client.stub :list_blobs, multiple_values do result = @service.list_blobs('test_container') assert result[:next_marker].nil? assert_equal @blob_list, result[:blobs] end end def test_list_blobs_with_max_results_success @blob_client.stub :list_blobs, @blobs1 do options = { max_results: 2 } result = @service.list_blobs('test_container', options) assert_equal 'marker', result[:next_marker] assert_equal @blob_list[0, 2], result[:blobs] end end def test_list_blobs_not_found exception = ->(*) { raise StandardError.new('Not found(404). Not exist') } @blob_client.stub :list_blobs, exception do assert_raises('NotFound') do @service.list_blobs('test_container') end end end def test_list_blobs_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :list_blobs, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.list_blobs('test_container') end end end def test_list_blobs_exception @blob_client.stub :list_blobs, 'exception' do assert_raises(RuntimeError) do @service.list_blobs('test_container') end end end def test_list_blobs_mock result = @mock_service.list_blobs('test_container') assert_equal 'marker', result[:next_marker] assert_equal @blob_list, result[:blobs] end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_put_blob_https_url.rb0000644000004100000410000000232414615741124027127 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestPutBlobHttpsUrl < Minitest::Test # This class posesses the test cases for the requests of Blob service. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @service = Fog::AzureRM::Storage.new(storage_account_credentials) @signature_client = @service.send(:signature_client, Minitest::Mock.new) @url = ApiStub::Requests::Storage::File.blob_https_url @token = ApiStub::Requests::Storage::File.blob_url_token end def test_put_blob_https_urls_success @signature_client.stub :generate_service_sas_token, @token do assert_equal "#{@url}?#{@token}", @service.put_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600) assert_equal "#{@url}?#{@token}", @service.put_object_url('test_container', 'test_blob', Time.now.utc + 3600, {}) end end def test_put_blob_https_url_mock assert_equal "#{@url}?#{@token}", @mock_service.put_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600) assert_equal "#{@url}?#{@token}", @mock_service.put_object_url('test_container', 'test_blob', Time.now.utc + 3600, {}) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_put_container_acl.rb0000644000004100000410000000217614615741124026713 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestPutContainerACL < Minitest::Test # This class posesses the test cases for the requests of setting storage container acl. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_put_container_acl_success @blob_client.stub :set_container_acl, true do assert @service.put_container_acl('test_container', 'container') end end def test_put_container_acl_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :set_container_acl, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.put_container_acl('test_container', 'container') end end end def test_put_container_acl_mock assert @mock_service.put_container_acl('test_container', 'container') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_blob_encoding.rb0000644000004100000410000000222414615741124026637 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ require 'webrick' class TestGetBlobGzipped < Minitest::Test def setup @server = WEBrick::HTTPServer.new( BindAddress: '127.0.0.1', Port: 0, Logger: WEBrick::Log.new(nil, 0), AccessLog: [] ) @server_uri = URI.parse("http://#{@server.config.values_at(:BindAddress, :Port).join(':')}/test") @thread = Thread.new do @server.start end @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def teardown @server&.shutdown @thread&.join end def test_get_blob_with_encoding io = StringIO.new.binmode gzip = Zlib::GzipWriter.new(io) gzip.write "Hello world.\n" gzip.close @server.mount_proc '/' do |_request, response| response.header['Content-Encoding'] = 'gzip' response.body = io.string end blob, content = @blob_client.stub :generate_uri, @server_uri do @service.get_blob('test_container', 'test_blob') end assert_equal 'gzip', blob.properties[:content_encoding] assert_equal io.string, content end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_put_blob_block.rb0000644000004100000410000000217514615741124026201 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestPutBlobBlock < Minitest::Test # This class posesses the test cases for the requests of putting blob block. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_put_blob_block_success @blob_client.stub :put_blob_block, true do assert @service.put_blob_block('test_container', 'test_blob', 'id', 'data') end end def test_put_blob_block_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :put_blob_block, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.put_blob_block('test_container', 'test_blob', 'id', 'data') end end end def test_put_blob_block_mock assert @mock_service.put_blob_block('test_container', 'test_blob', 'id', 'data') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_container_properties.rb0000644000004100000410000000311114615741124030305 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestGetContainerProperties < Minitest::Test # This class posesses the test cases for the requests of getting storage container properties. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @container = ApiStub::Requests::Storage::Directory.container end def test_get_container_properties_success @blob_client.stub :get_container_properties, @container do assert_equal @container, @service.get_container_properties('test_container') end end def test_get_container_properties_not_found exception = ->(_name, _option) { raise StandardError.new('Not found(404). Not exist') } @blob_client.stub :get_container_properties, exception do assert_raises('NotFound') do @service.get_container_properties('test_container') end end end def test_get_container_properties_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :get_container_properties, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.get_container_properties('test_container') end end end def test_get_container_properties_mock assert_equal @container, @mock_service.get_container_properties('test_container') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_commit_blob_blocks.rb0000644000004100000410000000220714615741124027040 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestCommitBlobBlocks < Minitest::Test # This class posesses the test cases for the requests of committing blob blocks. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_commit_blob_blocks_success @blob_client.stub :commit_blob_blocks, true do assert @service.commit_blob_blocks('test_container', 'test_blob', []) end end def test_commit_blob_blocks_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :commit_blob_blocks, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.commit_blob_blocks('test_container', 'test_blob', []) end end end def test_commit_blob_blocks_mock assert @mock_service.commit_blob_blocks('test_container', 'test_blob', []) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_acquire_container_lease.rb0000644000004100000410000000244014615741124030060 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestAcquireContainerLease < Minitest::Test # This class posesses the test cases for the requests of acquire container lease. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @container_lease_id = ApiStub::Requests::Storage::Directory.container_lease_id end def test_acquire_container_lease_success @blob_client.stub :acquire_container_lease, @container_lease_id do assert_equal @container_lease_id, @service.acquire_container_lease('test_container') end end def test_acquire_container_lease_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :acquire_container_lease, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.acquire_container_lease('test_container') end end end def test_acquire_container_lease_mock assert_equal @container_lease_id, @mock_service.acquire_container_lease('test_container') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_delete_object.rb0000644000004100000410000000265014615741124026007 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestDeleteObject < Minitest::Test # This class posesses the test cases for the requests of deleting storage blobs. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @mocked_not_found_response = mocked_storage_http_not_found_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_delete_object_success @blob_client.stub :delete_blob, true do assert @service.delete_object('test_container', 'test_blob') end end def test_delete_object_with_not_found_success http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_not_found_response) } @blob_client.stub :delete_blob, http_exception do assert @service.delete_object('test_container', 'test_blob') end end def test_delete_object_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :delete_blob, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.delete_object('test_container', 'test_blob') end end end def test_delete_object_mock assert @mock_service.delete_blob('test_container', 'test_blob') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_put_blob_properties.rb0000644000004100000410000000242214615741124027276 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestPutBlobProperties < Minitest::Test # This class posesses the test cases for the requests of setting blob properties. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @properties = { content_language: 'english', content_disposition: 'attachment' } end def test_put_blob_properties_success @blob_client.stub :set_blob_properties, true do assert @service.put_blob_properties('test_container', 'test_blob', @properties) end end def test_put_blob_properties_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :set_blob_properties, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.put_blob_properties('test_container', 'test_blob', @properties) end end end def test_put_blob_properties_mock assert @mock_service.put_blob_properties('test_container', 'test_blob', @properties) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_wait_blob_copy_operation_to_finish.rb0000644000004100000410000001171614615741124032340 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestWaitBlobCopyOperationToFinish < Minitest::Test # This class posesses the test cases for the requests of waiting storage blob copy operation to finish. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @blob = storage_blob @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_wait_blob_copy_operation_to_finish_with_success copy_id = @blob.properties[:copy_id] copy_status = 'pending' i = 0 multiple_values = lambda do |*| i += 1 if i == 1 @blob.properties[:copy_status] = copy_status @blob.properties[:copy_progress] = '0/1024' @blob.properties[:copy_status_description] = 'in progress' return @blob end if i == 2 @blob.properties[:copy_status] = copy_status @blob.properties[:copy_progress] = '2/1024' @blob.properties[:copy_status_description] = 'in progress' return @blob end if i == 3 @blob.properties[:copy_status] = copy_status @blob.properties[:copy_progress] = '1023/1024' @blob.properties[:copy_status_description] = 'in progress' return @blob end @blob.properties[:copy_status] = 'success' @blob.properties[:copy_progress] = '1024/1024' @blob.properties[:copy_status_description] = 'finish' @blob end @service.stub :get_blob_properties, multiple_values do @service.stub :sleep, ->(delay) {} do assert @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status) end end end def test_wait_blob_copy_operation_to_finish_with_copy_finished_success copy_id = nil copy_status = 'success' @service.stub :get_blob_properties, @blob do assert @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status) end end def test_wait_blob_copy_operation_to_finish_with_copy_id_is_nil copy_id = nil copy_status = 'pending' @service.stub :get_blob_properties, @blob do assert @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status) end end def test_wait_blob_copy_operation_to_finish_with_copy_id_not_match_exception copy_id = 'copy_id' copy_status = 'pending' @service.stub :get_blob_properties, @blob do @service.stub :delete_blob, true do assert_raises(RuntimeError) do @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status) end end end end def test_wait_blob_copy_operation_to_finish_with_timeout_exception copy_id = @blob.properties[:copy_id] copy_status = 'pending' i = 0 multiple_values = lambda do |*| i += 1 if i == 1 @blob.properties[:copy_status] = copy_status @blob.properties[:copy_progress] = '0/1024' @blob.properties[:copy_status_description] = 'in progress' return @blob end @blob.properties[:copy_status] = copy_status @blob.properties[:copy_progress] = '0/1024' @blob.properties[:copy_status_description] = 'in progress' @blob end stubbed_times = [ Time.now, Time.now + 5 ] @service.stub :get_blob_properties, multiple_values do Time.stub :new, -> { stubbed_times.shift } do @service.stub :delete_blob, true do assert_raises(Timeout::Error) do @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status, 2) end end end end end def test_wait_blob_copy_operation_to_finish_with_fail_exception copy_id = @blob.properties[:copy_id] copy_status = 'pending' @blob.properties[:copy_status] = 'failed' @service.stub :get_blob_properties, @blob do @service.stub :delete_blob, true do assert_raises(RuntimeError) do @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status) end end end end def test_wait_blob_copy_operation_to_finish_with_fail_when_delete_blob_http_exception copy_id = @blob.properties[:copy_id] copy_status = 'pending' @blob.properties[:copy_status] = 'failed' http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @service.stub :get_blob_properties, @blob do @service.stub :delete_blob, http_exception do assert_raises(RuntimeError) do @service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', copy_id, copy_status) end end end end def test_wait_blob_copy_operation_to_finish_mock assert @mock_service.wait_blob_copy_operation_to_finish('test_container', 'test_blob', 'copy_id', 'pending') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_check_container_exists.rb0000644000004100000410000000117114615741124027732 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestCheckContainerExists < Minitest::Test # This class posesses the test cases for the requests of checking container exists. def setup @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @container = ApiStub::Requests::Storage::Directory.container end def test_check_container_exists_success @blob_client.stub :get_container_properties, @container do assert_equal @service.check_container_exists('test_container'), true end end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_compare_container_blobs.rb0000644000004100000410000000245514615741124030073 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestCompareContainerBlobs < Minitest::Test # This class posesses the test cases for the requests of comparing blobs. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @blob_list = ApiStub::Requests::Storage::File.blob_list end def test_compare_container_blobs_success @service.stub :get_identical_blobs_from_containers, @blob_list do assert_equal @blob_list, @service.compare_container_blobs('test_container1', 'test_container2') end end def test_compare_container_blobs_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @service.stub :get_identical_blobs_from_containers, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.compare_container_blobs('test_container1', 'test_container2') end end end def test_compare_container_blobs_mock assert_equal @blob_list, @mock_service.compare_container_blobs('test_container1', 'test_container2') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_blob_url.rb0000644000004100000410000000600114615741124025650 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestGetBlobUrl < Minitest::Test # This class posesses the test cases for the requests of Blob service. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! end def test_get_blob_url_success service = Fog::AzureRM::Storage.new(storage_account_credentials) blob_client = service.instance_variable_get(:@blob_client) mock_generate_uri = Minitest::Mock.new url = ApiStub::Requests::Storage::File.blob_https_url 2.times do mock_generate_uri.expect(:call, URI.parse(url), ['test_container/test_blob', {}, { encode: true }]) end blob_client.stub :generate_uri, mock_generate_uri do assert_equal url, service.get_blob_url('test_container', 'test_blob') options = { scheme: 'http' } assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options) end end def test_get_blob_url_for_china_success china_storage_account_credentials = storage_account_credentials.merge(environment: Fog::AzureRM::ENVIRONMENT_AZURE_CHINA_CLOUD) service = Fog::AzureRM::Storage.new(china_storage_account_credentials) url = ApiStub::Requests::Storage::File.blob_https_url(Fog::AzureRM::ENVIRONMENT_AZURE_CHINA_CLOUD) assert_equal url, service.get_blob_url('test_container', 'test_blob') options = { scheme: 'http' } assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options) end def test_get_blob_url_for_us_success us_storage_account_credentials = storage_account_credentials.merge(environment: Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT) service = Fog::AzureRM::Storage.new(us_storage_account_credentials) url = ApiStub::Requests::Storage::File.blob_https_url(Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT) assert_equal url, service.get_blob_url('test_container', 'test_blob') options = { scheme: 'http' } assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options) end def test_get_blob_url_for_german_success german_storage_account_credentials = storage_account_credentials.merge(environment: Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD) service = Fog::AzureRM::Storage.new(german_storage_account_credentials) url = ApiStub::Requests::Storage::File.blob_https_url(Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD) assert_equal url, service.get_blob_url('test_container', 'test_blob') options = { scheme: 'http' } assert_equal url.gsub('https:', 'http:'), service.get_blob_url('test_container', 'test_blob', options) end def test_get_blob_url_mock url = ApiStub::Requests::Storage::File.blob_https_url assert_equal url, @mock_service.get_blob_url('test_container', 'test_blob') options = { scheme: 'http' } http_url = url.gsub('https:', 'http:') assert_equal http_url, @mock_service.get_blob_url('test_container', 'test_blob', options) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_delete_container.rb0000644000004100000410000000264014615741124026522 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestDeleteContainer < Minitest::Test # This class posesses the test cases for the requests of deleting storage containers. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @mocked_not_found_response = mocked_storage_http_not_found_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_delete_container_success @blob_client.stub :delete_container, true do assert @service.delete_container('test_container') end end def test_delete_container_not_found_success http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_not_found_response) } @blob_client.stub :delete_container, http_exception do assert @service.delete_container('test_container') end end def test_delete_blob_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :delete_container, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.delete_container('test_container') end end end def test_delete_container_mock assert @mock_service.delete_container('test_container') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_delete_blob_https_url.rb0000644000004100000410000000234014615741124027557 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestDeleteBlobHttpsUrl < Minitest::Test # This class posesses the test cases for the requests of Blob service. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @service = Fog::AzureRM::Storage.new(storage_account_credentials) @signature_client = @service.send(:signature_client, Minitest::Mock.new) @url = ApiStub::Requests::Storage::File.blob_https_url @token = ApiStub::Requests::Storage::File.blob_url_token end def test_delete_blob_http_urls_success @signature_client.stub :generate_service_sas_token, @token do assert_equal "#{@url}?#{@token}", @service.delete_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600) assert_equal "#{@url}?#{@token}", @service.delete_object_url('test_container', 'test_blob', Time.now.utc + 3600) end end def test_delete_blob_https_url_mock assert_equal "#{@url}?#{@token}", @mock_service.delete_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600) assert_equal "#{@url}?#{@token}", @mock_service.delete_object_url('test_container', 'test_blob', Time.now.utc + 3600) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_container_acl.rb0000644000004100000410000000245414615741124026661 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestGetContainerAcl < Minitest::Test # This class posesses the test cases for the requests of getting storage container acl. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @raw_container_acl = ApiStub::Requests::Storage::Directory.raw_container_acl @container_acl = ApiStub::Requests::Storage::Directory.container_acl end def test_get_container_acl_success @blob_client.stub :get_container_acl, @raw_container_acl do assert_equal @container_acl, @service.get_container_acl('test_container') end end def test_get_container_acl_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :get_container_acl, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.get_container_acl('test_container') end end end def test_get_container_acl_mock assert_equal @container_acl, @mock_service.get_container_acl('test_container') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_put_container_metadata.rb0000644000004100000410000000234314615741124027730 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestPutContainerMetadata < Minitest::Test # This class posesses the test cases for the requests of container service. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @metadata = ApiStub::Requests::Storage::Directory.container_metadata end def test_put_container_metadata_success @blob_client.stub :set_container_metadata, true do assert @service.put_container_metadata('test_container', @metadata) end end def test_put_container_metadata_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :set_container_metadata, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.put_container_metadata('test_container', @metadata) end end end def test_put_container_metadata_mock assert @mock_service.put_container_metadata('test_container', @metadata) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_blob_properties.rb0000644000004100000410000000321114615741124027242 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestGetBlobProperties < Minitest::Test # This class posesses the test cases for the requests of getting storage blob properties. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @blob = ApiStub::Requests::Storage::File.blob end def test_get_blob_properties_success @blob_client.stub :get_blob_properties, @blob do assert_equal @blob, @service.get_blob_properties('test_container', 'test_blob') end end def test_get_blob_properties_not_found exception = ->(*) { raise StandardError.new('Not found(404). Not exist') } @blob_client.stub :get_blob_properties, exception do assert_raises('NotFound') do @service.get_blob_properties('test_container', 'test_blob') end end end def test_get_blob_properties_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :get_blob_properties, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.get_blob_properties('test_container', 'test_blob') end end end def test_get_blob_properties_mock mock_blob_properties = @mock_service.get_blob_properties('test_container', 'test_blob') assert_equal @blob.name, mock_blob_properties.name assert_equal @blob.properties, mock_blob_properties.properties end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_release_blob_lease.rb0000644000004100000410000000223514615741124027005 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestReleaseBlobLease < Minitest::Test # This class posesses the test cases for the requests of releasing blob lease. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_release_blob_lease_success @blob_client.stub :release_blob_lease, true do assert @service.release_blob_lease('test_container', 'test_blob', 'lease_id') end end def test_release_blob_lease_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :release_blob_lease, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.release_blob_lease('test_container', 'test_blob', 'lease_id') end end end def test_release_blob_lease_mock assert @mock_service.release_blob_lease('test_container', 'test_blob', 'lease_id') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_delete_blob.rb0000644000004100000410000000263014615741124025455 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestDeleteBlob < Minitest::Test # This class posesses the test cases for the requests of deleting storage blobs. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @mocked_not_found_response = mocked_storage_http_not_found_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_delete_blob_success @blob_client.stub :delete_blob, true do assert @service.delete_blob('test_container', 'test_blob') end end def test_delete_blob_with_not_found_success http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_not_found_response) } @blob_client.stub :delete_blob, http_exception do assert @service.delete_blob('test_container', 'test_blob') end end def test_delete_blob_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :delete_blob, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.delete_blob('test_container', 'test_blob') end end end def test_delete_blob_mock assert @mock_service.delete_blob('test_container', 'test_blob') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_put_blob_http_url.rb0000644000004100000410000000241114615741124026741 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestPutBlobHttpUrl < Minitest::Test # This class posesses the test cases for the requests of Blob service. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @service = Fog::AzureRM::Storage.new(storage_account_credentials) @signature_client = @service.send(:signature_client, Minitest::Mock.new) @url = ApiStub::Requests::Storage::File.blob_https_url.gsub('https:', 'http:') @token = ApiStub::Requests::Storage::File.blob_url_token end def test_put_blob_http_urls_success @signature_client.stub :generate_service_sas_token, @token do assert_equal "#{@url}?#{@token}", @service.put_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600) end end def test_put_url_https_in_container_and_blob_names uri = URI.parse(@service.put_blob_http_url('https://container', 'https://blob', Time.now.utc + 3600)) assert_equal 'http', uri.scheme assert_equal '/https://container/https://blob', CGI.unescape(uri.path) end def test_put_blob_http_url_mock assert_equal "#{@url}?#{@token}", @mock_service.put_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_copy_blob_from_uri.rb0000644000004100000410000000253014615741124027066 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestCopyBlobFromUri < Minitest::Test # This class posesses the test cases for the requests of copying blobs from uri. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @blob_copy_result = ApiStub::Requests::Storage::File.blob_copy_result end def test_copy_blob_from_uri_success @blob_client.stub :copy_blob_from_uri, @blob_copy_result do assert_equal @blob_copy_result, @service.copy_blob_from_uri('destination_container', 'destination_blob', 'source_uri') end end def test_copy_blob_from_uri_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :copy_blob_from_uri, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.copy_blob_from_uri('destination_container', 'destination_blob', 'source_uri') end end end def test_copy_blob_from_uri_mock assert_equal @blob_copy_result, @mock_service.copy_blob_from_uri('destination_container', 'destination_blob', 'source_uri') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_list_containers.rb0000644000004100000410000000337614615741124026425 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestListContainers < Minitest::Test # This class posesses the test cases for the requests of listing storage containers. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @containers = ApiStub::Requests::Storage::Directory.container_list @containers1 = Azure::Storage::Common::Service::EnumerationResults.new @containers1.continuation_token = 'marker' @containers1.push(@containers[0]) @containers1.push(@containers[1]) @containers2 = Azure::Storage::Common::Service::EnumerationResults.new @containers2.push(@containers[2]) end def test_list_containers_success multiple_values = lambda do |options| return @containers2 if options[:marker] == 'marker' return @containers1 end @blob_client.stub :list_containers, multiple_values do assert_equal @containers, @service.list_containers end end def test_list_containers_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :list_containers, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.list_containers end end end def test_list_containers_exception @blob_client.stub :list_containers, 'exception' do assert_raises(RuntimeError) do @service.list_containers end end end def test_list_containers_mock assert_equal @containers, @mock_service.list_containers end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_release_container_lease.rb0000644000004100000410000000225514615741124030053 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestReleaseContainerLease < Minitest::Test # This class posesses the test cases for the requests of releasing container lease. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_release_container_lease_success @blob_client.stub :release_container_lease, true do assert @service.release_container_lease('test_container', 'lease_id') end end def test_release_container_lease_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :release_container_lease, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.release_container_lease('test_container', 'lease_id') end end end def test_release_container_lease_mock assert @mock_service.release_container_lease('test_container', 'lease_id') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_put_blob_pages.rb0000644000004100000410000000220514615741124026200 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestPutBlobPages < Minitest::Test # This class posesses the test cases for the requests of putting blob page. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_put_blob_pages_success @blob_client.stub :put_blob_pages, true do assert @service.put_blob_pages('test_container', 'test_blob', 0, 1024, 'data') end end def test_put_blob_pages_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :put_blob_pages, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.put_blob_pages('test_container', 'test_blob', 0, 1024, 'data') end end end def test_put_blob_pages_mock assert @mock_service.put_blob_pages('test_container', 'test_blob', 0, 1024, 'data') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_object.rb0000644000004100000410000000214014615741124025316 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestGetObject < Minitest::Test # This class posesses the test cases for the requests of getting storage blob. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @raw_cloud_blob = storage_blob @blob = ApiStub::Requests::Storage::File.blob_as_hash @blob_with_content = @blob.merge(body: 'content') end def test_get_object_success @blob_client.stub :get_blob, @blob_with_content do assert_equal @blob_with_content, @service.get_object('test_container', 'test_blob') end end def test_get_object_not_found exception = ->(*) { raise StandardError.new('Not found(404). Not exist') } @blob_client.stub :get_blob, exception do assert_raises('NotFound') do @service.get_object('test_container', 'test_blob') end end end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_container_url.rb0000644000004100000410000000175714615741124026731 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestGetContainerUrl < Minitest::Test # This class posesses the test cases for the requests of getting storage container url. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @service = Fog::AzureRM::Storage.new(storage_account_credentials) @url = ApiStub::Requests::Storage::Directory.container_https_url end def test_get_container_url_success assert_equal @url, @service.get_container_url('test_container') options = { scheme: 'http' } assert_equal @url.gsub('https:', 'http:'), @service.get_container_url('test_container', options) end def test_get_container_url_mock assert_equal @url, @mock_service.get_container_url('test_container') options = { scheme: 'http' } http_url = @url.gsub('https:', 'http:') assert_equal http_url, @mock_service.get_container_url('test_container', options) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_acquire_blob_lease.rb0000644000004100000410000000236214615741124027017 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestAcquireBlobLease < Minitest::Test # This class posesses the test cases for the requests of acquire blob lease. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @blob_lease_id = ApiStub::Requests::Storage::File.blob_lease_id end def test_acquire_blob_lease_success @blob_client.stub :acquire_blob_lease, @blob_lease_id do assert_equal @blob_lease_id, @service.acquire_blob_lease('test_container', 'test_blob') end end def test_acquire_blob_lease_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :acquire_blob_lease, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.acquire_blob_lease('test_container', 'test_blob') end end end def test_acquire_blob_lease_mock assert_equal @blob_lease_id, @mock_service.acquire_blob_lease('test_container', 'test_blob') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_blob_https_url.rb0000644000004100000410000001607614615741124027107 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestGetBlobHttpsUrl < Minitest::Test HOUR = 3600 DAY = 24 * HOUR WEEK = 7 * DAY # This class posesses the test cases for the requests of Blob service. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @signature_client = @service.send(:signature_client, Minitest::Mock.new) @url = ApiStub::Requests::Storage::File.blob_https_url @token = ApiStub::Requests::Storage::File.blob_url_token end def test_get_blob_https_url_success mock_generate_uri = Minitest::Mock.new 2.times do mock_generate_uri.expect(:call, URI.parse(@url), ['test_container/test_blob', {}, { encode: true }]) end @blob_client.stub :generate_uri, mock_generate_uri do @signature_client.stub :generate_service_sas_token, @token do assert_equal "#{@url}?#{@token}", @service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600) assert_equal "#{@url}?#{@token}", @service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600) end end end def test_get_blob_https_url_with_content_disposition mock_generate_uri = Minitest::Mock.new mock_generate_service_token = Minitest::Mock.new url_params = { content_disposition: 'attachment' } 2.times do mock_generate_uri.expect(:call, URI.parse(@url), ['test_container/test_blob', {}, { encode: true }]) mock_generate_service_token.expect(:call, @token) do |_relative_path, params| params[:service] == 'b' && params[:resource] == 'b' && params[:permissions] == 'r' && params[:protocol] == 'https' && params[:content_disposition] == url_params[:content_disposition] end end @blob_client.stub :generate_uri, mock_generate_uri do @signature_client.stub :generate_service_sas_token, mock_generate_service_token do assert_equal "#{@url}?#{@token}", @service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600, url_params) assert_equal "#{@url}?#{@token}", @service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600, url_params) end end end def test_get_url_remove_trailing_periods_from_path_segments mock_generate_uri = Minitest::Mock.new mock_generate_service_token = Minitest::Mock.new 2.times do mock_generate_uri.expect(:call, URI.parse(@url), ['.test0/..test1/...test2', {}, { encode: true }]) mock_generate_service_token.expect(:call, @token) do |relative_path, _| relative_path == '.test0/..test1/...test2' end end @blob_client.stub :generate_uri, mock_generate_uri do @signature_client.stub :generate_service_sas_token, mock_generate_service_token do assert_equal "#{@url}?#{@token}", @service.get_blob_https_url('.test0.', '..test1../...test2...', Time.now.utc + 3600) assert_equal "#{@url}?#{@token}", @service.get_object_url('.test0.', '..test1../...test2...', Time.now.utc + 3600) end end end def test_get_blob_https_url_with_endpoint_success service = Fog::AzureRM::Storage.new(storage_account_credentials_with_endpoint) signature_client = service.send(:signature_client, Minitest::Mock.new) url = 'http://localhost:10000/mockaccount/test_container/test_blob' token = ApiStub::Requests::Storage::File.blob_url_token signature_client.stub :generate_service_sas_token, token do assert_equal "#{url}?#{token}", service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600) assert_equal "#{url}?#{token}", service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600) end end def test_get_blob_https_url_with_domain_success service = Fog::AzureRM::Storage.new(storage_account_credentials_with_domain) signature_client = service.send(:signature_client, Minitest::Mock.new) url = 'https://mockaccount.test.example.com/test_container/test_blob' token = ApiStub::Requests::Storage::File.blob_url_token signature_client.stub :generate_service_sas_token, token do assert_equal "#{url}?#{token}", service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600) assert_equal "#{url}?#{token}", service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600) end end def test_get_blob_https_url_with_token_signer_success service = Fog::AzureRM::Storage.new(storage_account_credentials_with_token_signer) blob_client = service.instance_variable_get(:@blob_client) ref_time = Time.now stubbed_times = [] requested_expiries = [] expected_user_delegation_key_starts = [] # initial request stubbed_times << ref_time requested_expiries << stubbed_times.last + 1 * HOUR expected_user_delegation_key_starts << stubbed_times.last # second request during expiry window stubbed_times << ref_time + 5.5 * DAY requested_expiries << stubbed_times.last + 1 * DAY # no additonal expected_user_delegation_key_starts # request extending past current expiry stubbed_times << ref_time + 6.5 * DAY requested_expiries << stubbed_times.last + 1 * DAY expected_user_delegation_key_starts << stubbed_times.last # second request within new expiry stubbed_times << ref_time + 10.5 * DAY requested_expiries << stubbed_times.last + 1 * DAY # no additonal expected_user_delegation_key_starts user_delegation_key_starts = [] mock_user_delegation_key = lambda do |start, expiry| user_delegation_key_starts << start assert_equal 1 * WEEK, expiry - start key = Azure::Storage::Common::Service::UserDelegationKey.new key.signed_start = "start-#{start.to_i}" key.signed_expiry = 'test-expiry' key.value = 'delegation-key' key end mock_new_signer = lambda do |token| assert_equal 'delegation-key', token mock_token_signer end requested_expiries.each do mock_token_signer.expect(:sign, 'test-signature', [/\Ar\n.+test_blob\n.+\nstart-\d+\ntest-expiry/m]) end Time.stub :now, -> { stubbed_times.first } do blob_client.stub :get_user_delegation_key, mock_user_delegation_key do Azure::Core::Auth::Signer.stub :new, mock_new_signer do while (requested_expiry = requested_expiries.shift) url = service.get_blob_https_url('test_container', 'test_blob', requested_expiry) assert_match(/^#{Regexp.escape @url}.+&skt=start-#{user_delegation_key_starts.last.to_i}&.+&sig=test-signature/, url) stubbed_times.shift end end end end assert_equal expected_user_delegation_key_starts, user_delegation_key_starts end def test_get_blob_https_url_mock assert_equal "#{@url}?#{@token}", @mock_service.get_blob_https_url('test_container', 'test_blob', Time.now.utc + 3600) assert_equal "#{@url}?#{@token}", @mock_service.get_object_url('test_container', 'test_blob', Time.now.utc + 3600) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_copy_blob.rb0000644000004100000410000000330514615741124025165 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestCopyBlob < Minitest::Test # This class posesses the test cases for the requests of copying blobs. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @blob_copy_result = ApiStub::Requests::Storage::File.blob_copy_result end def test_copy_blob_success @blob_client.stub :copy_blob, @blob_copy_result do assert_equal @blob_copy_result, @service.copy_blob('destination_container', 'destination_blob', 'source_container', 'source_blob') assert_equal @blob_copy_result, @service.copy_object('destination_container', 'destination_blob', 'source_container', 'source_blob') end end def test_copy_blob_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :copy_blob, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.copy_blob('destination_container', 'destination_blob', 'source_container', 'source_blob') @service.copy_object('destination_container', 'destination_blob', 'source_container', 'source_blob') end end end def test_copy_blob_mock assert_equal @blob_copy_result, @mock_service.copy_blob('destination_container', 'destination_blob', 'source_container', 'source_blob') assert_equal @blob_copy_result, @mock_service.copy_object('destination_container', 'destination_blob', 'source_container', 'source_blob') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_create_container.rb0000644000004100000410000000227114615741124026523 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Container Class class TestCreateContainer < Minitest::Test # This class posesses the test cases for the requests of creating storage containers. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @container = ApiStub::Requests::Storage::Directory.container end def test_create_container_success @blob_client.stub :create_container, @container do assert_equal @container, @service.create_container('test_container') end end def test_create_container_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :create_container, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.create_container('test_container') end end end def test_create_container_mock assert_equal @container, @mock_service.create_container('test_container') end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_blob_http_url.rb0000644000004100000410000000563214615741124026720 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestGetBlobHttpUrl < Minitest::Test # This class posesses the test cases for the requests of Blob service. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @signature_client = @service.send(:signature_client, Minitest::Mock.new) @url = ApiStub::Requests::Storage::File.blob_https_url.gsub('https:', 'http:') @token = ApiStub::Requests::Storage::File.blob_url_token end def test_get_blob_http_url_success @signature_client.stub :generate_service_sas_token, @token do assert_equal "#{@url}?#{@token}", @service.get_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600) end end def test_get_blob_http_url_with_content_disposition mock_generate_uri = Minitest::Mock.new mock_generate_service_token = Minitest::Mock.new url_params = { content_disposition: 'attachment' } mock_generate_uri.expect(:call, URI.parse(@url), ['test_container/test_blob', {}, { encode: true }]) mock_generate_service_token.expect(:call, @token) do |_relative_path, params| params[:service] == 'b' && params[:resource] == 'b' && params[:permissions] == 'r' && params[:protocol].nil? && params[:content_disposition] == url_params[:content_disposition] end @blob_client.stub :generate_uri, mock_generate_uri do @signature_client.stub :generate_service_sas_token, mock_generate_service_token do assert_equal "#{@url}?#{@token}", @service.get_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600, url_params) end end end def test_get_url_remove_trailing_periods_from_path_segments mock_generate_uri = Minitest::Mock.new mock_generate_service_token = Minitest::Mock.new mock_generate_uri.expect(:call, URI.parse(@url), ['.test0/..test1/...test2', {}, { encode: true }]) mock_generate_service_token.expect(:call, @token) do |relative_path, _| relative_path == '.test0/..test1/...test2' end @blob_client.stub :generate_uri, mock_generate_uri do @signature_client.stub :generate_service_sas_token, mock_generate_service_token do assert_equal "#{@url}?#{@token}", @service.get_blob_http_url('.test0.', '..test1../...test2...', Time.now.utc + 3600) end end end def test_get_url_https_in_container_and_blob_names uri = URI.parse(@service.get_blob_http_url('https://container', 'https://blob', Time.now.utc + 3600)) assert_equal 'http', uri.scheme assert_equal '/https://container/https://blob', CGI.unescape(uri.path) end def test_get_blob_http_url_mock assert_equal "#{@url}?#{@token}", @mock_service.get_blob_http_url('test_container', 'test_blob', Time.now.utc + 3600) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_put_blob_metadata.rb0000644000004100000410000000232214615741124026661 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestPutBlobMetadata < Minitest::Test # This class posesses the test cases for the requests of setting blob metadata. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @metadata = ApiStub::Requests::Storage::File.blob_metadata end def test_put_blob_metadata_success @blob_client.stub :set_blob_metadata, true do assert @service.put_blob_metadata('test_container', 'test_blob', @metadata) end end def test_put_blob_metadata_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :set_blob_metadata, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.put_blob_metadata('test_container', 'test_blob', @metadata) end end end def test_put_blob_metadata_mock assert @mock_service.put_blob_metadata('test_container', 'test_blob', @metadata) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_create_page_blob.rb0000644000004100000410000000220314615741124026446 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestCreatePageBlob < Minitest::Test # This class posesses the test cases for the requests of creating storage page blobs. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) end def test_create_page_blob_success @blob_client.stub :create_page_blob, true do assert @service.create_page_blob('test_container', 'test_blob', 1_024) end end def test_create_page_blob_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :create_page_blob, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.create_page_blob('test_container', 'test_blob', 1_024) end end end def test_create_page_blob_mock assert @mock_service.create_page_blob('test_container', 'test_blob', 1_024) end end gitlab-fog-azure-rm-1.9.1/test/requests/storage/test_get_blob.rb0000644000004100000410000001046014615741124024772 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Storage Blob Class class TestGetBlob < Minitest::Test # This class posesses the test cases for the requests of getting storage blob. def setup Fog.mock! @mock_service = Fog::AzureRM::Storage.new(storage_account_credentials) Fog.unmock! @mocked_response = mocked_storage_http_error @service = Fog::AzureRM::Storage.new(storage_account_credentials) @blob_client = @service.instance_variable_get(:@blob_client) @raw_cloud_blob = storage_blob @blob = ApiStub::Requests::Storage::File.blob_as_hash @blob_with_content = [ @blob, 'content' ] end def test_get_blob_success @blob_client.stub :get_blob, @blob_with_content do assert_equal @blob_with_content, @service.get_blob('test_container', 'test_blob') end end def test_get_blob_not_found exception = ->(*) { raise StandardError.new('Not found(404). Not exist') } @blob_client.stub :get_blob, exception do assert_raises('NotFound') do @service.get_blob('test_container', 'test_blob') end end end def test_get_blob_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :get_blob, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.get_blob('test_container', 'test_blob') end end end def test_get_blob_mock assert_equal @blob_with_content, @mock_service.get_blob('test_container', 'test_blob') end def test_get_blob_with_block_given_success data = '' @blob_client.stub :get_blob_properties, @raw_cloud_blob do @blob_client.stub :get_blob, @blob_with_content do @service.get_blob('test_container', 'test_blob') do |chunk, _remaining_bytes, _total_bytes| data << chunk end assert_equal @blob_with_content[1], data end end end def test_get_blob_with_block_given_with_emtpy_blob_success data = '' empty_raw_cloud_blob = @raw_cloud_blob empty_raw_cloud_blob.properties[:content_length] = 0 empty_blob_with_content = [ @blob, '' ] @blob_client.stub :get_blob_properties, empty_raw_cloud_blob do @blob_client.stub :get_blob, empty_blob_with_content do @service.get_blob('test_container', 'test_blob') do |chunk, _remaining_bytes, _total_bytes| data << chunk end assert data.empty? end end end def test_get_blob_with_block_given_with_emtpy_range_success data = '' options = { start_range: 1024, end_range: 1024 } @blob_client.stub :get_blob_properties, @raw_cloud_blob do @blob_client.stub :get_blob, @blob_with_content do @service.get_blob('test_container', 'test_blob', options) do |chunk, _remaining_bytes, _total_bytes| data << chunk end assert data.empty? end end end def test_get_blob_with_block_given_invalid_options options = { start_range: 1024, end_range: 0 } @blob_client.stub :get_blob_properties, @raw_cloud_blob do @service.stub :get_blob_properties, @blob_with_content[0] do assert_raises(ArgumentError) do @service.get_blob('test_container', 'test_blob', options) do |*chunk| end end end end end def test_get_blob_with_block_given_not_exist http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :get_blob_properties, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.get_blob('test_container', 'test_blob') do |*chunk| end end end end def test_get_blob_with_block_given_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @blob_client.stub :get_blob_properties, @raw_cloud_blob do @blob_client.stub :get_blob, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @service.get_blob('test_container', 'test_blob') do |*chunk| end end end end end def test_get_blob_with_block_given_mock data = '' @mock_service.get_blob('test_container', 'test_blob') do |chunk, _remaining_bytes, _total_bytes| data << chunk end assert_equal @blob_with_content[1], data end end gitlab-fog-azure-rm-1.9.1/test/integration/0000755000004100000410000000000014615741124020634 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/integration/container.rb0000644000004100000410000001714414615741124023152 0ustar www-datawww-datarequire 'fog/azurerm' require 'yaml' ######################################################################################################################## ###################### Services object required by all actions ###################### ###################### Keep it Uncommented! ###################### ######################################################################################################################## azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) ######################################################################################################################## ###################### Resource names ##################### ######################################################################################################################## time = Time.now.to_i container_name = "con#{time}" test_container_name = "tcon#{time}" ######################################################################################################################## ###################### Prerequisites ###################### ######################################################################################################################## begin storage_data = Fog::AzureRM::Storage.new( azure_storage_account_name: azure_credentials['azure_storage_account_name'], azure_storage_access_key: azure_credentials['azure_storage_access_key'], azure_storage_endpoint: azure_credentials['azure_storage_endpoint'], environment: azure_credentials['environment'] ) ######################################################################################################################## ###################### Check Container Exists ###################### ######################################################################################################################## flag = storage_data.directories.check_container_exists(container_name) puts "Container doesn't exist." unless flag ######################################################################################################################## ###################### Create Container ###################### ######################################################################################################################## container = storage_data.directories.create( key: container_name ) puts "Created container: #{container.key}" container2 = storage_data.directories.create( key: test_container_name, public: true ) puts "Created second container: #{container.key}" ######################################################################################################################## ###################### List containers ###################### ######################################################################################################################## containers = storage_data.directories.all puts 'List containers:' containers.each do |a_container| puts a_container.key end ######################################################################################################################## ###################### Get container acl ###################### ######################################################################################################################## container = storage_data.directories.get(container_name, max_results: 1) puts "Get container: #{container.key}" puts "Get container access control list: #{container.acl}" ######################################################################################################################## ###################### Update Container ###################### ######################################################################################################################## container.acl = 'container' container.metadata = { 'owner' => 'azure' } container.save(is_create: false) puts 'Updated container' ######################################################################################################################## ###################### Get container acl ###################### ######################################################################################################################## puts "Get updated container access control list: #{container.acl}" ######################################################################################################################## ###################### Get container metadata ###################### ######################################################################################################################## puts "Get container metadata: #{container.metadata}" ######################################################################################################################## ###################### Get container public https url ###################### ######################################################################################################################## puts "Get container public url: #{container.public_url}" ######################################################################################################################## ###################### Get container public http url ###################### ######################################################################################################################## puts "Get container public url having scheme http: #{container.public_url(scheme: 'http')}" ######################################################################################################################## ###################### Lease Container ###################### ######################################################################################################################## lease_id_container = storage_data.acquire_container_lease(container_name) Fog::Logger.debug lease_id_container puts 'Leased Container' ######################################################################################################################## ###################### Release Leased Container ###################### ######################################################################################################################## storage_data.release_container_lease(container_name, lease_id_container) puts 'Release Leased Container' ######################################################################################################################## ###################### Deleted Container ###################### ######################################################################################################################## puts "Deleted container: #{container.destroy}" rescue => ex puts "Integration Test for container is failing: #{ex.inspect}\n#{ex.backtrace.join("\n")}" raise ensure container2&.destroy end gitlab-fog-azure-rm-1.9.1/test/integration/blob.rb0000644000004100000410000003620414615741124022104 0ustar www-datawww-datarequire 'fog/azurerm' require 'yaml' ######################################################################################################################## ###################### Services object required by all actions ###################### ###################### Keep it Uncommented! ###################### ######################################################################################################################## azure_credentials = YAML.load_file(File.expand_path('credentials/azure.yml', __dir__)) ######################################################################################################################## ###################### Resource names ##################### ######################################################################################################################## time = Time.now.to_i container_name = "con#{time}" test_container_name = "tcon#{time}" ######################################################################################################################## ###################### Prerequisites ###################### ######################################################################################################################## begin storage_data = Fog::Storage.new( provider: 'AzureRM', azure_storage_account_name: azure_credentials['azure_storage_account_name'], azure_storage_access_key: azure_credentials['azure_storage_access_key'], azure_storage_endpoint: azure_credentials['azure_storage_endpoint'], environment: azure_credentials['environment'] ) scheme = URI.parse(azure_credentials.fetch('azure_storage_endpoint', 'https:')).scheme ######################################################################################################################## ###################### Create Container ###################### ######################################################################################################################## test_container1 = storage_data.directories.create( key: container_name, public: true ) test_container2 = storage_data.directories.create( key: test_container_name, public: false ) ######################################################################################################################## ###################### Get container ###################### ######################################################################################################################## container = storage_data.directories.get(container_name) test_container = storage_data.directories.get(test_container_name) ######################################################################################################################## ###################### Create a small block blob ###################### ######################################################################################################################## small_blob_name = 'small_test_file.dat' content = Array.new(1024 * 1024) { [*'0'..'9', *'a'..'z'].sample }.join options = { key: small_blob_name, body: content } blob = container.files.create(options) puts "Created small block blob: #{blob.key}" ######################################################################################################################## ###################### Create a large block blob ###################### ######################################################################################################################## large_blob_name = 'large_test_file.dat' begin large_blob_file_name = '/tmp/large_test_file.dat' File.open(large_blob_file_name, 'w') do |large_file| 33.times do large_file.puts(content) end end File.open(large_blob_file_name) do |file| options = { key: large_blob_name, body: file } blob = container.files.create(options) puts "Created large block blob: #{blob.key}" end ensure File.delete(large_blob_file_name) if File.exist?(large_blob_file_name) end ######################################################################################################################## ###################### Create a small page blob ###################### ######################################################################################################################## small_page_blob_name = 'small_test_file.vhd' content = Array.new(1024 * 1024 + 512) { [*'0'..'9', *'a'..'z'].sample }.join options = { key: small_page_blob_name, body: content, blob_type: 'PageBlob' } blob = container.files.create(options) puts "Created small page blob: #{blob.key}" ######################################################################################################################## ###################### Create a large page blob ###################### ######################################################################################################################## begin large_page_blob_file_name = '/tmp/large_test_file.vhd' large_page_blob_name = 'large_test_file.vhd' File.open(large_page_blob_file_name, 'w') do |large_file| content = Array.new(1024 * 1024) { [*'0'..'9', *'a'..'z'].sample }.join 33.times do large_file.puts(content) end content = Array.new(512) { [*'0'..'9', *'a'..'z'].sample }.join large_file.puts(content) large_file.truncate(33 * 1024 * 1024 + 512) end File.open(large_page_blob_file_name) do |file| options = { key: large_page_blob_name, body: file, blob_type: 'PageBlob' } blob = container.files.create(options) puts "Created large page blob: #{blob.key}" end ensure File.delete(large_page_blob_file_name) if File.exist?(large_page_blob_file_name) end ######################################################################################################################## ###################### Copy Blob ######################## ######################################################################################################################## puts "Copy blob: #{container.files.head(small_blob_name).copy(test_container_name, small_blob_name)}" ######################################################################################################################## ###################### Get a public URL ###################### ######################################################################################################################## blob_uri = container.files.head(large_blob_name).public_url puts "Get blob public uri: #{blob_uri}" ######################################################################################################################## ###################### Copy Blob from URI ######################## ######################################################################################################################## copied_blob = test_container.files.new(key: 'small_blob_name') puts "Copy blob from uri: #{copied_blob.copy_from_uri(blob_uri)}" ######################################################################################################################## ###################### Update blob ###################### ######################################################################################################################## copied_blob.content_encoding = 'utf-8' copied_blob.metadata = { 'owner' => 'azure' } copied_blob.save(update_body: false) temp = test_container.files.head(small_blob_name) puts 'Updated blob' Fog::Logger.debug temp.content_encoding Fog::Logger.debug temp.metadata ######################################################################################################################## ###################### Compare Blob ##################### ######################################################################################################################## puts "Compare blobs: #{storage_data.compare_container_blobs(container_name, test_container_name)}" ######################################################################################################################## ###################### Blob Exist ##################### ######################################################################################################################## puts 'Blob exist' if container.files.head(small_blob_name) ######################################################################################################################## ###################### Blob Count in a Container ##################### ######################################################################################################################## puts "Blob count in a container: #{container.files.all.length}" ######################################################################################################################## ###################### List Blobs in a Container ##################### ######################################################################################################################## puts 'List blobs in a container:' container.files.each do |temp_file| puts temp_file.key end ######################################################################################################################## ###################### Download a small blob ###################### ######################################################################################################################## begin downloaded_file_name = '/tmp/downloaded_' + small_blob_name blob = container.files.get(small_blob_name) File.open(downloaded_file_name, 'wb') do |file| file.write(blob.body) end puts 'Downloaded small blob' ensure File.delete(downloaded_file_name) if File.exist?(downloaded_file_name) end ######################################################################################################################## ###################### Download a large blob ###################### ######################################################################################################################## begin downloaded_file_name = '/tmp/downloaded_' + large_blob_name File.open(downloaded_file_name, 'wb') do |file| container.files.get(large_blob_name) do |chunk, remaining_bytes, total_bytes| Fog::Logger.debug "remaining_bytes: #{remaining_bytes}, total_bytes: #{total_bytes}" file.write(chunk) end end puts 'Downloaded large blob' ensure File.delete(downloaded_file_name) if File.exist?(downloaded_file_name) end ######################################################################################################################## ###################### Get a https URL with expires ###################### ######################################################################################################################## test_blob = test_container.files.head(small_blob_name) puts "Get https URL with expires: #{test_blob.public?}, #{test_blob.url(Time.now + 3600)}" Fog::Logger.debug test_blob.public? Fog::Logger.debug test_blob.url(Time.now + 3600) ######################################################################################################################## ###################### Get a http URL with expires ###################### ######################################################################################################################## puts "Get a http URL with expires: #{test_blob.url(Time.now + 3600, scheme: 'http')}" ######################################################################################################################## ###################### Test generated GET and PUT URLs ###################### ######################################################################################################################## url_blob_name = 'url-test.txt' url_blob_content = 'Hello world.' get_url = storage_data.public_send("get_blob_#{scheme}_url", container_name, url_blob_name, Time.now + 3600) put_url = storage_data.public_send("put_blob_#{scheme}_url", container_name, url_blob_name, Time.now + 3600) response = Faraday.put(put_url, url_blob_content, 'x-ms-blob-type' => 'BlockBlob') raise unless response.success? puts 'Uploaded blob using PUT blob URL' response = Faraday.get(get_url) raise unless response.success? raise unless response.body == url_blob_content puts 'Downloaded blob using GET blob URL' ######################################################################################################################## ###################### Lease Blob ###################### ######################################################################################################################## lease_id_blob = storage_data.acquire_blob_lease(container_name, large_blob_name) puts 'Leased blob' ######################################################################################################################## ###################### Release Leased Blob ###################### ######################################################################################################################## storage_data.release_blob_lease(container_name, large_blob_name, lease_id_blob) puts 'Release Leased Blob' ######################################################################################################################## ###################### Delete Blob ###################### ######################################################################################################################## blob = container.files.head(large_blob_name) puts "Deleted blob: #{blob.destroy}" rescue => ex puts "Integration Test for blob is failing: #{ex.inspect}\n#{ex.backtrace.join("\n")}" raise ensure test_container1&.destroy test_container2&.destroy end gitlab-fog-azure-rm-1.9.1/test/integration/credentials/0000755000004100000410000000000014615741124023131 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/integration/credentials/azure.yml0000644000004100000410000000036614615741124025007 0ustar www-datawww-dataazure_storage_account_name: devstoreaccount1 azure_storage_access_key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw== azure_storage_endpoint: http://azurite:10000/devstoreaccount1 environment: AzureCloud gitlab-fog-azure-rm-1.9.1/test/integration/README.md0000644000004100000410000000074314615741124022117 0ustar www-datawww-data# Integration Tests To run Integration Tests, first enter the following information for your test storage account into **credentials\azure.yml** file: - `azure_storage_account_name` - `azure_storage_access_key` Then run **bundle exec ruby file_name.rb** to run integration test for a specific service e.g. For integration tests for blobs, run: **bundle exec ruby test/integration/blob.rb** Also make sure the **DEBUG** flag is set in your fog environment to see proper logging. gitlab-fog-azure-rm-1.9.1/test/test_helper.rb0000755000004100000410000001164414615741124021165 0ustar www-datawww-dataif ENV['COVERAGE'] require 'simplecov' SimpleCov.start do add_filter 'test' command_name 'Minitest' end end if ENV['CODECLIMATE_REPO_TOKEN'] require 'simplecov' SimpleCov.start do add_filter 'test' command_name 'Minitest' end end class TestRaiseLogger def write(message) raise message end def tty? false end end require 'fog/core/logger' Fog::Logger[:deprecation] = TestRaiseLogger.new Fog::Logger[:warning] = TestRaiseLogger.new require 'minitest/autorun' require 'azure/core/http/http_error' require 'azure/core/http/http_response' $LOAD_PATH.unshift(File.expand_path '../lib', __dir__) require File.expand_path '../lib/fog/azurerm', __dir__ require File.expand_path './api_stub', __dir__ def storage_account_credentials { azure_storage_account_name: 'mockaccount', azure_storage_access_key: 'YWNjZXNzLWtleQ==' } end def storage_account_credentials_with_endpoint storage_account_credentials.merge( { azure_storage_endpoint: 'http://localhost:10000/mockaccount' } ) end def storage_account_credentials_with_domain storage_account_credentials.merge( { azure_storage_domain: 'test.example.com' } ) end def storage_account_credentials_with_token_signer { azure_storage_account_name: 'mockaccount', azure_storage_token_signer: mock_token_signer } end def mock_token_signer @mock_token_signer ||= Minitest::Mock.new(Azure::Core::Auth::Signer.new('access-token')) end # Mock Class for Blob class MockBlob def initialize @properties = {} @metadata = {} yield self if block_given? end attr_accessor :name attr_accessor :snapshot attr_accessor :properties attr_accessor :metadata end # Mock Class for Response class MockResponse def initialize(code, body, headers) @status = code @body = body @headers = headers @headers.each do |k, v| @headers[k] = [v] unless v.respond_to? 'first' end end attr_accessor :status attr_accessor :body attr_accessor :headers end def mocked_storage_http_error mocked_net_response = MockResponse.new 'mocked_code', 'mocked_body', a: 'a', b: 'b' Azure::Core::Http::HttpResponse.new mocked_net_response, 'mocked_uri' end def mocked_storage_http_not_found_error mocked_net_response = MockResponse.new '404', 'mocked_body', a: 'a', b: 'b' Azure::Core::Http::HttpResponse.new mocked_net_response, 'mocked_uri' end def directory(service) Fog::AzureRM::Storage::Directory.new( key: 'test_container', acl: 'container', etag: '0x8D29C92176C8352', last_modified: Time.parse('Tue, 04 Aug 2015 06:01:08 GMT'), lease_duration: nil, lease_state: 'available', lease_status: 'unlocked', metadata: { 'key1' => 'value1', 'key2' => 'value2' }, service: service, collection: Fog::AzureRM::Storage::Directories.new(service: @service) ) end def file(service) Fog::AzureRM::Storage::File.new( key: 'test_blob', directory: directory(service), last_modified: Time.parse('Tue, 04 Aug 2015 06:01:08 GMT'), etag: '0x8D29C92176C8352', metadata: { 'key1' => 'value1', 'key2' => 'value2' }, lease_status: 'unlocked', lease_state: 'available', lease_duration: nil, content_length: 4_194_304, content_type: 'application/octet-stream', content_encoding: nil, content_language: nil, content_disposition: nil, content_md5: 'tXAohIyxuu/t94Lp/ujeRw==', cache_control: nil, sequence_number: 0, blob_type: 'BlockBlob', copy_id: '095adc3b-e277-4c3d-97e0-0abca881f60c', copy_status: 'success', copy_source: 'https://testaccount.blob.core.windows.net/testblob/4m?snapshot=2016-02-04T08%3A35%3A50.3157696Z', copy_progress: '4194304/4194304', copy_completion_time: 'Thu, 04 Feb 2016 08:35:52 GMT', copy_status_description: nil, accept_ranges: 0, service: service, collection: Fog::AzureRM::Storage::Files.new(service: @service, directory: directory(service)) ) end def storage_blob mock_blob = MockBlob.new mock_blob.name = 'test_blob' mock_blob.properties = { lease_status: 'unlocked', lease_state: 'available', lease_duration: nil, content_length: 4_194_304, content_type: 'application/octet-stream', content_encoding: nil, content_language: nil, content_disposition: nil, content_md5: 'tXAohIyxuu/t94Lp/ujeRw==', cache_control: nil, sequence_number: 0, blob_type: 'PageBlob', copy_id: '095adc3b-e277-4c3d-97e0-0abca881f60c', copy_status: 'success', copy_source: 'https://mockaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3157696Z', copy_progress: '4194304/4194304', copy_completion_time: 'Thu, 04 Feb 2016 08:35:52 GMT', copy_status_description: nil, accept_ranges: 0, last_modified: 'Tue, 04 Aug 2015 06:01:08 GMT', etag: '"0x8D29C92176C8352"' } mock_blob.metadata = { 'key1' => 'value1', 'key2' => 'value2' } mock_blob end gitlab-fog-azure-rm-1.9.1/test/api_stub/0000755000004100000410000000000014615741124020117 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/api_stub/requests/0000755000004100000410000000000014615741124021772 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/api_stub/requests/storage/0000755000004100000410000000000014615741124023436 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/api_stub/requests/storage/directory.rb0000644000004100000410000000512314615741124025770 0ustar www-datawww-datamodule ApiStub module Requests module Storage # Mock class for Deployment Requests # Below data should be as same as those in Mock classes in lib/fog/azurerm/requests/storage/*.rb class Directory def self.container { 'name' => 'test_container', 'public_access_level' => nil, 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available' } } end def self.container_lease_id { 'leaseId' => 'abc123' } end def self.container_object container = Azure::Storage::Blob::Container::Container.new container.public_access_level = 'container' container end def self.raw_container_acl [container_object, {}] end def self.container_acl [container_object.public_access_level, {}] end def self.container_https_url 'https://mockaccount.blob.core.windows.net/test_container?comp=list&restype=container' end def self.container_metadata { 'created-by' => 'User', 'source-machine' => 'Test-machine', 'category' => 'guidance', 'doctype' => 'textDocuments' } end def self.container_list [ { 'name' => 'test_container1', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available' } }, { 'name' => 'test_container2', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:01:08 GMT', 'etag' => '0x8D29C92176C8352', 'lease_status' => 'unlocked', 'lease_state' => 'available' } }, { 'name' => 'test_container3', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 01 Sep 2015 05:15:36 GMT', 'etag' => '0x8D2B28C5EB36458', 'lease_status' => 'unlocked', 'lease_state' => 'available' } } ] end end end end end gitlab-fog-azure-rm-1.9.1/test/api_stub/requests/storage/file.rb0000644000004100000410000002414214615741124024705 0ustar www-datawww-datamodule ApiStub module Requests module Storage # Mock class for Deployment Requests # Below data should be as same as those in Mock classes in lib/fog/azurerm/requests/storage/*.rb class File def self.blob blob_data = blob_as_hash blob = Azure::Storage::Blob::Blob.new blob.name = blob_data['name'] blob.metadata = blob_data['metadata'] blob.properties = blob_data['properties'].map { |k, v| { k.to_sym => v } }.reduce({}, &:merge!) blob end def self.blob_as_hash { 'name' => 'test_blob', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 09:30:31 GMT', 'etag' => '0x8D3A3EDD7C2B777', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'lease_duration' => nil, 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/testblob/4m?snapshot=2016-02-04T08%3A35%3A50.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } } end def self.blob_https_url(environment = Fog::AzureRM::ENVIRONMENT_AZURE_CLOUD) case environment when Fog::AzureRM::ENVIRONMENT_AZURE_CHINA_CLOUD 'https://mockaccount.blob.core.chinacloudapi.cn/test_container/test_blob' when Fog::AzureRM::ENVIRONMENT_AZURE_US_GOVERNMENT 'https://mockaccount.blob.core.usgovcloudapi.net/test_container/test_blob' when Fog::AzureRM::ENVIRONMENT_AZURE_GERMAN_CLOUD 'https://mockaccount.blob.core.cloudapi.de/test_container/test_blob' else 'https://mockaccount.blob.core.windows.net/test_container/test_blob' end end def self.blob_url_token 'token' end def self.blob_lease_id { 'leaseId' => 'abc123' } end def self.blob_metadata { 'created-by' => 'User', 'source-machine' => 'Test-machine', 'category' => 'guidance', 'doctype' => 'textDocuments' } end def self.blob_copy_result # copy_id, copy_status %w(abc123 pending) end def self.block_blob { 'name' => 'test_blob', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'BlockBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3256874Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } } end def self.emtpy_block_blob { 'name' => 'test_blob', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => nil, 'lease_state' => nil, 'content_length' => 0, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => nil, 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'BlockBlob', 'copy_id' => nil, 'copy_status' => nil, 'copy_source' => nil, 'copy_progress' => nil, 'copy_completion_time' => nil, 'copy_status_description' => nil, 'accept_ranges' => 0 } } end def self.blob_list [ { 'name' => 'test_blob1', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '0x8D3A3B5F017F52D', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3256874Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob2', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '0x8D29C92173526C8', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob3', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '0x8D29C92173526C8', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob4', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '0x8D29C92173526C8', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } } ] end end end end end gitlab-fog-azure-rm-1.9.1/test/api_stub/models/0000755000004100000410000000000014615741124021402 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/api_stub/models/storage/0000755000004100000410000000000014615741124023046 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/api_stub/models/storage/directory.rb0000644000004100000410000001620214615741124025400 0ustar www-datawww-datamodule ApiStub module Models module Storage # Mock class for Data Disk Model class Directory def self.container { 'name' => 'test_container', 'public_access_level' => nil, 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '"0x8D3A3B5F017F52D"', 'lease_status' => 'unlocked', 'lease_state' => 'available' } } end def self.container_acl ['container', {}] end def self.container_https_url 'https://mockaccount.blob.core.windows.net/test_container?comp=list&restype=container' end def self.container_list [ { 'name' => 'test_container1', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '"0x8D3A3B5F017F52D"', 'lease_status' => 'unlocked', 'lease_state' => 'available' } }, { 'name' => 'test_container2', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:01:08 GMT', 'etag' => '"0x8D29C92176C8352"', 'lease_status' => 'unlocked', 'lease_state' => 'available' } }, { 'name' => 'test_container3', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 01 Sep 2015 05:15:36 GMT', 'etag' => '"0x8D2B28C5EB36458"', 'lease_status' => 'unlocked', 'lease_state' => 'available' } } ] end def self.blob_list { next_marker: 'marker', blobs: [ { 'name' => 'test_blob1', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '"0x8D3A3B5F017F52D"', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3256874Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob2', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '"0x8D29C92173526C8"', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob3', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '"0x8D29C92173526C8"', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob4', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '"0x8D29C92173526C8"', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } } ] } end end end end end gitlab-fog-azure-rm-1.9.1/test/api_stub/models/storage/file.rb0000644000004100000410000001671514615741124024324 0ustar www-datawww-datamodule ApiStub module Models module Storage # Mock class for Data Disk Model class File def self.blob { 'name' => 'test_blob', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 09:30:31 GMT', 'etag' => '0x8D3A3EDD7C2B777', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'lease_duration' => nil, 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/testblob/4m?snapshot=2016-02-04T08%3A35%3A50.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } } end def self.blob_https_url 'https://mockaccount.blob.core.windows.net/test_container/test_blob' end def self.blob_metadata { 'created-by' => 'User', 'source-machine' => 'Test-machine', 'category' => 'guidance', 'doctype' => 'textDocuments' } end def self.blob_list { next_marker: 'marker', blobs: [ { 'name' => 'test_blob1', 'metadata' => {}, 'properties' => { 'last_modified' => 'Mon, 04 Jul 2016 02:50:20 GMT', 'etag' => '"0x8D3A3B5F017F52D"', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '095adc3b-e277-4c3d-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A50.3256874Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:35:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob2', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '"0x8D29C92173526C8"', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob3', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '"0x8D29C92173526C8"', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } }, { 'name' => 'test_blob4', 'metadata' => {}, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:02:08 GMT', 'etag' => '"0x8D29C92173526C8"', 'lease_status' => 'unlocked', 'lease_state' => 'available', 'content_length' => 4_194_304, 'content_type' => 'application/octet-stream', 'content_encoding' => nil, 'content_language' => nil, 'content_disposition' => nil, 'content_md5' => 'tXAohIyxuu/t94Lp/ujeRw==', 'cache_control' => nil, 'sequence_number' => 0, 'blob_type' => 'PageBlob', 'copy_id' => '0abcdc3b-4c3d-e277-97e0-0abca881f60c', 'copy_status' => 'success', 'copy_source' => 'https://testaccount.blob.core.windows.net/test_container/test_blob?snapshot=2016-02-04T08%3A35%3A55.3157696Z', 'copy_progress' => '4194304/4194304', 'copy_completion_time' => 'Thu, 04 Feb 2016 08:40:52 GMT', 'copy_status_description' => nil, 'accept_ranges' => 0 } } ] } end def self.container { 'name' => 'test_container', 'public_access_level' => 'container', 'metadata' => { 'key1' => 'value1', 'key2' => 'value2' }, 'properties' => { 'last_modified' => 'Tue, 04 Aug 2015 06:01:08 GMT', 'etag' => '"0x8D29C92176C8352"', 'lease_status' => 'unlocked', 'lease_state' => 'available' } } end end end end end gitlab-fog-azure-rm-1.9.1/test/models/0000755000004100000410000000000014615741124017574 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/models/storage/0000755000004100000410000000000014615741124021240 5ustar www-datawww-datagitlab-fog-azure-rm-1.9.1/test/models/storage/test_files.rb0000644000004100000410000001433514615741124023734 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Test class for Blob Collection class TestFiles < Minitest::Test def setup @service = Fog::AzureRM::Storage.new(storage_account_credentials) @directory = directory(@service) @files = @directory.files @mocked_response = mocked_storage_http_error @container = ApiStub::Models::Storage::File.container @blob = ApiStub::Models::Storage::File.blob @blob_list = ApiStub::Models::Storage::File.blob_list @blob_https_url = ApiStub::Models::Storage::File.blob_https_url end def test_collection_methods methods = [ :all, :each, :each_file_this_page, :get, :get_url, :get_http_url, :get_https_url, :head, :new ] methods.each do |method| assert_respond_to @files, method end end def test_collection_attributes attributes = [ :directory, :delimiter, :marker, :max_results, :next_marker, :prefix ] attributes.each do |attribute| assert_respond_to @files, attribute end end def test_all_method @service.stub :get_container_properties, @container do @service.stub :list_blobs, @blob_list do files = @files.all assert_instance_of Fog::AzureRM::Storage::Files, files assert_equal @blob_list[:blobs].size, files.size end end end def test_all_method_without_directory_exception assert_raises(ArgumentError) do @files.attributes.delete(:directory) @files.all end end def test_all_method_container_not_found @directory.collection.stub :get, nil do assert @files.all.nil? end end def test_each_method_with_all @blob_list[:next_marker] = nil @blob_list[:marker] = nil @service.stub :get_container_properties, @container do @service.stub :list_blobs, @blob_list do @files.next_marker = nil j = 0 @files.each do |file| assert_instance_of Fog::AzureRM::Storage::File, file j += 1 end assert_equal @blob_list[:blobs].size, j end end end def test_each_method_with_parts assert_instance_of Fog::AzureRM::Storage::Files, @files.each multiple_values = lambda do |_container_name, options| if options[:marker] == 'marker' return { next_marker: nil, blobs: @blob_list[:blobs][2, 2] } end return { next_marker: 'marker', blobs: @blob_list[:blobs][0, 2] } end @service.stub :get_container_properties, @container do @service.stub :list_blobs, multiple_values do j = 0 @files.each do |file| assert_instance_of Fog::AzureRM::Storage::File, file j += 1 end assert_equal @blob_list[:blobs].size, j end end end def test_get_method_success content = 'data' @service.stub :get_blob, [@blob, content] do file = @files.get('test_blob') assert_instance_of Fog::AzureRM::Storage::File, file assert_equal content, file.body end end def test_get_method_without_directory_exception assert_raises(ArgumentError) do @files.attributes.delete(:directory) @files.get('test_blob') end end def test_get_method_blob_not_found exception = ->(*) { raise 'NotFound' } @service.stub :get_blob, exception do assert @files.get('test_blob').nil? end end def test_get_method_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @service.stub :get_blob, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @files.get('test_blob') end end end def test_get_url_method_success @files.stub :get_https_url, @blob_https_url do assert_equal @blob_https_url, @files.get_url('test_blob', Time.now + 3600) end options = { scheme: 'http' } http_url = @blob_https_url.gsub('https:', 'http:') @files.stub :get_http_url, http_url do assert_equal http_url, @files.get_url('test_blob', Time.now + 3600, options) end end def test_get_url_method_without_directory_exception assert_raises(ArgumentError) do @files.attributes.delete(:directory) @files.get_url('test_blob', Time.now + 3600) end end def test_get_http_url_method_success http_url = @blob_https_url.gsub('https:', 'http:') @service.stub :get_blob_http_url, http_url do assert_equal http_url, @files.get_http_url('test_blob', Time.now + 3600) end end def test_get_http_url_method_without_directory_exception assert_raises(ArgumentError) do @files.attributes.delete(:directory) @files.get_http_url('test_blob', Time.now + 3600) end end def test_get_https_url_method_success @service.stub :get_blob_https_url, @blob_https_url do assert_equal @blob_https_url, @files.get_https_url('test_blob', Time.now + 3600) end end def test_get_https_url_method_without_directory_exception assert_raises(ArgumentError) do @files.attributes.delete(:directory) @files.get_https_url('test_blob', Time.now + 3600) end end def test_head_method_success @service.stub :get_blob_properties, @blob do file = @files.head('test_blob') assert_instance_of Fog::AzureRM::Storage::File, file assert file.attributes[:body].nil? end end def test_head_method_without_directory_exception assert_raises(ArgumentError) do @files.attributes.delete(:directory) @files.head('test_blob') end end def test_head_method_blob_not_found exception = ->(*) { raise 'NotFound' } @service.stub :get_blob_properties, exception do assert @files.head('test_blob').nil? end end def test_head_method_http_exception http_exception = ->(*) { raise Azure::Core::Http::HTTPError.new(@mocked_response) } @service.stub :get_blob_properties, http_exception do assert_raises(Azure::Core::Http::HTTPError) do @files.head('test_blob') end end end def test_new_method_success assert_instance_of Fog::AzureRM::Storage::File, @files.new end def test_new_method_without_directory_exception assert_raises(ArgumentError) do @files.attributes.delete(:directory) @files.new end end end gitlab-fog-azure-rm-1.9.1/test/models/storage/test_directory.rb0000644000004100000410000001120014615741124024622 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Test class for Storage Container Model class TestDirectory < Minitest::Test def setup @service = Fog::AzureRM::Storage.new(storage_account_credentials) @directory = directory(@service) @container = ApiStub::Models::Storage::Directory.container @container_acl = ApiStub::Models::Storage::Directory.container_acl @container_https_url = ApiStub::Models::Storage::Directory.container_https_url end def test_model_methods methods = [ :acl=, :acl, :destroy, :files, :public=, :public_url, :save, :persisted? ] methods.each do |method| assert_respond_to @directory, method end end def test_model_attributes attributes = [ :key, :etag, :last_modified, :lease_duration, :lease_state, :lease_status, :metadata ] @service.stub :create_container, @container do attributes.each do |attribute| assert_respond_to @directory, attribute end end end def test_set_acl_method_success result = @directory.acl = 'container' assert_equal 'container', result assert_equal 'container', @directory.attributes[:acl] end def test_set_acl_method_exception assert_raises(ArgumentError) do @directory.acl = 'invalid-acl' end end def test_get_acl_method_success # Return 'unknonw' when directory is not persist and acl is 'unknown' @directory.acl = 'unknown' @directory.stub :persisted?, false do assert_equal 'unknown', @directory.acl end # Return actual value directly when directory is not persist and acl is not 'unknown' @directory.acl = 'blob' @directory.stub :persisted?, false do assert_equal 'blob', @directory.acl end # Query actual value and return it when directory is persist and acl is 'unknown' @directory.acl = 'unknown' @directory.stub :persisted?, true do @service.stub :get_container_acl, @container_acl do assert_equal 'container', @directory.acl assert_equal 'container', @directory.attributes[:acl] end end end def test_get_acl_method_without_key_exception @directory.attributes.delete(:key) assert_raises(ArgumentError) do @directory.acl end end def test_destroy_method_success @service.stub :delete_container, true do assert @directory.destroy end end def test_destroy_method_without_key_exception @directory.attributes.delete(:key) assert_raises(ArgumentError) do @directory.destroy end end def test_files_method_success assert_instance_of Fog::AzureRM::Storage::Files, @directory.files end def test_set_public_method_success # Set public result = @directory.public = true assert result assert_equal 'container', @directory.attributes[:acl] # Set private result = @directory.public = false assert !result assert_equal nil, @directory.attributes[:acl] end def test_public_url_method_with_public_success @directory.stub :acl, 'container' do @service.stub :get_container_url, @container_https_url do assert_equal @container_https_url, @directory.public_url end end end def test_public_url_method_with_private_success @directory.stub :acl, nil do assert @directory.public_url.nil? end end def test_public_url_method_without_key_exception @directory.attributes.delete(:key) assert_raises(ArgumentError) do @directory.public_url end end def test_save_method_create_success @service.stub :create_container, @container do assert @directory.save assert @directory.attributes[:is_persisted] end end def test_save_method_update_success options = { is_create: false } @service.stub :put_container_acl, true do @service.stub :put_container_metadata, true do @service.stub :get_container_properties, @container do assert @directory.save(options) assert @directory.attributes[:is_persisted] end end end end def test_save_method_without_key_exception @directory.attributes.delete(:key) assert_raises(ArgumentError) do @directory.save end end def test_persisted_method_success @directory.attributes[:is_persisted] = true @directory.attributes[:last_modified] = nil assert @directory.persisted? @directory.attributes[:is_persisted] = false @directory.attributes[:last_modified] = 'datetime' assert @directory.persisted? @directory.attributes[:is_persisted] = false @directory.attributes[:last_modified] = nil assert !@directory.persisted? end end gitlab-fog-azure-rm-1.9.1/test/models/storage/test_directories.rb0000644000004100000410000000433714615741124025147 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Test class for Container Collection class TestDirectories < Minitest::Test def setup @service = Fog::AzureRM::Storage.new(storage_account_credentials) @directories = Fog::AzureRM::Storage::Directories.new(service: @service) @container_list = ApiStub::Models::Storage::Directory.container_list @container = ApiStub::Models::Storage::Directory.container @blob_list = ApiStub::Models::Storage::Directory.blob_list end def test_collection_methods methods = [ :all, :get, :check_container_exists ] methods.each do |method| assert_respond_to @directories, method end end def test_all_method_success @service.stub :list_containers, @container_list do dirs = @directories.all assert_instance_of Fog::AzureRM::Storage::Directories, dirs assert_equal @container_list.size, dirs.size dirs.each do |directory| assert_instance_of Fog::AzureRM::Storage::Directory, directory assert_equal 'unknown', directory.attributes[:acl] end end end def test_get_method_success @service.stub :get_container_properties, @container do @service.stub :list_blobs, @blob_list do directory = @directories.get('test_container') assert_instance_of Fog::AzureRM::Storage::Directory, directory assert_equal 'unknown', directory.attributes[:acl] end end end def test_get_method_container_not_found exception = ->(*) { raise 'NotFound' } @service.stub :get_container_properties, exception do assert @directories.get('test_container').nil? end end def test_get_method_exception exception = ->(*) { raise 'Error' } @service.stub :get_container_properties, exception do assert_raises(RuntimeError) do @directories.get('test_container') end end end def test_check_container_exists_true_response @service.stub :check_container_exists, true do assert @directories.check_container_exists('test_container') end end def test_check_container_exists_false_response @service.stub :check_container_exists, false do assert !@directories.check_container_exists('test_container') end end end gitlab-fog-azure-rm-1.9.1/test/models/storage/test_file.rb0000644000004100000410000002037614615741124023553 0ustar www-datawww-datarequire File.expand_path '../../test_helper', __dir__ # Test class for Storage Container Model class TestFile < Minitest::Test # rubocop:disable Metrics/ClassLength def setup @service = Fog::AzureRM::Storage.new(storage_account_credentials) @directory = directory(@service) @file = file(@service) @raw_cloud_blob = storage_blob @mocked_response = mocked_storage_http_error @blob = ApiStub::Models::Storage::File.blob @metadata = ApiStub::Models::Storage::File.blob_metadata @blob_list = ApiStub::Models::Storage::File.blob_list @blob_https_url = ApiStub::Models::Storage::File.blob_https_url end def test_model_methods methods = [ :save, :body, :body=, :copy, :copy_from_uri, :destroy, :public?, :public_url, :url ] methods.each do |method| assert_respond_to @file, method end end def test_model_attributes attributes = [ :key, :body, :directory, :accept_ranges, :content_length, :content_type, :content_md5, :content_encoding, :content_language, :cache_control, :content_disposition, :copy_completion_time, :copy_status, :copy_status_description, :copy_id, :copy_progress, :copy_source, :etag, :last_modified, :lease_duration, :lease_state, :lease_status, :sequence_number, :blob_type, :metadata ] attributes.each do |attribute| assert_respond_to @file, attribute end end def test_save_method_with_small_block_blob_success @file.body = 'd' * 1025 # SINGLE_BLOB_PUT_THRESHOLD is 32 * 1024 * 1024 @service.stub :create_block_blob, @raw_cloud_blob do assert @file.save end end def test_save_method_with_large_block_blob_success @file.body = 'd' * (32 * 1024 * 1024 + 1) # SINGLE_BLOB_PUT_THRESHOLD is 32 * 1024 * 1024 @service.stub :create_block_blob, @raw_cloud_blob do assert @file.save end end def test_save_method_with_page_blob_success options = { blob_type: 'PageBlob' } @file.metadata = @metadata @file.body = 'd' * 5 * 1024 * 1024 # MAXIMUM_CHUNK_SIZE is 4 * 1024 * 1024 @service.stub :save_page_blob, true do @service.stub :get_blob_properties, @raw_cloud_blob do assert @file.save(options) end end end def test_save_method_with_not_update_body_success options = { update_body: false } @file.metadata = @metadata @service.stub :put_blob_metadata, true do @service.stub :put_blob_properties, true do @service.stub :get_blob_properties, @raw_cloud_blob do assert @file.save(options) end end end end def test_save_method_without_directory_exception assert_raises(ArgumentError) do @file.attributes.delete(:directory) @file.save end end def test_save_method_without_key_exception assert_raises(ArgumentError) do @file.attributes.delete(:key) @file.save end end def test_save_method_create_without_body_exception assert_raises(ArgumentError) do @file.attributes.delete(:body) @file.save end end def test_get_body_method_local_success @file.attributes[:body] = 'body' assert_equal 'body', @file.body @file.attributes[:body] = nil @file.attributes[:last_modified] = nil assert_equal '', @file.body end def test_get_body_method_remote_success @file.attributes[:body] = nil remote_file = @file.dup body_content = 'data' @file.collection.stub :get, remote_file do remote_file.stub :body, body_content do body = @file.body assert_equal body_content, body assert_equal body_content, @file.attributes[:body] end end end def test_get_body_method_remote_not_found_success @file.attributes[:body] = nil @file.collection.stub :get, nil do body = @file.body assert_equal '', body assert_equal '', @file.attributes[:body] end end def test_set_body_method_success @file.body = 'new_body' assert_equal 'new_body', @file.attributes[:body] end def test_copy_method_success copy_id = @raw_cloud_blob.properties[:copy_id] copy_status = 'pending' @service.stub :get_blob_properties, @raw_cloud_blob do @service.stub :copy_blob, [copy_id, copy_status] do @service.stub :wait_blob_copy_operation_to_finish, true do target_file = @file.copy('target_container', 'target_blob') assert_instance_of Fog::AzureRM::Storage::File, target_file end end end end def test_copy_from_uri_method_success copy_id = @raw_cloud_blob.properties[:copy_id] copy_status = 'pending' @service.stub :get_blob_properties, @raw_cloud_blob do @service.stub :copy_blob_from_uri, [copy_id, copy_status] do @service.stub :wait_blob_copy_operation_to_finish, true do assert @file.copy_from_uri('source_uri') end end end end def test_copy_from_uri_method_without_directory_exception assert_raises(ArgumentError) do @file.attributes.delete(:directory) @file.copy_from_uri('source_uri') end end def test_copy_from_uri_method_without_key_exception assert_raises(ArgumentError) do @file.attributes.delete(:key) @file.copy_from_uri('source_uri') end end def test_destroy_method_success @service.stub :delete_blob, true do assert @file.destroy assert @file.attributes[:body].nil? end end def test_destroy_method_without_directory_exception assert_raises(ArgumentError) do @file.attributes.delete(:directory) @file.destroy end end def test_destroy_method_without_key_exception assert_raises(ArgumentError) do @file.attributes.delete(:key) @file.destroy end end def test_public_method_success @file.directory.acl = 'container' assert @file.public? @file.directory.acl = 'blob' assert @file.public? @file.directory.acl = nil assert !@file.public? end def test_public_method_without_directory_exception assert_raises(ArgumentError) do @file.attributes.delete(:directory) @file.public? end end def test_public_url_method_success @file.stub :public?, false do assert @file.public_url.nil? end @file.stub :public?, true do @service.stub :get_blob_url, @blob_https_url do assert @file.public_url, @blob_https_url end end http_url = @blob_https_url.gsub('https:', 'http:') options = { scheme: 'https' } @file.stub :public?, true do @service.stub :get_blob_url, http_url do assert @file.public_url(options), http_url end end end def test_public_url_method_without_directory_exception assert_raises(ArgumentError) do @file.attributes.delete(:directory) @file.public_url end end def test_public_url_method_without_key_exception assert_raises(ArgumentError) do @file.attributes.delete(:key) @file.public_url end end def test_url_method_success @file.collection.stub :get_url, @blob_https_url do assert @file.url(Time.now + 3600), @blob_https_url end end def test_url_method_with_content_disposition @file.collection.stub :get_url, @blob_https_url, { content_disposition: 'attachment' } do assert @file.url(Time.now + 3600, content_disposition: 'attachment'), @blob_https_url end end def test_url_method_with_response_content_disposition fake = Minitest::Mock.new expiry = Time.now + 3600 fake.expect :call, nil, [@file.key, expiry, { content_disposition: 'attachment', content_type: nil }] @file.collection.stub(:get_url, fake) do @file.url(expiry, { query: { 'response-content-disposition' => 'attachment' } }) end end def test_url_method_with_response_content_type fake = Minitest::Mock.new expiry = Time.now + 3600 fake.expect :call, nil, [@file.key, expiry, { content_disposition: nil, content_type: 'image/png' }] @file.collection.stub(:get_url, fake) do @file.url(expiry, { query: { 'response-content-type' => 'image/png' } }) end end def test_url_method_without_key_exception assert_raises(ArgumentError) do @file.attributes.delete(:key) @file.url(Time.now + 3600) end end end gitlab-fog-azure-rm-1.9.1/test/api_stub.rb0000644000004100000410000002026614615741124020452 0ustar www-datawww-data# Module for API Stub module ApiStub module Models # Load test Compute models module Compute autoload :Server, File.expand_path('api_stub/models/compute/server', __dir__) autoload :AvailabilitySet, File.expand_path('api_stub/models/compute/availability_set', __dir__) autoload :VirtualMachineExtension, File.expand_path('api_stub/models/compute/virtual_machine_extension', __dir__) autoload :ManagedDisk, File.expand_path('api_stub/models/compute/managed_disk', __dir__) autoload :Snapshot, File.expand_path('api_stub/models/compute/snapshot', __dir__) end # Load test Resources models module Resources autoload :ResourceGroup, File.expand_path('api_stub/models/resources/resource_group', __dir__) autoload :Deployment, File.expand_path('api_stub/models/resources/deployment', __dir__) autoload :Resource, File.expand_path('api_stub/models/resources/resource', __dir__) end # Load test Storage models module Storage autoload :StorageAccount, File.expand_path('api_stub/models/storage/storageaccount', __dir__) autoload :File, ::File.expand_path('api_stub/models/storage/file', __dir__) autoload :Directory, ::File.expand_path('api_stub/models/storage/directory', __dir__) end # Load test Network models module Network autoload :PublicIp, File.expand_path('api_stub/models/network/public_ip', __dir__) autoload :Subnet, File.expand_path('api_stub/models/network/subnet', __dir__) autoload :VirtualNetwork, File.expand_path('api_stub/models/network/virtual_network', __dir__) autoload :NetworkInterface, File.expand_path('api_stub/models/network/network_interface', __dir__) autoload :LoadBalancer, File.expand_path('api_stub/models/network/load_balancer', __dir__) autoload :NetworkSecurityGroup, File.expand_path('api_stub/models/network/network_security_group', __dir__) autoload :NetworkSecurityRule, File.expand_path('api_stub/models/network/network_security_rule', __dir__) autoload :VirtualNetworkGateway, File.expand_path('api_stub/models/network/virtual_network_gateway', __dir__) autoload :VirtualNetworkGatewayConnection, File.expand_path('api_stub/models/network/virtual_network_gateway_connection', __dir__) autoload :ExpressRouteCircuit, File.expand_path('api_stub/models/network/express_route_circuit', __dir__) autoload :ExpressRouteCircuitPeering, File.expand_path('api_stub/models/network/express_route_circuit_peering', __dir__) autoload :ExpressRouteCircuitAuthorization, File.expand_path('api_stub/models/network/express_route_circuit_authorization', __dir__) autoload :ExpressRouteServiceProvider, File.expand_path('api_stub/models/network/express_route_service_provider', __dir__) autoload :LocalNetworkGateway, File.expand_path('api_stub/models/network/local_network_gateway', __dir__) end # Load test ApplicationGateway models module ApplicationGateway autoload :Gateway, File.expand_path('api_stub/models/application_gateway/gateway', __dir__) end # Load test TrafficManager models module TrafficManager autoload :TrafficManagerEndPoint, File.expand_path('api_stub/models/traffic_manager/traffic_manager_end_point', __dir__) autoload :TrafficManagerProfile, File.expand_path('api_stub/models/traffic_manager/traffic_manager_profile', __dir__) end # Load test DNS models module DNS autoload :Zone, File.expand_path('api_stub/models/dns/zone', __dir__) autoload :RecordSet, File.expand_path('api_stub/models/dns/record_set', __dir__) end # Load test Sql models module Sql autoload :SqlServer, File.expand_path('api_stub/models/sql/sql_server', __dir__) autoload :SqlDatabase, File.expand_path('api_stub/models/sql/sql_database', __dir__) autoload :SqlFirewallRule, File.expand_path('api_stub/models/sql/sql_firewall_rule', __dir__) end # Load test KeyVault models module KeyVault autoload :Vault, File.expand_path('api_stub/models/key_vault/vault', __dir__) end end module Requests # Load test Compute requests module Compute autoload :AvailabilitySet, File.expand_path('api_stub/requests/compute/availability_set', __dir__) autoload :VirtualMachine, File.expand_path('api_stub/requests/compute/virtual_machine', __dir__) autoload :VirtualMachineExtension, File.expand_path('api_stub/requests/compute/virtual_machine_extension', __dir__) autoload :ManagedDisk, File.expand_path('api_stub/requests/compute/managed_disk', __dir__) autoload :Image, File.expand_path('api_stub/requests/compute/image', __dir__) autoload :Snapshot, File.expand_path('api_stub/requests/compute/snapshot', __dir__) end # Load test Resources requests module Resources autoload :ResourceGroup, File.expand_path('api_stub/requests/resources/resource_group', __dir__) autoload :Deployment, File.expand_path('api_stub/requests/resources/deployment', __dir__) autoload :AzureResource, File.expand_path('api_stub/requests/resources/resource', __dir__) end # Load test Storage requests module Storage autoload :StorageAccount, File.expand_path('api_stub/requests/storage/storageaccount', __dir__) autoload :File, ::File.expand_path('api_stub/requests/storage/file', __dir__) autoload :Directory, ::File.expand_path('api_stub/requests/storage/directory', __dir__) end # Load test Network requests module Network autoload :PublicIp, File.expand_path('api_stub/requests/network/public_ip', __dir__) autoload :Subnet, File.expand_path('api_stub/requests/network/subnet', __dir__) autoload :VirtualNetwork, File.expand_path('api_stub/requests/network/virtual_network', __dir__) autoload :NetworkInterface, File.expand_path('api_stub/requests/network/network_interface', __dir__) autoload :LoadBalancer, File.expand_path('api_stub/requests/network/load_balancer', __dir__) autoload :NetworkSecurityGroup, File.expand_path('api_stub/requests/network/network_security_group', __dir__) autoload :NetworkSecurityRule, File.expand_path('api_stub/requests/network/network_security_rule', __dir__) autoload :VirtualNetworkGateway, File.expand_path('api_stub/requests/network/virtual_network_gateway', __dir__) autoload :VirtualNetworkGatewayConnection, File.expand_path('api_stub/requests/network/virtual_network_gateway_connection', __dir__) autoload :ExpressRouteCircuit, File.expand_path('api_stub/requests/network/express_route_circuit', __dir__) autoload :ExpressRouteCircuitPeering, File.expand_path('api_stub/requests/network/express_route_circuit_peering', __dir__) autoload :ExpressRouteCircuitAuthorization, File.expand_path('api_stub/requests/network/express_route_circuit_authorization', __dir__) autoload :ExpressRouteServiceProvider, File.expand_path('api_stub/requests/network/express_route_service_provider', __dir__) autoload :LocalNetworkGateway, File.expand_path('api_stub/requests/network/local_network_gateway', __dir__) end # Load test ApplicationGateway requests module ApplicationGateway autoload :Gateway, File.expand_path('api_stub/requests/application_gateway/gateway', __dir__) end # Load test TrafficManager requests module TrafficManager autoload :TrafficManagerEndPoint, File.expand_path('api_stub/requests/traffic_manager/traffic_manager_endpoint', __dir__) autoload :TrafficManagerProfile, File.expand_path('api_stub/requests/traffic_manager/traffic_manager_profile', __dir__) end # Load test DNS requests module DNS autoload :Zone, File.expand_path('api_stub/requests/dns/zone', __dir__) autoload :RecordSet, File.expand_path('api_stub/requests/dns/record_set', __dir__) end # Load test Sql requests module Sql autoload :SqlServer, File.expand_path('api_stub/requests/sql/sql_server', __dir__) autoload :SqlDatabase, File.expand_path('api_stub/requests/sql/database', __dir__) autoload :FirewallRule, File.expand_path('api_stub/requests/sql/firewall_rule', __dir__) end # Load test KeyVault requests module KeyVault autoload :Vault, File.expand_path('api_stub/requests/key_vault/vault', __dir__) end end end gitlab-fog-azure-rm-1.9.1/.hound.yml0000644000004100000410000000004214615741124017244 0ustar www-datawww-dataruby: config_file: .rubocop.yml gitlab-fog-azure-rm-1.9.1/LICENSE.md0000644000004100000410000000220214615741124016732 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) 2014-2015 [CONTRIBUTORS.md](https://github.com/fog/fog-azure-rm/blob/master/CONTRIBUTORS.md) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gitlab-fog-azure-rm-1.9.1/.rubocop_todo.yml0000644000004100000410000001745414615741124020644 0ustar www-datawww-data# This configuration was generated by # `rubocop --auto-gen-config` # on 2020-08-07 04:33:26 UTC using RuboCop version 0.89.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 1 # Configuration parameters: Include. # Include: **/*.gemspec Gemspec/RequiredRubyVersion: Exclude: - 'gitlab-fog-azure-rm.gemspec' # Offense count: 23 # Cop supports --auto-correct. Layout/EmptyLineAfterGuardClause: Enabled: false # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AllowAliasSyntax, AllowedMethods. # AllowedMethods: alias_method, public, protected, private Layout/EmptyLinesAroundAttributeAccessor: Exclude: - 'lib/fog/azurerm/models/storage/file.rb' # Offense count: 2 # Configuration parameters: EnforcedStyle. # SupportedStyles: native, lf, crlf Layout/EndOfLine: Exclude: - 'lib/fog/azurerm/models/resources/azure_resource.rb' - 'lib/fog/azurerm/models/resources/azure_resources.rb' # Offense count: 13 # Cop supports --auto-correct. # Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. # SupportedHashRocketStyles: key, separator, table # SupportedColonStyles: key, separator, table # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit Layout/HashAlignment: Exclude: - 'lib/fog/azurerm/models/storage/file.rb' - 'test/test_helper.rb' # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: space, no_space Layout/SpaceAroundEqualsInParameterDefault: Exclude: - 'lib/fog/azurerm/requests/storage/release_container_lease.rb' # Offense count: 1 # Cop supports --auto-correct. Layout/SpaceBeforeComma: Exclude: - 'gitlab-fog-azure-rm.gemspec' # Offense count: 2 Lint/DuplicateMethods: Exclude: - 'lib/fog/azurerm/models/storage/directory.rb' - 'lib/fog/azurerm/models/storage/file.rb' # Offense count: 2 Lint/RescueException: Exclude: - 'lib/fog/azurerm/models/storage/directories.rb' - 'lib/fog/azurerm/requests/storage/check_container_exists.rb' # Offense count: 3 Lint/UselessAssignment: Exclude: - 'lib/fog/azurerm/storage.rb' - 'test/integration/container.rb' # Offense count: 1 # Configuration parameters: CheckForMethodsWithNoSideEffects. Lint/Void: Exclude: - 'lib/fog/azurerm/models/storage/directory.rb' # Offense count: 30 # Configuration parameters: IgnoredMethods. Metrics/AbcSize: Max: 66 # Offense count: 11 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: Max: 250 # Offense count: 9 # Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: Max: 14 # Offense count: 98 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods. Metrics/MethodLength: Max: 115 # Offense count: 1 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: Max: 6 # Offense count: 9 # Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: Max: 14 # Offense count: 9 Naming/ConstantName: Exclude: - 'lib/fog/azurerm/models/storage/kind.rb' - 'lib/fog/azurerm/models/storage/sku_name.rb' - 'lib/fog/azurerm/models/storage/sku_tier.rb' # Offense count: 38 # Cop supports --auto-correct. # Configuration parameters: PreferredName. Naming/RescuedExceptionsVariableName: Enabled: false # Offense count: 13 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: separated, grouped Style/AccessorGrouping: Exclude: - 'lib/fog/azurerm/requests/storage/save_page_blob.rb' - 'test/test_helper.rb' # Offense count: 2 # Cop supports --auto-correct. Style/ExpandPathArguments: Exclude: - 'gitlab-fog-azure-rm.gemspec' - 'lib/fog/azurerm/utilities/general.rb' # Offense count: 2 # Cop supports --auto-correct. Style/ExplicitBlockArgument: Exclude: - 'lib/fog/azurerm/models/storage/files.rb' # Offense count: 117 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Enabled: false # Offense count: 3 # Cop supports --auto-correct. Style/IfUnlessModifier: Exclude: - 'lib/fog/azurerm/requests/storage/compare_container_blobs.rb' - 'lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb' # Offense count: 1 # Cop supports --auto-correct. Style/MultilineIfModifier: Exclude: - 'lib/fog/azurerm/models/resources/dependency.rb' # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AllowedMethods. # AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with Style/NestedParenthesizedCalls: Exclude: - 'test/test_helper.rb' # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. # SupportedStyles: predicate, comparison Style/NumericPredicate: Exclude: - 'spec/**/*' - 'lib/fog/azurerm/requests/storage/get_blob.rb' # Offense count: 2 Style/OptionalBooleanParameter: Exclude: - 'lib/fog/azurerm/async_response.rb' - 'lib/fog/azurerm/utilities/general.rb' # Offense count: 36 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: Exclude: - 'lib/fog/azurerm/models/storage/directory.rb' - 'lib/fog/azurerm/models/storage/file.rb' - 'lib/fog/azurerm/models/storage/files.rb' - 'lib/fog/azurerm/requests/storage/copy_blob.rb' - 'lib/fog/azurerm/requests/storage/copy_blob_from_uri.rb' - 'test/api_stub/requests/storage/file.rb' - 'test/test_helper.rb' # Offense count: 48 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: compact, exploded Style/RaiseArgs: Enabled: false # Offense count: 1 # Cop supports --auto-correct. Style/RedundantBegin: Exclude: - 'lib/fog/azurerm/storage.rb' # Offense count: 16 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, explicit Style/RescueStandardError: Exclude: - 'lib/fog/azurerm/models/storage/files.rb' - 'lib/fog/azurerm/requests/storage/create_block_blob.rb' - 'lib/fog/azurerm/requests/storage/multipart_save_block_blob.rb' - 'lib/fog/azurerm/requests/storage/save_page_blob.rb' - 'lib/fog/azurerm/requests/storage/wait_blob_copy_operation_to_finish.rb' - 'test/integration/blob.rb' - 'test/integration/container.rb' - 'test/integration/storage_account.rb' # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods. # AllowedMethods: present?, blank?, presence, try, try! Style/SafeNavigation: Exclude: - 'test/integration/blob.rb' - 'test/integration/container.rb' - 'test/integration/storage_account.rb' # Offense count: 2 # Cop supports --auto-correct. Style/StringConcatenation: Exclude: - 'test/integration/blob.rb' # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes Style/StringLiterals: Exclude: - 'gitlab-fog-azure-rm.gemspec' # Offense count: 9 # Cop supports --auto-correct. # Configuration parameters: MinSize. # SupportedStyles: percent, brackets Style/SymbolArray: EnforcedStyle: brackets # Offense count: 257 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Layout/LineLength: Max: 1242 gitlab-fog-azure-rm-1.9.1/Gemfile0000644000004100000410000000014014615741124016620 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in fog-azure-rm.gemspec gemspec gitlab-fog-azure-rm-1.9.1/CONTRIBUTORS.md0000644000004100000410000000072114615741124017611 0ustar www-datawww-data * Adnan Khalil * Samawia Moin * Shaffan Chaudhry * Zeeshan Arshad * Haider Ali * Waqar Haider * Bilal Naeem * Azeem Sajid * Maham Nazir * Muhammad Asad * Muhammad Abbas Sheikh gitlab-fog-azure-rm-1.9.1/.arclint0000644000004100000410000000014614615741124016770 0ustar www-datawww-data{ "linters": { "ruby": { "type": "rubocop", "include": "/\\.(rb|rake)$/" } } }gitlab-fog-azure-rm-1.9.1/.travis.yml0000644000004100000410000000306314615741124017445 0ustar www-datawww-datalanguage: ruby sudo: false before_install: - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true - gem install bundler -v '< 2' - gem uninstall -aIx nokogiri -i /home/travis/.rvm/gems/ruby-2.4.1@global nokogiri script: bash ./rake-script.sh rvm: - 2.0.0 - 2.1.0 - 2.1.1 - 2.1.5 - 2.2.10 - 2.3.7 - 2.4.4 - 2.5.1 - jruby-head matrix: fast_finish: true allow_failures: - rvm: jruby-head notifications: email: recipients: - dev-oneops@confiz.com on_success: always on_failure: always addons: code_climate: repo_token: b1401494baa004d90402414cb33a7fc6420fd3693e60c677a120ddefd7d84cfd jobs: include: - stage: gem release deploy: provider: rubygems api_key: secure: "aKIOqa6gFMQOcwdNBNsfRoAQm+LVCRf9JpEFnDH8YLRp9A+roj0BL3hZ+pP+pb2sQSEQqU46bfBBrhB2b6Xmjnmv5d0878bl+eYOXeu90CfqRf+v/y+2k/pMsVsKs3Su7M0bHGOeHYT+segRqDHaZaJHkAW8RwLLm5A+0TyEeVjkkpFcyX8fjr5sfvD+XbEmXmmPWPuShQjKTTj1HFYJknRLLNXVYd7ZM9eKgiQfuyomdUTk8yguqNDBWW1BjiEE/0JYqx4wJxdGKPHYT+enP1xIebJVx1gEEnc/OgyBZqtmOirlh2Rnuk58NZfArzwMzIvVclJvPmynmEAlHEWtXwUgQMW5Wu/RYpxRRpr5tDRfru99hll4N9bcA439GlsNHTNJf82zmGNFIdDJ8kUJ08tVPwTvEnWGzLIdKAKWyRV+SESmZb5u3m9e4VTd06/q8gdbW9pG9UGmoes/j32lKzk9DkheCVzQjdxfRs81Z/7uTB3OhhpQnrRlf7qa2OnMDZKrip67UQHiruzAX6naQ7D5fEHR64DGZG7fQ/xRi0oG21UdNl1n/Bioj6ChFXLyInKeA0fiEwwquWK2S/2Sr5ERTBzbv9TkvbJ/1vv8FWcYYmb7bL22699V9yWcsOxEdZEYDucg71g6OrPeNeFZDsJ1749fZzW2X444+4Xtwys=" gem: fog-azure-rm gemspec: fog-azure-rm.gemspec on: tags: true branch: master gitlab-fog-azure-rm-1.9.1/README.md0000644000004100000410000001051714615741124016615 0ustar www-datawww-data[![Gem Version](https://badge.fury.io/rb/fog-azure-rm.svg)](https://badge.fury.io/rb/fog-azure-rm) [![Build Status](https://travis-ci.org/fog/fog-azure-rm.svg?branch=master)](https://travis-ci.org/fog/fog-azure-rm) [![security](https://hakiri.io/github/fog/fog-azure-rm/master.svg)](https://hakiri.io/github/fog/fog-azure-rm/master) [![Test Coverage](https://codeclimate.com/github/fog/fog-azure-rm/badges/coverage.svg)](https://codeclimate.com/github/fog/fog-azure-rm/coverage) [![Code Climate](https://codeclimate.com/github/fog/fog-azure-rm/badges/gpa.svg)](https://codeclimate.com/github/fog/fog-azure-rm) # Fog Azure Resource Manager NOTE: This is a fork of https://github.com/fog/fog-azure-rm. This fork is used to support blob transfers with CarrierWave and Fog v2. This document describes how to get started with Fog using Microsoft Azure as a cloud resource management services provider. ## Pre-requisites * Fog-azure-rm supports Ruby version 2.0.0 or later ## Installation Add this line to your application's Gemfile: ```ruby gem 'fog-azure-rm' ``` And then execute: $ bundle Or install it yourself as: $ gem install fog-azure-rm ## Usage You can use this gem against the Microsoft Azure Resource Manager Services in the cloud. Of course, to use the Microsoft Azure Resource Manager Services in the cloud, you need to first [create a Microsoft Azure account](http://www.azure.com/en-us/pricing/free-trial/). * Set 'LOCATION' constant based on the Azure cloud you are using in [config.rb] (https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/config.rb) file. By default it will be 'eastus'. ### Authentication The next step to use this gem, is authentication and permissioning. It is important to get familiar with this concept. For a reference on setting up a service principal from the command line see [Authenticating a service principal with Azure Resource Manager](http://aka.ms/cli-service-principal) or [Unattended Authentication](http://aka.ms/auth-unattended). For a more robust explanation of authentication in Azure, see [Developer’s guide to auth with Azure Resource Manager API](http://aka.ms/arm-auth-dev-guide). After creating the service principal, you should have three pieces of information, a client id (GUID), client secret (string) and tenant id (GUID). ### Compute Fog-AzureRM for compute includes implementation of Virtual Machines and Availability Sets. Readme for the usage of [Compute](https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/docs/compute.md) module. ### Resources Fog-AzureRM for resources includes implementation of Resource Groups. Readme for the usage of [Resources](https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/docs/resources.md) module. ### DNS Fog-AzureRM for dns includes implementation of Record sets and Zones. Readme for the usage of [DNS](https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/docs/dns.md) module. ### Network Fog-AzureRM for network includes implementation of Network Interfaces, Public IPs, Subnets and Virtual Networks. Readme for the usage of [Network](https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/docs/network.md) module. ### Storage Fog-AzureRM for storage includes implementation of Storage Accounts. Readme for the usage of [Storage](https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/docs/storage.md) module. ### Traffic Manager Fog-AzureRM for Traffic Manager includes implementation of Traffic Manager Profile and Traffic Manager End-points. Readme for the usage of [Traffic Manager](https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/docs/traffic_manager.md) module. ### SQL Fog-AzureRM for SQL includes implementation of SQL Server, SQL Databases and Data Warehouse. Readme for the usage of [Azure SQL](https://github.com/fog/fog-azure-rm/blob/master/lib/fog/azurerm/docs/sql.md) module. ## Supported Services Use following command for the complete list of services, Fog provides for Azure Resource Manager. ```ruby Fog::AzureRM.services ``` # Documentation https://www.rubydoc.info/github/fog/fog-azure-rm/master ## Contributing See [CONTRIBUTING.md](https://github.com/fog/fog-azure-rm/blob/master/CONTRIBUTING.md) in this repository. ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). gitlab-fog-azure-rm-1.9.1/gitlab-fog-azure-rm.gemspec0000755000004100000410000000322514615741124022457 0ustar www-datawww-datalib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'fog/azurerm/version' Gem::Specification.new do |spec| spec.name = 'gitlab-fog-azure-rm' spec.version = Fog::AzureRM::VERSION spec.authors = ['Shaffan Chaudhry', 'Samawia Moin', 'Adnan Khalil', 'Zeeshan Arshad', 'Haider Ali', 'Waqar Haider', 'Bilal Naeem', 'Muhammad Asad', 'Azeem Sajid', 'Maham Nazir', 'Abbas Sheikh'] spec.summary = "Module for the 'fog' gem to support Azure Blob Storage with CarrierWave and Fog." spec.description = "This is a stripped-down fork of fog-azure-rm that enables Azure Blob Storage to be used with CarrierWave and Fog." spec.files = `git ls-files`.split("\n") spec.test_files = `git ls-files -- {spec,tests}/*`.split("\n") spec.require_paths = %w[lib] spec.license = 'MIT' spec.homepage = 'https://gitlab.com/gitlab-org/gitlab-fog-azure-rm' spec.rdoc_options = %w[--charset=UTF-8] spec.extra_rdoc_files = %w[README.md] spec.required_ruby_version = '>= 2.7.0' spec.post_install_message = 'Thanks for installing!' spec.add_development_dependency 'codeclimate-test-reporter' , '~> 1.0.0' spec.add_development_dependency 'minitest', '~> 5.8.4' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rubocop', '~> 0.89.1' spec.add_development_dependency 'simplecov' spec.add_development_dependency 'webrick', '~> 1.8' spec.add_dependency 'azure-storage-blob', '~> 2.0' spec.add_dependency 'azure-storage-common', '~> 2.0' spec.add_dependency 'fog-core', '~> 2.1' spec.add_dependency 'fog-json', '~> 1.2' spec.add_dependency 'mime-types' end gitlab-fog-azure-rm-1.9.1/.rubocop.yml0000644000004100000410000000012514615741124017602 0ustar www-datawww-datainherit_from: .rubocop_todo.yml AllCops: NewCops: enable TargetRubyVersion: 2.7 gitlab-fog-azure-rm-1.9.1/CHANGELOG.md0000644000004100000410000002756414615741124017161 0ustar www-datawww-data## Unreleased ## 1.8.0 - Remove deprecated ms_rest_azure dependency (thanks to @jasoncodes) !38 ## 1.7.0 - Fix #get_object return type to be consistent with other Fog providers !36 - Require Ruby 2.7+ !36 ## 1.6.0 - Add get_object request method !34 - Fix uninitialized constant errors !35 ## 1.5.0 - Add delete_object request method !32 ## 1.4.0 - Move all top-level constants and functions to Fog::AzureRM !30 ## 1.3.0 - Fix Ruby 3.0 compatibility !27 ## 1.2.0 - Support setting returned Content-Disposition in GetBlob requests !25 ## 1.1.1 - Remove trailing periods per path segment when retrieving blob URLs !23 ## 1.1.0 - Yanked ## 1.0.1 - Fix URL generation for files with UTF-8 characters !21 ## 1.0.0 - Fix multipart uploads not working and drop multipart_save_block_blob !19 ## 0.9.0 - Fix TimeoutError deprecation !17 - Update Azure storage libraries !16 ## 0.8.1 - Fix `azure_storage_domain` not getting propagated properly !14 ## 0.8.0 - Add `azure_storage_domain` for specifying custom domain !11 ## 0.7.0 - Loosen mime-types version dependency !9 - Drop azure_mgmt_storage and other dependencies !8 ## 0.6.0 - Fix get_object_url !7 - Add get_object_url method !6 - Add support for copy_object !5 - Add support for DELETE blob !4 - Add support for PUT blobs !3 - Add and update Rubocop files !2 - Delete all code except blob storage-related functionality !1 ## 0.5.2 **Added** - Printing Information from `AzureOperationError` Response Headers ## 0.5.1 **Added** - Added Managed Disk Caching Option ## 0.5.0 **Added** - Asynchronous creation of Network Interface Card ## 0.4.9 **Added** - Current Ruby versions added in .travis.yml for testing - Asynchronous deletion of Managed Disk added **Changed** - List method which handles pagination by default has been updated for Network Security Group. - .travis.yml updated to handle bundler gem dependency on Ruby 2.3+ - Mocks for Azure::Blobs updated ## 0.4.8 **Added:** - Added enable_accelerated_networking attribute for NIC ## 0.4.7 **Added:** - Support added to list resources in a resource group - Added OS disk id attribute to the 'Compute' model ## 0.4.6 **Added:** - Created Custom Fog Exceptions ## 0.4.5 **Changed:** - Updated dependency of fog-json to (~> 1.0.2) ## 0.4.4 **Fixed:** - Compute Service - Fixed customData Update Issue ## 0.4.3 **Fixed:** - Compute Service - Fixed Server Update Scenario ## 0.4.2 **Fixed:** - Fixed 'raise_azure_exception' method ## 0.4.1 **Fixed:** - Fixed check existence methods for all resources - Fixed mime-types dependency issue ## 0.4.0 **Added** - Support added for custom vm image reference ## 0.3.9 **Changed** - Fixed Fog::Storage issue of requiring the 'mime-types' gem ## 0.3.8 **Changed:** - Updated documentation **Fixed:** - Compute Service - Fixed issue with fault/update domain not populating ## 0.3.7 **Fixed:** - DNS Service - Fixed bug in DNS service ## 0.3.6 **Added:** - Compute Service - Added support for custom image provisioning with managed disk - DNS Service - Fog Models for RecordSet Types 'A' and 'CNAME' - Automated gem publishing on release tagging **Changed:** - Loosened dependency on fog-core - Updated documentation ## 0.3.5 **Added:** - Compute Service - Added platform update domain and platform fault domain propertied in server model - Compute Service - Added custom image support for managed VM **Changed:** - Compute Service - Changed required arguments for server create method **Fixed** - Compute Service - Fixed issue with creating VM with custom image ## 0.3.4 **Added:** - Compute Service - Added support for custom OS disk size during VM creation - Compute Service - Added support to attach Managed Disk to VM - Added resource tagging support on creation **Removed:** - Recovery Vault Support ## 0.3.3 **Added:** - Compute Service - Added support to create availability set with managed disk support **Changed:** - Compute Service - Provided option to configure fault and update domain values - Removed dependency on Rest Client - azure-storage dependency fixed to 0.11.5.preview (to enable use with ruby 2.0.0) **Fixed:** - Unit tests - Storage and Compute ## 0.3.2 **Added:** - Compute Service - Made remaining server(virtual machine) methods async ## 0.3.1 **Changed:** - Updated azure storage gem dependency to be flexible ## 0.3.0 **Added** - Compute Service - Added support for Managed Disk - Compute Service - Added async method of creating server(virtual machine) **Changed:** - Compute Service - Changed create server method to take multiple NICs instead of one - Updated Azure SDK gems to v0.9.0 **Fixed:** - Integration tests ## 0.2.7 **Changed:** - Traffic Manager Service - Updated Traffic Manager Profile create method to receive and create Endpoints with it. **Fixed:** - Network Service - Fixed issue in check_virtual_network_exists request ## 0.2.6 **Fixed:** - Compute Service - storage_account_name attribute issue in server model - Network Service - Attaching NSG issue while creating NIC **Removed:** - Dependency on nokogiri ## 0.2.5 **Fixed:** - Fog Model enums proper namespacing ## 0.2.4 **Changed:** - Updated Fog model enums ## 0.2.3 **Added:** - Added Fog models for Azure SDK Enums **Changed** - Compute Service - Made 'password' attribute as optional to create linux virtual machine ## 0.2.2 **Changed:** - Network Service - Updated NIC for load balancer attributes ## 0.2.1 **Changed:** - Compute Service - Added new parameter to create virtual machine request ## 0.2.0 **Added:** - Added support for multiple environments - Added support to check for resource existence **Changed:** - Azure SQL Service - Updated Azure SQL Support to use azure_mgmt_sql gem. - Azure Network Service - Added list all request in Load Balancer and Virtual Network ## 0.1.2 **Added:** - Storage Service - Added support for multiple environments **Changed:** * Updated fog-azure-rm runtime gem dependencies to latest: * azure_mgmt_compute 0.8.0 * azure_mgmt_network 0.8.0 * azure_mgmt_resources 0.8.0 * azure_mgmt_storage 0.8.0 * azure_mgmt_dns 0.8.0 * azure_mgmt_traffic_manager 0.8.0 * azure-storage 0.11.4.preview' * Refactoring in Azure SQL ## 0.1.1 **Added:** - Storage Service - Multi-thread support for uploading blobs - Added support for all Azure locations(Global, China, Gov and Germany) **Changed:** * Updated fog-azure-rm runtime gem dependencies to latest: * azure_mgmt_compute 0.7.0 * azure_mgmt_network 0.7.0 * azure_mgmt_resources 0.7.0 * azure_mgmt_storage 0.7.0 * azure_mgmt_dns 0.7.0 * azure_mgmt_traffic_manager 0.7.0 * azure-storage 0.11.3.preview' * Provided same storage interfaces as other providers (PR: 204) * Updated Data Disk operations (PR: 220) * Updated namespaces * Updated integration scripts ## 0.1.0 **Added:** - Azure SQL Service - Added support for SQL Server Firewall Rules. - Azure Recovery Vault - Added support for Azure Recovery Vault. - Azure Storage Service - Encryption support for storage account and Added support to create new data disk. ## 0.0.9 **Added:** - Azure SQL Service - Added support for SQL Server, SQL Databases and Data warehouse. - Updated fog-azure-rm runtime gem dependencies to latest. **Changed:** - DNS Service - DNS Service moved from API calls to Azure latest SDK. ## 0.0.8 **Added:** - Compute Service - Added support to create virtual machine from a custom image. - Network Service - Added Network Security Rule. - Network Service - Added Get Available IP Addresses count in Subnet - Compute Service - Virtual Machine Extension - Added Blob count, blob exist, blob compare,blob copy, lease blob, release lease blob, delete blob, set blob properties, get blob properties, set blob metadata, get blob metadata, get blob, list blob functionality for storage - Added get container properties, get container metadata, set container metadata, get container, list container, delete container, Get the access control list of the container ## 0.0.6 **Added:** - Compute Service - Added Custom data support for creating Virtual Machine. - Network Service - Added Express Route Circuit Authorization. - Network Service - Added Virtual Network Gateway Connection support - Network Service - Added Local Network Gateway - Traffic Manager - Added support for Update Traffic Manager Profile and Endpoint. **Changed:** - Used autoload in place of require to avoid loading time issues - Used Fog DSL to register services ## 0.0.5 **Added:** - Network Service - Added Get request for Public IP - Network Service - Added Express Route Circuit - Network Service - Added VPN Gateway **Changed:** * Updated fog-azure-rm runtime gem dependencies to latest: * azure_mgmt_compute 0.5.0 * azure_mgmt_network 0.5.0 * azure_mgmt_resources 0.5.0 * azure_mgmt_storage 0.5.0 * azure_mgmt_traffic_manager 0.5.0 * rest-client 2.0.0 * fog-core 1.42.0 * Traffic Manager Service - Moved Traffic Manager from Network Service to Traffic Manager Service. * Application Gateway Service - Moved Application Gateway from Network Service to Application Gateway Service. ## 0.0.4 **Added:** - Storage Service - Added Support for Azure container operations - Storage Service - Added blob container metadata support - Storage Service - Added support to get storage access key - Network Service - Added support for updation methods for Network Security Group - Network Service - Added support for updation methods for Virtual Network(vnet) - Network Service - Added support for updation methods for Subnet - Network Service - Added support for updation methods for Network Interface Card(NIC) - Compute Service - Added support for azure resource manager templates - Resource Service - Added support to tag azure resources - Integration test scripts for all services - Documentation - Added fog structure information in contribution guide **Changed:** - Compute Service - Moved data disk model to storage service and updated unit tests - Compute Service - Loaded Data Disk model to make it accessible in Server model - Network Service - Support for internal load balancer and documentation update - Network Service - Improved subnet and virtual network module - Network Service - Updated unit test and integration test - Documentation - Changed delete_data_disk request name to delete_disk **Fixed:** - Resolved bugs in server.rb integration file **Removed:** - Compute Service - Moved data disk implementation to storage service ## 0.0.3 **Added:** - Compute Service: Support for Attach Data Disk & Detach Data Disk in Server - Compute Service: Support for Windows VM in create Server - Network Service - Application Gateway - Compute Service- check_vm_status method in Server as per: https://github.com/fog/fog-azure-rm/issues/38 - Badges in Readme.md file **Fixed:** - Code Climate Issues - Rubocop Offences - Compute service - Bug in Sever model as per: https://github.com/fog/fog-azure-rm/issues/36 - Network Service - Bug in Network Interface as per: https://github.com/fog/fog-azure-rm/issues/65 **Removed:** - Shindo Unit Tests **Integrated:** - Code Climate - Travis CI - Hound CI - Gemnasium - Waffle ## 0.0.2 **Added:** - Network Service - Network Security Group - Network Service - Load Balancer - Network Service - Traffic Manager - Minitest Unit Tests - DNS Requests - Response Parser: Compute, Network, DNS, Storage - Mock class implementation in all services **Changed:** - Response related changes in all services - Network Service - Subnet attributes names - Code standardization in all services ## 0.0.1 **Fixed:** - Network Service - Network Interface Card ## 0.0.0 **Added:** - Shindo Unit Tests - All - Minitest Unit Tests - Compute, Storage, Network, Resources, DNS Models - Documentation - All Services - Compute Service - Server - Compute Service - Availability Set - Network Service - Network Interface - Network Service - Subnet - Network Service - Virtual Network - Network Service - Public IP - Storage Service - Storage Account - Resource Service - Resource Manager - DNS Service - Record Set - DNS Service - Zone