From d15897319dc396f3f7e3cc8a5b40b40ffad24a35 Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sun, 18 Jun 2023 20:55:19 +1000 Subject: [PATCH] Setup pre-commit * resolved issues with data/template.yaml * resolved issues with enc.py --- .pre-commit-config.yaml | 25 +++++++++++++++++++++++++ data/template.yaml | 24 +++++++++++++++--------- enc.py | 15 +++++++++------ 3 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..826662f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,25 @@ +repos: + - repo: 'https://github.com/adrienverge/yamllint' + rev: v1.32.0 + hooks: + - id: 'yamllint' + - repo: https://github.com/psf/black + rev: 23.3.0 + hooks: + - id: black + language_version: python3.7 + + - repo: https://github.com/PyCQA/flake8 + rev: 6.0.0 + hooks: + - id: flake8 + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + + # - repo: https://github.com/pre-commit/mirrors-mypy + # rev: v1.3.0 + # hooks: + # - id: mypy diff --git a/data/template.yaml b/data/template.yaml index f1c6087..9f2ca91 100644 --- a/data/template.yaml +++ b/data/template.yaml @@ -1,4 +1,19 @@ --- +# In this example, parameter1 and parameter2 are parameters for +# the role::puppet::puppetmaster class, while global_parameter1 +# and global_parameter2 are global variables that will be available +# in your Puppet manifests as $::global_parameter1 and $::global_parameter2. +# +# The parameters key sets top-level variables which are accessible in all +# classes. The parameters under the classes key are parameters specific to +# those classes. +# +# You can adapt this template to set any class parameters or global +# variables you need. +# +# Please note that for Puppet 5 or later, you can access the global +# variables without the leading :: like so: $global_parameter1. However, +# the leading :: is needed for compatibility with Puppet 4. classes: role::puppet::puppetmaster: parameter1: value1 @@ -7,12 +22,3 @@ parameters: global_parameter1: value3 global_parameter2: value4 environment: production - - - # In this example, parameter1 and parameter2 are parameters for the role::puppet::puppetmaster class, while global_parameter1 and global_parameter2 are global variables that will be available in your Puppet manifests as $::global_parameter1 and $::global_parameter2. - # - # The parameters key sets top-level variables which are accessible in all classes. The parameters under the classes key are parameters specific to those classes. - # - # You can adapt this template to set any class parameters or global variables you need. - # - # Please note that for Puppet 5 or later, you can access the global variables without the leading :: like so: $global_parameter1. However, the leading :: is needed for compatibility with Puppet 4. diff --git a/enc.py b/enc.py index b6a9c50..55217ed 100755 --- a/enc.py +++ b/enc.py @@ -1,20 +1,22 @@ #!/usr/bin/env python import sys + import yaml + def main(): # Get the hostname from the command line arguments if len(sys.argv) != 2: - print('Usage: {} '.format(sys.argv[0]), file=sys.stderr) + print("Usage: {} ".format(sys.argv[0]), file=sys.stderr) sys.exit(1) hostname = sys.argv[1] # Construct the file path - file_path = '/opt/puppetlabs/enc/data/{}.yaml'.format(hostname) + file_path = "/opt/puppetlabs/enc/data/{}.yaml".format(hostname) # Try to open and read the YAML file try: - with open(file_path, 'r') as f: + with open(file_path, "r") as f: file_content = f.read() try: # Parse the YAML file @@ -22,11 +24,12 @@ def main(): # If correctly parsed, print the raw content print(file_content) except yaml.YAMLError as e: - print('Error in {}: {}'.format(file_path, e), file=sys.stderr) + print("Error in {}: {}".format(file_path, e), file=sys.stderr) sys.exit(1) except IOError as e: - print('Could not open {}: {}'.format(file_path, e), file=sys.stderr) + print("Could not open {}: {}".format(file_path, e), file=sys.stderr) sys.exit(1) -if __name__ == '__main__': + +if __name__ == "__main__": main()