Sha256: 2a56f177a602ee01c989105fb9b7bc9a910d48556001011cf0a494bfd74594ea

Contents?: true

Size: 1.72 KB

Versions: 14

Compression:

Stored size: 1.72 KB

Contents

require "fog/core/collection"
require "fog/google/models/sql/operation"

module Fog
  module Google
    class SQL
      class Operations < Fog::Collection
        model Fog::Google::SQL::Operation

        ##
        # Lists all instance operations that have been performed on the given instance
        #
        # @param [String] instance_id Instance ID
        # @return [Array<Fog::Google::SQL::Operation>] List of instance operation resources
        def all(instance_id)
          data = []
          begin
            data = service.list_operations(instance_id).body["items"] || []
          rescue Fog::Errors::Error => e
            # Google SQL returns a 403 if we try to access a non-existing resource
            # The default behaviour in Fog is to return an empty Array
            raise e unless e.message == "The client is not authorized to make this request."
          end

          load(data)
        end

        ##
        # Retrieves an instance operation that has been performed on an instance
        #
        # @param [String] instance_id Instance ID
        # @param [String] operation_id Instance operation ID
        # @return [Fog::Google::SQL::Operation] Instance operation resource
        def get(instance_id, operation_id)
          if operation = service.get_operation(instance_id, operation_id).body
            new(operation)
          end
        rescue Fog::Errors::NotFound
          nil
        rescue Fog::Errors::Error => e
          # Google SQL returns a 403 if we try to access a non-existing resource
          # The default behaviour in Fog is to return a nil
          return nil if e.message == "The client is not authorized to make this request."
          raise e
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fog-google-0.6.0 lib/fog/google/models/sql/operations.rb
fog-google-0.5.5 lib/fog/google/models/sql/operations.rb
fog-google-0.5.4 lib/fog/google/models/sql/operations.rb
fog-google-0.5.3 lib/fog/google/models/sql/operations.rb
fog-google-0.5.2 lib/fog/google/models/sql/operations.rb
fog-google-0.5.1 lib/fog/google/models/sql/operations.rb
fog-google-0.5.0 lib/fog/google/models/sql/operations.rb
fog-google-0.4.2 lib/fog/google/models/sql/operations.rb
fog-google-0.4.1 lib/fog/google/models/sql/operations.rb
fog-google-0.4.0 lib/fog/google/models/sql/operations.rb
fog-google-0.3.2 lib/fog/google/models/sql/operations.rb
fog-google-0.3.1 lib/fog/google/models/sql/operations.rb
fog-google-0.3.0 lib/fog/google/models/sql/operations.rb
fog-google-0.2.0 lib/fog/google/models/sql/operations.rb