Sha256: 106d4ab9f58659621fe74bb37eea8beff342faef25232d46deb91785073209f1

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

module Jellyfish
  module Fog
    module AWS
      class Storage < Jellyfish::Provisioner
        def provision
          instance_name = "id-#{order_item.uuid[0..9]}"
          begin
            storage = connection.directories.create(key: instance_name, public: true)
          rescue Excon::Errors::BadRequest, Excon::Errors::Forbidden => e
            raise e, 'Bad request. Check for valid credentials and proper permissions.', e.backtrace
          end

          order_item.payload_response = storage.to_json
          order_item.provision_status = 'ok'
        end

        def retire
          connection.delete_bucket(storage_key)
          order_item.provision_status = 'retired'
        rescue Excon::Errors::BadRequest, Excon::Errors::Forbidden => e
          raise e, 'Bad request. Check for valid credentials and proper permissions.', e.backtrace
        end

        private

        def connection
          ::Fog::Storage.new(Jellyfish::Fog::AWS.aws_settings.merge(provider: 'AWS'))
        end

        def storage_key
          order_item.payload_response['key']
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jellyfish_fog_aws-0.3.0 lib/jellyfish_fog_aws/storage.rb
jellyfish_fog_aws-0.2.2 lib/jellyfish_fog_aws/storage.rb
jellyfish_fog_aws-0.2.1 lib/jellyfish_fog_aws/storage.rb
jellyfish_fog_aws-0.2.0 lib/jellyfish_fog_aws/storage.rb
jellyfish_fog_aws-0.1.1 lib/jellyfish_fog_aws/storage.rb