From 0e2062128bbc4cd052f1b6e56f5fc89eb622ff76 Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 15 Aug 2024 22:44:50 -0700 Subject: [PATCH 1/2] client: plugins: refactor example plugin - Dynamically construct instance * Platform and tag should not be hard-coded - Add note regarding construction - Refactor main() --- client/plugins/docker/example.bash | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/client/plugins/docker/example.bash b/client/plugins/docker/example.bash index beb97a7..edafddb 100755 --- a/client/plugins/docker/example.bash +++ b/client/plugins/docker/example.bash @@ -38,8 +38,12 @@ [ -z "$DOCKER_FINANCE_CLIENT_REPO" ] && exit 1 source "${DOCKER_FINANCE_CLIENT_REPO}/client/src/docker/lib/lib_docker.bash" +[[ -z "$global_platform" || -z "$global_arg_delim_1" || -z "$global_user" || -z "$global_tag" ]] && lib_utils::die_fatal +instance="${global_platform}${global_arg_delim_1}${global_user}:${global_tag}" + # Initialize "constructor" -lib_docker::docker "archlinux/${USER}:default" +# NOTE: "constructor" only needed if calling library directly +lib_docker::docker "$instance" || lib_utils::die_fatal # # Implementation @@ -47,20 +51,16 @@ lib_docker::docker "archlinux/${USER}:default" function main() { - [ -z "$global_arg_delim_1" ] && exit 1 - [ -z "$global_arg_delim_2" ] && exit 1 - [ -z "$global_platform" ] && exit 1 - [ -z "$global_tag" ] && exit 1 - [ -z "$global_user" ] && exit 1 + [ -z "$global_arg_delim_2" ] && lib_utils::die_fatal - echo -e " + local -r _example=" This clients's environment: $(printenv | grep ^DOCKER_FINANCE | sort) -This plugin's caller image: +This plugin's caller instance: - "${global_platform}${global_arg_delim_1}${global_user}:${global_tag}" + $instance This plugin's path is: @@ -70,10 +70,11 @@ This plugin's arguments: '${*}' -Showing current version:" +Showing current version: +$(lib_docker::version type${global_arg_delim_2}short) - lib_docker::version type${global_arg_delim_2}short - echo +" + lib_utils::print_custom "$_example" } main "$@" From 9e8a448640dd9da222da22ffc51a72e1043e8f9f Mon Sep 17 00:00:00 2001 From: Aaron Fiore Date: Thu, 15 Aug 2024 23:43:00 -0700 Subject: [PATCH 2/2] client: plugins: catch lib_docker ctor (Tor plugin) - Catch if lib_docker constructor fails - Add note regarding construction --- client/plugins/docker/tor.bash | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/plugins/docker/tor.bash b/client/plugins/docker/tor.bash index 1a2f78f..fa65a6a 100755 --- a/client/plugins/docker/tor.bash +++ b/client/plugins/docker/tor.bash @@ -26,7 +26,10 @@ source "${DOCKER_FINANCE_CLIENT_REPO}/client/src/docker/lib/lib_docker.bash" [[ -z "$global_platform" || -z "$global_arg_delim_1" || -z "$global_user" || -z "$global_tag" ]] && lib_utils::die_fatal instance="${global_platform}${global_arg_delim_1}${global_user}:${global_tag}" -lib_docker::docker "$instance" # NOTE: "constructor" only needed if calling library directly + +# Initialize "constructor" +# NOTE: "constructor" only needed if calling library directly +lib_docker::docker "$instance" || lib_utils::die_fatal # # Implementation