Sha256: 169c681c973da460c858e30536dca37c6dfc22b68f99c255c773c17d539085fa

Contents?: true

Size: 1.37 KB

Versions: 5

Compression:

Stored size: 1.37 KB

Contents

module Legion::Extensions::Node::Runners
  module Vault
    def request_token(**)
      return {} if Legion::Settings[:crypt][:vault][:connected]
      return {} unless Legion::Settings[:crypt][:vault][:enabled]

      request_vault_token
    end

    def request_vault_token(**)
      Legion::Extensions::Node::Transport::Messages::RequestVaultToken.new.publish
      {}
    end

    def receive_vault_token(message:, **opts) # rubocop:disable Metrics/AbcSize
      return if Legion::Settings[:crypt][:vault][:connected]

      Legion::Settings[:crypt][:vault][:token] = Legion::Crypt.decrypt_from_keypair(message: message)
      %i[protocol address port].each do |setting|
        next unless opts.key? setting
        next unless Legion::Settings[:crypt][:vault][setting].nil?

        Legion::Settings[:crypt][:vault][setting] = opts[setting]
      end
      Legion::Crypt.connect_vault
      {}
    end

    def push_vault_token(public_key:, node_name:, **)
      return {} unless Legion::Settings[:crypt][:vault][:token]

      encrypted = Legion::Crypt.encrypt_from_keypair(message: Legion::Settings[:crypt][:vault][:token],
                                                     pub_key: public_key)
      Legion::Extensions::Node::Transport::Messages::PushVaultToken.new(token: encrypted, queue_name: node_name).publish
      {}
    end

    include Legion::Extensions::Helpers::Lex
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lex-node-0.2.0 lib/legion/extensions/node/runners/vault.rb
lex-node-0.1.7 lib/legion/extensions/node/runners/vault.rb
lex-node-0.1.6 lib/legion/extensions/node/runners/vault.rb
lex-node-0.1.5 lib/legion/extensions/node/runners/vault.rb
lex-node-0.1.4 lib/legion/extensions/node/runners/vault.rb