From 90a7b665f34199c9d1bfb37f620a7bbe3bd98077 Mon Sep 17 00:00:00 2001
From: Massimiliano Adamo <maxadamo@gmail.com>
Date: Sat, 19 Nov 2022 02:52:38 +0100
Subject: [PATCH] add message for atomic check

---
 wile_coyote/bin/anvil           | 2 +-
 wile_coyote/bin/cert2json       | 2 +-
 wile_coyote/tools/__init__.py   | 1 +
 wile_coyote/tools/consul_kit.py | 5 +++--
 wile_coyote/tools/redis_kit.py  | 5 +++--
 wile_coyote/tools/vault_kit.py  | 5 +++--
 6 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/wile_coyote/bin/anvil b/wile_coyote/bin/anvil
index a2e0e35..7c06ee3 100755
--- a/wile_coyote/bin/anvil
+++ b/wile_coyote/bin/anvil
@@ -1,4 +1,4 @@
-#!/usr/bin/env python3
+#!/usr/bin/python3
 """Anvil,
    wile_coyote test tool, erases, uploads and checks certificates
    validity onto test instances of Vault, Redis and Consul.
diff --git a/wile_coyote/bin/cert2json b/wile_coyote/bin/cert2json
index 1a76da2..bb55abb 100755
--- a/wile_coyote/bin/cert2json
+++ b/wile_coyote/bin/cert2json
@@ -22,7 +22,7 @@ from docopt import docopt
 import wile_coyote.tools
 
 
-PROCESSES=6
+PROCESSES = 6
 WEB_BASE = REDIS_HOST = wile_coyote.tools.WEB_BASE
 ARGS = docopt(__doc__)
 PROVIDER = ARGS['--provider']
diff --git a/wile_coyote/tools/__init__.py b/wile_coyote/tools/__init__.py
index 342dac5..94f862e 100644
--- a/wile_coyote/tools/__init__.py
+++ b/wile_coyote/tools/__init__.py
@@ -12,6 +12,7 @@ for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
 
     config = configparser.RawConfigParser()
     config.read(wile_coyote.common.constants.CRED_CONF, encoding="utf8")
+    ATOMIC_MSG = 'Atomic Check: '
     VAULT_HOST = config.get('acme', 'vault_host')
     REDIS_HOST = config.get('acme', 'redis_host')
     REDIS_TOKEN = config.get('acme', 'redis_token')
diff --git a/wile_coyote/tools/consul_kit.py b/wile_coyote/tools/consul_kit.py
index b4a9245..693fc03 100644
--- a/wile_coyote/tools/consul_kit.py
+++ b/wile_coyote/tools/consul_kit.py
@@ -79,6 +79,7 @@ def put(key, value, log_file, leader):
 
 def test(log_file, leader):
     """ Check consul connection """
+    ATOMIC_CHECK = wile_coyote.tools.ATOMIC_MSG
     token = wile_coyote.tools.CONSUL_TOKEN
     rnd = ''.join([random.choice(string.ascii_letters) for _ in range(8)])
     c_client = Consul(host=leader, port='443', token=token, scheme='https')
@@ -86,9 +87,9 @@ def test(log_file, leader):
     try:
         _ = c_client.kv.put('do_not_delete', rnd)
     except Exception as err:
-        log.handler(f'could not write test key to {leader}: {err}',
+        log.handler(f'{ATOMIC_CHECK}could not write test key to {leader}: {err}',
                     log_file, True)
         log.handler(wile_coyote.common.constants.GIVEUP, log_file)
         os._exit(1)
     else:
-        log.handler(f'successfully wrote Consul test key to {leader}', log_file)
+        log.handler(f'{ATOMIC_CHECK}successfully wrote Consul test key to {leader}', log_file)
diff --git a/wile_coyote/tools/redis_kit.py b/wile_coyote/tools/redis_kit.py
index 020e8d9..a22cfcb 100644
--- a/wile_coyote/tools/redis_kit.py
+++ b/wile_coyote/tools/redis_kit.py
@@ -54,6 +54,7 @@ def save(log_file):
 
 def test(log_file):
     """ Check Redis connection """
+    ATOMIC_CHECK = wile_coyote.tools.ATOMIC_MSG
     host = wile_coyote.tools.REDIS_HOST
     token = wile_coyote.tools.REDIS_TOKEN
     rnd = ''.join([random.choice(string.ascii_letters) for _ in range(8)])
@@ -62,9 +63,9 @@ def test(log_file):
     try:
         _ = r_client.set('do_not_delete', rnd)
     except Exception as err:
-        log.handler(f'could not write test key to {host}: {err}',
+        log.handler(f'{ATOMIC_CHECK}could not write test key to {host}: {err}',
                     log_file, True)
         log.handler('giving up...', log_file)
         os._exit(1)
     else:
-        log.handler(f'successfully wrote Redis test key to {host}', log_file)
+        log.handler(f'{ATOMIC_CHECK}successfully wrote Redis test key to {host}', log_file)
diff --git a/wile_coyote/tools/vault_kit.py b/wile_coyote/tools/vault_kit.py
index aa0c74f..4452810 100644
--- a/wile_coyote/tools/vault_kit.py
+++ b/wile_coyote/tools/vault_kit.py
@@ -79,6 +79,7 @@ def put_v2(key, value, log_file, unit='nomad', mount_point='nomad'):
 
 def test(log_file):
     """ Check Vault connection """
+    ATOMIC_CHECK = wile_coyote.tools.ATOMIC_MSG
     disable_warnings(InsecureRequestWarning)  # pylint: disable=E1101
     host = wile_coyote.tools.VAULT_HOST
     token = wile_coyote.tools.config.get('acme', f'vault_token_puppet')
@@ -89,9 +90,9 @@ def test(log_file):
     try:
         _ = v_client.write(key_name, value=rnd)
     except Exception as err:  # pylint: disable=w0703
-        log.handler(f'could not write key {key_name} to Vault {host}: {err}',
+        log.handler(f'{ATOMIC_CHECK}could not write key {key_name} to Vault {host}: {err}',
                     log_file, True)
         log.handler(wile_coyote.common.constants.GIVEUP, log_file)
         os._exit(1)
     else:
-        log.handler(f'successfully wrote Vault test key to {host}', log_file)
+        log.handler(f'{ATOMIC_CHECK}successfully wrote Vault test key to {host}', log_file)
-- 
GitLab