Sha256: 22b83a941482989df1e95236afe9ce473017d11a71d665e46737d0b18776f751

Contents?: true

Size: 1.6 KB

Versions: 41

Compression:

Stored size: 1.6 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).items || []
            data = data.map(&:to_h)
          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] operation_id Instance operation ID
        # @return [Fog::Google::SQL::Operation] Instance operation resource
        def get(operation_id)
          if operation = service.get_operation(operation_id).to_h
            new(operation)
          end
        rescue ::Google::Apis::ClientError => 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
          raise e unless e.status_code == 404 || e.status_code == 403
          nil
        end
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
fog-google-1.24.1 lib/fog/google/models/sql/operations.rb
fog-google-1.24.0 lib/fog/google/models/sql/operations.rb
fog-google-1.23.0 lib/fog/google/models/sql/operations.rb
fog-google-1.22.0 lib/fog/google/models/sql/operations.rb
fog-google-1.21.1 lib/fog/google/models/sql/operations.rb
fog-google-1.21.0 lib/fog/google/models/sql/operations.rb
fog-google-1.20.0 lib/fog/google/models/sql/operations.rb
fog-google-1.19.0 lib/fog/google/models/sql/operations.rb
fog-google-1.18.0 lib/fog/google/models/sql/operations.rb
fog-google-1.17.0 lib/fog/google/models/sql/operations.rb
fog-google-1.16.1 lib/fog/google/models/sql/operations.rb
fog-google-1.16.0 lib/fog/google/models/sql/operations.rb
fog-google-1.15.0 lib/fog/google/models/sql/operations.rb
fog-google-1.14.0 lib/fog/google/models/sql/operations.rb
gitlab-fog-google-1.14.0 lib/fog/google/models/sql/operations.rb
fog-google-1.13.0 lib/fog/google/models/sql/operations.rb
gitlab-fog-google-1.13.0 lib/fog/google/models/sql/operations.rb
fog-google-1.12.1 lib/fog/google/models/sql/operations.rb
fog-google-1.12.0 lib/fog/google/models/sql/operations.rb
fog-google-1.11.0 lib/fog/google/models/sql/operations.rb