aboutsummaryrefslogtreecommitdiffstats
path: root/modules/openssh/templates
diff options
context:
space:
mode:
authorOlivier Blin <dev@blino.org>2017-02-23 01:29:21 +0100
committerOlivier Blin <dev@blino.org>2017-02-23 01:52:38 +0100
commitbbf66681a90a588a288cb0d2a812e7a8ba0706ba (patch)
tree5acf1578aef8a8cbc44878af0ff9c49f977c1464 /modules/openssh/templates
parentf662c03552bf595f7fce3dd5d49b1e7a5b116b01 (diff)
downloadpuppet-bbf66681a90a588a288cb0d2a812e7a8ba0706ba.tar
puppet-bbf66681a90a588a288cb0d2a812e7a8ba0706ba.tar.gz
puppet-bbf66681a90a588a288cb0d2a812e7a8ba0706ba.tar.bz2
puppet-bbf66681a90a588a288cb0d2a812e7a8ba0706ba.tar.xz
puppet-bbf66681a90a588a288cb0d2a812e7a8ba0706ba.zip
ldap-sshkey2file.py: use argparse for options parsing and usage
Diffstat (limited to 'modules/openssh/templates')
-rwxr-xr-xmodules/openssh/templates/ldap-sshkey2file.py31
1 files changed, 15 insertions, 16 deletions
diff --git a/modules/openssh/templates/ldap-sshkey2file.py b/modules/openssh/templates/ldap-sshkey2file.py
index f01a3fbf..7c41832d 100755
--- a/modules/openssh/templates/ldap-sshkey2file.py
+++ b/modules/openssh/templates/ldap-sshkey2file.py
@@ -5,6 +5,8 @@ import os
import random
import shutil
import tempfile
+import argparse
+import textwrap
try:
import ldap
@@ -29,18 +31,19 @@ nslcd_conf_file="<%= nslcd_conf_file %>"
filter="(&(objectClass=inetOrgPerson)(objectClass=ldapPublicKey)(objectClass=posixAccount)(sshPublicKey=*))"
keypathprefix='/home'
-def usage():
- print "%s" % sys.argv[0]
- print
- print "Will fetch all enabled user accounts under %s" % peopledn
- print "with ssh keys in them and write each one to"
- print "%s/<login>/.ssh/authorized_keys" % keypathprefix
- print
- print "It will return failure when no keys are updated and success"
- print "when one or more keys have changed."
- print
- print "This script is intended to be run from cron as root"
- print
+parser = argparse.ArgumentParser(
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ description=textwrap.dedent('''\
+ Will fetch all enabled user accounts under %s
+ with ssh keys in them and write each one to
+ %s/<login>/.ssh/authorized_keys
+
+ It will return failure when no keys are updated and success
+ when one or more keys have changed.
+
+ This script is intended to be run from cron as root;
+ ''' % (peopledn, keypathprefix)))
+args = parser.parse_args()
def get_bindpw():
try:
@@ -134,10 +137,6 @@ def write_keys(keys, user, uid, gid):
return True
-if len(sys.argv) != 1:
- usage()
- sys.exit(1)
-
bindpw = get_bindpw()
changed = False