Skip to content

Commit

Permalink
fix(certmanager): handle issues reported by CodeQL (#160)
Browse files Browse the repository at this point in the history
* fix(certmanager): avoid implicit string concat in a list

* refactor(certmanager): remove variable that defined multiple times

* refactor(certmanager): parse passed options
  • Loading branch information
iromli authored Dec 23, 2021
1 parent b993f41 commit 407fee8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
37 changes: 15 additions & 22 deletions docker-jans-certmanager/scripts/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import logging.config
from contextlib import suppress

import click

Expand Down Expand Up @@ -31,6 +32,16 @@
}


def _parse_opts(opts):
parsed_opts = {}
for opt in opts:
with suppress(ValueError):
k, v = opt.split(":", 1)
if k and v:
parsed_opts[k] = v
return parsed_opts


# ============
# CLI commands
# ============
Expand Down Expand Up @@ -61,18 +72,9 @@ def patch(service, dry_run, opts):
logger.warning("Dry-run mode is enabled!")

logger.info(f"Processing updates for service {service}")

_opts = {}
for opt in opts:
try:
k, v = opt.split(":", 1)
_opts[k] = v
except ValueError:
k = opt
v = ""

parsed_opts = _parse_opts(opts)
callback_cls = PATCH_SERVICE_MAP[service]
callback_cls(manager, dry_run, **_opts).patch()
callback_cls(manager, dry_run, **parsed_opts).patch()


@cli.command()
Expand All @@ -93,18 +95,9 @@ def prune(service, dry_run, opts):
logger.warning("Dry-run mode is enabled!")

logger.info(f"Processing updates for service {service}")

_opts = {}
for opt in opts:
try:
k, v = opt.split(":", 1)
_opts[k] = v
except ValueError:
k = opt
v = ""

parsed_opts = _parse_opts(opts)
callback_cls = PRUNE_SERVICE_MAP[service]
callback_cls(manager, dry_run, **_opts).prune()
callback_cls(manager, dry_run, **parsed_opts).prune()


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion docker-jans-certmanager/scripts/client_api_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def generate_keystore(cert_file, key_file, keystore_file, keystore_password):

def _patch_connector(self, conn_type):
suffix = f"client_api_{conn_type}"
cert_file, key_file = f"{suffix}.crt", f"{suffix}.key"
cert_cn = self.opts.get(f"{conn_type}-cn", "localhost")

cert_file, key_file = self.generate_x509(suffix, cert_cn)
Expand Down
2 changes: 1 addition & 1 deletion docker-jans-certmanager/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def export_openid_keys(keystore, keypasswd, alias, export_file):
cmd = " ".join([
"java",
"-Dlog4j.defaultInitOverride=true",
"-cp /app/javalibs/*"
"-cp /app/javalibs/*",
"io.jans.as.client.util.KeyExporter",
"-keystore {}".format(keystore),
"-keypasswd {}".format(keypasswd),
Expand Down

0 comments on commit 407fee8

Please sign in to comment.