Sha256: 9dda164629d194a06bf7df4ed3410a0994bdb26745516a9b3cf3ecbb15081040

Contents?: true

Size: 989 Bytes

Versions: 8

Compression:

Stored size: 989 Bytes

Contents

# frozen_string_literal: true

require 'ruby_vault'

module RakeVault
  module Auth
    module Approle
      def self.login(address, path, role_id, secret_id)
        role_id = role_id ? "role_id=#{role_id}" : nil
        secret_id = secret_id ? "secret_id=#{secret_id}" : nil

        stdout_io = StringIO.new

        configure_stdout(stdout_io)
        write(address, path, role_id, secret_id)
        reset_stdout
        RakeVault::TokenFile.write(stdout_io.string)
      end

      def self.write(address, path, role_id, secret_id)
        RubyVault.write(
          address: address,
          path: path,
          data: [role_id, secret_id].compact,
          format: 'json'
        )
      end

      def self.configure_stdout(stdout_io)
        RubyVault.configure do |config|
          config.stdout = stdout_io
        end
      end

      def self.reset_stdout
        RubyVault.configure do |config|
          config.stdout = $stdout
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rake_vault-0.3.0.pre.4 lib/rake_vault/auth/approle.rb
rake_vault-0.3.0.pre.3 lib/rake_vault/auth/approle.rb
rake_vault-0.3.0.pre.2 lib/rake_vault/auth/approle.rb
rake_vault-0.3.0.pre.1 lib/rake_vault/auth/approle.rb
rake_vault-0.2.0 lib/rake_vault/auth/approle.rb
rake_vault-0.1.0.pre.14 lib/rake_vault/auth/approle.rb
rake_vault-0.1.0.pre.13 lib/rake_vault/auth/approle.rb
rake_vault-0.1.0.pre.12 lib/rake_vault/auth/approle.rb