From 769ef925e4e07e1e7217356f56dee50171a7b52f Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 6 Sep 2018 18:55:53 +0200 Subject: [PATCH] TT#37257 NGCP::Template::Object: Add new ngcp.get_ssh_pub_key function To be able to generate an authorized_keys file from templates we need to fetch the public ssh keys for the root user. This function will make this task easier. Change-Id: If8edef0e77a5f3c1167fe8dfd0e92e4d9e468a6a --- lib/NGCP/Template/Object.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/NGCP/Template/Object.pm b/lib/NGCP/Template/Object.pm index 7a0a920e..253621e1 100644 --- a/lib/NGCP/Template/Object.pm +++ b/lib/NGCP/Template/Object.pm @@ -150,6 +150,21 @@ sub get_mgmt_node return; } +sub get_ssh_pub_key +{ + my ($self, $key_type) = @_; + + my $ssh_keys_dir = '/etc/ngcp-config/shared-files/ssh/'; + my $ssh_key_file = "$ssh_keys_dir/id_${key_type}.pub"; + open my $fh, '<', $ssh_key_file or die "Error opening $ssh_key_file"; + my $ssh_pub_key = <$fh>; + close $fh; + chomp $ssh_pub_key; + die "Fatal error retrieving SSH public key" unless length $ssh_pub_key; + + return $ssh_pub_key; +} + 1; __END__ @@ -210,6 +225,11 @@ Returns the name of the management node calling this function. Returns the NGCP management node shared name. +=item $ssh_pub_keye = $t->get_ssh_pub_key($key_type) + +Returns the SSH public key with $key_type ('rsa', 'ed25519', etc.) from +the ngcpcfg shared-files storage. + =back =head1 AUTHOR