Skip to content

Commit 4a46fc8

Browse files
committed
accounts_ssh_authorized_keys_line_parser: Output regex matches when sshkey format isnt correct
1 parent ea2f809 commit 4a46fc8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/puppet/functions/accounts_ssh_authorized_keys_line_parser.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717

1818
def accounts_ssh_authorized_keys_line_parser_string(str)
1919
matched = str.match(%r{((sk-ssh-ed25519|sk-ecdsa-|ssh-|ecdsa-)[^\s]+)\s+([^\s]+)\s+(.*)$})
20-
raise ArgumentError, 'Wrong Keyline format!' unless matched && matched.length == 5
20+
21+
raise ArgumentError, "Wrong Keyline format! Got nil after applying regex to'#{str}'" unless matched
22+
unless matched.length == 5
23+
output = []
24+
# first element is str, aftwerwards are all matching groups. We ignore the first element
25+
(1..matched.length).each do |counter|
26+
output << "element #{counter}: #{matched[counter]}"
27+
end
28+
raise ArgumentError, "Wrong Keyline format! Input: #{str}. Expected 4 elements after applying regex, got: #{output}"
29+
end
2130

2231
options = str[0, str.index(matched[0])].rstrip
2332
[options, matched[1], matched[3], matched[4]]

0 commit comments

Comments
 (0)