diff options
author | Bobosila Victor <victor.bobosila@puppet.com> | 2021-10-04 12:16:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-04 12:16:24 +0300 |
commit | efd4d1b3213336c4f7f4a04fb5075a0ce1682fa6 (patch) | |
tree | 3fd2f83f284b673ea19187b395101e1663171cf8 /lib/puppet | |
parent | 9a54482d64ef21e8b6b1063845a96b1a72cd8f3c (diff) | |
parent | b2565ef72fd744e31cc3e3836dc5b69e193fa88c (diff) | |
download | puppet-sshkeys_core-efd4d1b3213336c4f7f4a04fb5075a0ce1682fa6.tar.gz puppet-sshkeys_core-efd4d1b3213336c4f7f4a04fb5075a0ce1682fa6.tar.bz2 |
Merge pull request #48 from GabrielNagy/MODULES-11197/pdk-update
(MODULES-11197) Update to pdk-templates 2.2.0
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/type/ssh_authorized_key.rb | 22 | ||||
-rw-r--r-- | lib/puppet/type/sshkey.rb | 16 |
2 files changed, 20 insertions, 18 deletions
diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb index 9749e29..701dfe5 100644 --- a/lib/puppet/type/ssh_authorized_key.rb +++ b/lib/puppet/type/ssh_authorized_key.rb @@ -2,16 +2,17 @@ require 'puppet/parameter/boolean' module Puppet Type.newtype(:ssh_authorized_key) do - @doc = "Manages SSH authorized keys. Currently only type 2 keys are supported. + @doc = "@summary Manages SSH authorized keys. Currently only type 2 keys are supported. In their native habitat, SSH keys usually appear as a single long line, in the format `<TYPE> <KEY> <NAME/COMMENT>`. This resource type requires you - to split that line into several attributes. Thus, a key that appears in - your `~/.ssh/id_rsa.pub` file like this... + to split that line into several attributes. + + @example Thus, a key that appears in your `~/.ssh/id_rsa.pub` file like this... ssh-rsa AAAAB3Nza[...]qXfdaQ== nick@magpie.example.com - ...would translate to the following resource: + @example ...would translate to the following resource: ssh_authorized_key { 'nick@magpie.example.com': ensure => present, @@ -21,8 +22,9 @@ module Puppet } To ensure that only the currently approved keys are present, you can purge - unmanaged SSH keys on a per-user basis. Do this with the `user` resource - type's `purge_ssh_keys` attribute: + unmanaged SSH keys on a per-user basis. + + @example Do this with the `user` resource type's `purge_ssh_keys` attribute: user { 'nick': ensure => present, @@ -86,7 +88,7 @@ module Puppet the `name` attribute/resource title." validate do |value| - raise Puppet::Error, _('Key must not contain whitespace: %{value}') % { value: value } if value =~ %r{\s} + raise Puppet::Error, _('Key must not contain whitespace: %{value}') % { value: value } if %r{\s}.match?(value) end end @@ -110,10 +112,10 @@ module Puppet return nil unless resource[:user] begin - return File.expand_path("~#{resource[:user]}/.ssh/authorized_keys") + File.expand_path("~#{resource[:user]}/.ssh/authorized_keys") rescue Puppet.debug 'The required user is not yet present on the system' - return nil + nil end end @@ -169,7 +171,7 @@ module Puppet sk-ecdsa-sha2-nistp256@openssh.com|sk-ssh-ed25519@openssh.com| ssh-rsa-cert-v01@openssh.com|ssh-ed25519-cert-v01@openssh.com| ssh-dss-cert-v01@openssh.com|ecdsa-sha2-nistp256-cert-v01@openssh.com| - ecdsa-sha2-nistp384-cert-v01@openssh.com|ecdsa-sha2-nistp521-cert-v01@openssh.com)\s+([^ ]+)\s*(.*)$}x + ecdsa-sha2-nistp384-cert-v01@openssh.com|ecdsa-sha2-nistp521-cert-v01@openssh.com)\s+([^ ]+)\s*(.*)$}x.freeze def self.keyline_regex REGEX end diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb index 6e603a2..11d6cef 100644 --- a/lib/puppet/type/sshkey.rb +++ b/lib/puppet/type/sshkey.rb @@ -1,10 +1,10 @@ module Puppet Type.newtype(:sshkey) do - @doc = "Installs and manages ssh host keys. By default, this type will - install keys into `/etc/ssh/ssh_known_hosts`. To manage ssh keys in a - different `known_hosts` file, such as a user's personal `known_hosts`, - pass its path to the `target` parameter. See the `ssh_authorized_key` - type to manage authorized keys." + @doc = "@summary Installs and manages ssh host keys. + By default, this type will install keys into `/etc/ssh/ssh_known_hosts`. + To manage ssh keys in a different `known_hosts` file, such as a user's personal + `known_hosts`, pass its path to the `target` parameter. See the + `ssh_authorized_key` type to manage authorized keys." ensurable @@ -82,10 +82,10 @@ module Puppet end validate do |value| - if value =~ %r{\s} + if %r{\s}.match?(value) raise Puppet::Error, _('Aliases cannot include whitespace') end - if value =~ %r{,} + if %r{,}.match?(value) raise Puppet::Error, _('Aliases must be provided as an array, not a comma-separated list') end end @@ -97,7 +97,7 @@ module Puppet isnamevar validate do |value| - raise Puppet::Error, _('Resourcename cannot include whitespaces') if value =~ %r{\s} + raise Puppet::Error, _('Resourcename cannot include whitespaces') if %r{\s}.match?(value) raise Puppet::Error, _('No comma in resourcename allowed. If you want to specify aliases use the host_aliases property') if value.include?(',') end end |