Sha256: 21d0ba57e7588a9584093363c7f990cbe33bd1dbb1330282cc9c1b2803ed4acb

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

module Fog
  module Sql
    class AzureRM
      # Real class for Sql Database Request
      class Real
        def get_database(resource_group, server_name, name)
          msg = "Getting Sql Database: #{name} in Resource Group: #{resource_group}."
          Fog::Logger.debug msg
          resource_url = "#{AZURE_RESOURCE}/subscriptions/#{@subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Sql/servers/#{server_name}/databases/#{name}?api-version=2014-04-01-preview"
          begin
            token = Fog::Credentials::AzureRM.get_token(@tenant_id, @client_id, @client_secret)
            response = RestClient.get(
              resource_url,
              accept: :json,
              content_type: :json,
              authorization: token
            )
          rescue MsRestAzure::AzureOperationError => e
            raise_azure_exception(e, JSON.parse(e.response)['message'])
          end
          Fog::Logger.debug "Sql Database fetched successfully in Resource Group: #{resource_group}"
          JSON.parse(response)
        end
      end

      # Mock class for Sql Database Request
      class Mock
        def get_database(*)
          {
            'location' => '{database-location}',
            'properties' => {
              'createMode' => '{creation-mode}',
              'sourceDatabaseId' => '{source-database-id}',
              'edition' => '{database-edition}',
              'collation' => '{collation-name}',
              'maxSizeBytes' => '{max-database-size}',
              'requestedServiceObjectiveId' => '{requested-service-id}',
              'requestedServiceObjectiveName' => '{requested-service-id}',
              'restorePointInTime' => '{restore-time}',
              'sourceDatabaseDeletionDate' => '{source-deletion-date}',
              'elasticPoolName' => '{elastic-pool-name}'
            }
          }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-azure-rm-0.0.9 lib/fog/azurerm/requests/sql/get_database.rb