Sha256: 3b5a93c6db0a8cf830d4ed88b8c1c74917d433d76cd1ccdd03a985d51b30cc8d

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

# typed: true
# frozen_string_literal: true

module Workato
  module Testing
    class VCREncryptedCassetteSerializer < ActiveSupport::EncryptedFile
      def initialize
        super(
          content_path: '',
          key_path: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_PATH,
          env_key: Workato::Connector::Sdk::DEFAULT_MASTER_KEY_ENV,
          raise_if_missing_key: true
        )
      end

      def file_extension
        'enc'
      end

      def serialize(hash)
        ::Dir::Tmpname.create('vcr_cassette') do |tmp_path|
          @content_path = Pathname.new(tmp_path)
        end
        write(YAML.dump(hash))
        File.binread(content_path)
      ensure
        File.unlink(content_path) if content_path.exist?
        @content_path = ''
      end

      def deserialize(string)
        ::Dir::Tmpname.create('vcr_cassette') do |tmp_path|
          @content_path = Pathname.new(tmp_path)
        end
        File.write(@content_path, string)
        ::YAML.safe_load(read).presence || {}
      ensure
        File.unlink(content_path) if content_path.exist?
        @content_path = ''
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
workato-connector-sdk-1.2.0 lib/workato/testing/vcr_encrypted_cassette_serializer.rb
workato-connector-sdk-1.0.3 lib/workato/testing/vcr_encrypted_cassette_serializer.rb
workato-connector-sdk-1.1.0 lib/workato/testing/vcr_encrypted_cassette_serializer.rb
workato-connector-sdk-1.0.2 lib/workato/testing/vcr_encrypted_cassette_serializer.rb