Sha256: 181ce88af4f08009c91617b0f1a5a228952bd1672d9cee0e008dbe41d1699a75

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module VagrantPlugins
  module GuestVyOS
    module Cap
      class InsertPublicKey
        def self.insert_public_key(machine, contents)
          contents = contents.chomp

          key_type, key_value, key_name = contents.split()

          commands = <<-EOS
if [ "$(id -g -n)" != 'vyattacfg' ] ; then
  exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@"
fi
source /opt/vyatta/etc/functions/script-template
set system login user vagrant authentication public-keys #{key_name} type #{key_type}
set system login user vagrant authentication public-keys #{key_name} key #{key_value}
commit
save
          EOS

          temp = Tempfile.new("vagrant")
          temp.binmode
          temp.write(commands)
          temp.close

          machine.communicate.tap do |comm|
            comm.upload(temp.path, "/tmp/vagrant-insert-public-key")
            comm.execute("bash /tmp/vagrant-insert-public-key")
            comm.execute("rm -f /tmp/vagrant-insert-public-key")
          end

          temp.unlink

        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-vyos-1.1.2 lib/vagrant-vyos/cap/insert_public_key.rb