From ebedffb14ccf87a4404cc82edd817aa965fbea0c Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sat, 17 Dec 2022 00:33:34 +0100 Subject: [PATCH] Clone cleaning and configure CI to run tests --- .pylintrc | 3 +++ .woodpecker.yml | 13 +++++++++++++ updateMemberOf | 30 +++++++++++++++++++----------- 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 .pylintrc create mode 100644 .woodpecker.yml diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..c305092 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,3 @@ +[MESSAGES CONTROL] +disable=consider-using-f-string, + invalid-name, diff --git a/.woodpecker.yml b/.woodpecker.yml new file mode 100644 index 0000000..f0b938a --- /dev/null +++ b/.woodpecker.yml @@ -0,0 +1,13 @@ +pipeline: + test-pylint: + group: test + image: pipelinecomponents/pylint + commands: + - pip install https://gitea.zionetrix.net/bn8/python-mylib.git + - pylint check_ceph_usage + + test-flake8: + group: test + image: pipelinecomponents/flake8 + commands: + - flake8 check_ceph_usage diff --git a/updateMemberOf b/updateMemberOf index fa9f90c..9e92df4 100755 --- a/updateMemberOf +++ b/updateMemberOf @@ -1,6 +1,8 @@ #!/usr/bin/python - -""" Tool to force update memberOf attributes of users on OpenLDAP directory using memberOf overlay """ +""" +Tool to force update memberOf attributes of users on OpenLDAP directory using +memberOf overlay +""" import getpass import logging @@ -15,7 +17,8 @@ default_host = 'ldapi:///' default_filter = '(objectClass=posixGroup)' default_attr = 'uniqueMember' -parser = get_opts_parser(desc="Update memberOf attributes", just_try=True, progress=True) +parser = get_opts_parser( + desc="Update memberOf attributes", just_try=True, progress=True) # options ldap_opts = parser.add_argument_group('LDAP options') @@ -69,11 +72,11 @@ ldap_opts.add_argument( ) ldap_opts.add_argument( '-a', '--attr', - action="store", - type=str, - dest="attr", - help="Group members attribute (default: %s)" % default_attr, - default=default_attr + action="store", + type=str, + dest="attr", + help="Group members attribute (default: %s)" % default_attr, + default=default_attr ) options = parser.parse_args() @@ -86,13 +89,17 @@ init_logging(options, "Update memberOf") if options.dn and not options.pwd: options.pwd = getpass.getpass() + class MyLdapClient(LdapClient): """ Implement a custom LdapClient to handle group objects """ - def __init__(self, scripts_options): # pylint: disable=super-init-not-called + # pylint: disable=super-init-not-called + def __init__(self, scripts_options): self.options = scripts_options logging.info(u"Connect to LDAP server %s", self.options.host) - self.cnx = LdapServer(self.options.host, dn=self.options.dn, pwd=self.options.pwd, v2=self.options.ldapv2) + self.cnx = LdapServer( + self.options.host, dn=self.options.dn, pwd=self.options.pwd, + v2=self.options.ldapv2) self.cnx.connect() def get_groups(self): @@ -101,7 +108,7 @@ class MyLdapClient(LdapClient): 'group', self.options.filter, self.options.base, - [ self.options.attr ] + [self.options.attr] ) def touch_group_members(self, obj): @@ -121,6 +128,7 @@ class MyLdapClient(LdapClient): return myldap.update_object(obj, changes) return False + # Start LDAP connection myldap = MyLdapClient(options) groups = myldap.get_groups()