From e5613d9a3051ba0d4cc76c366ffb7519422ca0ac Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Mon, 2 Oct 2023 14:57:41 -0600 Subject: [PATCH 1/5] Update Dockerfile and `magellan.sh` for container --- Dockerfile | 8 +++--- bin/magellan.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 7 deletions(-) mode change 100644 => 100755 bin/magellan.sh diff --git a/Dockerfile b/Dockerfile index f5d7b65..d5232d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,15 @@ FROM cgr.dev/chainguard/wolfi-base -RUN apk add --no-cache tini +RUN apk add --no-cache tini bash # nobody 65534:65534 USER 65534:65534 -COPY magellan / +COPY magellan /magellan +COPY bin/magellan.sh /usr/bin/magellan.sh -CMD [ "/magellan" ] + +CMD [ "/magellan.sh" ] ENTRYPOINT [ "/sbin/tini", "--" ] diff --git a/bin/magellan.sh b/bin/magellan.sh old mode 100644 new mode 100755 index 0850f87..8d1744d --- a/bin/magellan.sh +++ b/bin/magellan.sh @@ -1,17 +1,78 @@ +#!/bin/bash + +EXE=./magellan +SUBNETS="" +PORTS="" +USER="" +PASS="" +ARGS="" + function build(){ - go mod tidy && go build -C bin/magellan + go mod tidy && go build -C bin/magellan } function scan() { - ./magellan scan --subnet 172.16.0.0 --port 443 + # ./magellan scan --subnet 172.16.0.0 --port 443 + ${EXE} scan --subnet ${SUBNETS} --port ${PORTS} } function list(){ - ./magellan list + # ./magellan list + ${EXE} list } function collect() { - ./magellan collect --user admin --pass password + # ./magellan collect --user admin --pass password + ${EXE} collect --user ${USER} --pass ${PASS} } + +# parse incoming arguments to set variables +while [[ $# -gt 0 ]]; do + case $1 in + --subnet) + SUBNETS="$2" + shift # past argument + shift # past value + ;; + -p|--port) + PORTS="$2" + shift # past argument + shift # past value + ;; + --user) + USER="$2" + shift # past argument + shift # past value + ;; + --pass|--password) + PASS="$2" + shift + shift + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + ARGS+=("$1") # save positional arg + shift # past argument + ;; + esac +done + +set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters + +echo "subnets = ${SUBNETS}" +echo "ports = ${PORTS}" +echo "user = ${USER}" +echo "pass = ..." + +if [[ -n $1 ]]; then + echo "Last line of file specified as non-opt/last argument:" + tail -1 "$1" +fi + +scan +collect \ No newline at end of file From b730e98fb3464f54d41783d9a386d6fe9d247708 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Mon, 2 Oct 2023 15:37:27 -0600 Subject: [PATCH 2/5] Fixed issue with `AddRedfishEndpoint` returning nil --- internal/api/smd/smd.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/api/smd/smd.go b/internal/api/smd/smd.go index a8369ea..76f518b 100644 --- a/internal/api/smd/smd.go +++ b/internal/api/smd/smd.go @@ -51,6 +51,9 @@ func AddRedfishEndpoint(data []byte, headers map[string]string) error { // Add redfish endpoint via POST `/hsm/v2/Inventory/RedfishEndpoints` endpoint url := makeEndpointUrl("/Inventory/RedfishEndpoints") res, body, err := util.MakeRequest(url, "POST", data, headers) + if res == nil { + return fmt.Errorf("no response") + } fmt.Printf("smd url: %v\n", url) fmt.Printf("res: %v\n", res.Status) fmt.Printf("body: %v\n", string(body)) @@ -69,6 +72,9 @@ func UpdateRedfishEndpoint(xname string, data []byte, headers map[string]string) // Update redfish endpoint via PUT `/hsm/v2/Inventory/RedfishEndpoints` endpoint url := makeEndpointUrl("/Inventory/RedfishEndpoints/" + xname) res, body, err := util.MakeRequest(url, "PUT", data, headers) + if res == nil { + return fmt.Errorf("no response") + } fmt.Printf("smd url: %v\n", url) fmt.Printf("res: %v\n", res.Status) fmt.Printf("body: %v\n", string(body)) From 7a99aa5b2dc906654833e40402997345d0764089 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Mon, 2 Oct 2023 15:42:06 -0600 Subject: [PATCH 3/5] Exposed more parameters in `magellan.sh` script --- bin/magellan.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/magellan.sh b/bin/magellan.sh index 8d1744d..585e457 100755 --- a/bin/magellan.sh +++ b/bin/magellan.sh @@ -5,6 +5,9 @@ SUBNETS="" PORTS="" USER="" PASS="" +SMD_HOST="" +THREADS="-1" +TIMEOUT="30" ARGS="" @@ -14,7 +17,7 @@ function build(){ function scan() { # ./magellan scan --subnet 172.16.0.0 --port 443 - ${EXE} scan --subnet ${SUBNETS} --port ${PORTS} + ${EXE} scan --subnet ${SUBNETS} --port ${PORTS} --host ${SMD_HOST} --timeout ${TIMEOUT} --threads ${THREADS} } function list(){ @@ -24,7 +27,7 @@ function list(){ function collect() { # ./magellan collect --user admin --pass password - ${EXE} collect --user ${USER} --pass ${PASS} + ${EXE} collect --user ${USER} --pass ${PASS} --timeout ${TIMEOUT} --threads ${THREADS} } @@ -51,6 +54,21 @@ while [[ $# -gt 0 ]]; do shift shift ;; + --smd-host) + SMD_HOST="$2" + shift + shift + ;; + --timeout) + TIMEOUT="$2" + shift + shift + ;; + --threads) + THREADS="$2" + shift + shift + ;; -*|--*) echo "Unknown option $1" exit 1 From 69374a29e8dca30423cd1bc0c0b98fce007597e0 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Tue, 3 Oct 2023 12:21:52 -0600 Subject: [PATCH 4/5] Fixed argument passed to wrong command --- bin/magellan.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/magellan.sh b/bin/magellan.sh index 585e457..e81a90b 100755 --- a/bin/magellan.sh +++ b/bin/magellan.sh @@ -17,7 +17,7 @@ function build(){ function scan() { # ./magellan scan --subnet 172.16.0.0 --port 443 - ${EXE} scan --subnet ${SUBNETS} --port ${PORTS} --host ${SMD_HOST} --timeout ${TIMEOUT} --threads ${THREADS} + ${EXE} scan --subnet ${SUBNETS} --port ${PORTS} --timeout ${TIMEOUT} --threads ${THREADS} } function list(){ @@ -27,7 +27,7 @@ function list(){ function collect() { # ./magellan collect --user admin --pass password - ${EXE} collect --user ${USER} --pass ${PASS} --timeout ${TIMEOUT} --threads ${THREADS} + ${EXE} collect --user ${USER} --pass ${PASS} --timeout ${TIMEOUT} --threads ${THREADS} --host ${SMD_HOST} } From c2567a0b569b55d3ec226040710a3491aa0f9b12 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Tue, 3 Oct 2023 12:26:51 -0600 Subject: [PATCH 5/5] Added SMD port option for docker --- bin/magellan.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/magellan.sh b/bin/magellan.sh index e81a90b..4c34a82 100755 --- a/bin/magellan.sh +++ b/bin/magellan.sh @@ -6,6 +6,7 @@ PORTS="" USER="" PASS="" SMD_HOST="" +SMD_PORT="" THREADS="-1" TIMEOUT="30" ARGS="" @@ -27,7 +28,7 @@ function list(){ function collect() { # ./magellan collect --user admin --pass password - ${EXE} collect --user ${USER} --pass ${PASS} --timeout ${TIMEOUT} --threads ${THREADS} --host ${SMD_HOST} + ${EXE} collect --user ${USER} --pass ${PASS} --timeout ${TIMEOUT} --threads ${THREADS} --host ${SMD_HOST} --port ${SMD_PORT} } @@ -59,6 +60,11 @@ while [[ $# -gt 0 ]]; do shift shift ;; + --smd-port) + SMD_PORT="$2" + shift + shift + ;; --timeout) TIMEOUT="$2" shift @@ -82,6 +88,8 @@ done set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters +echo "SMD host = ${SMD_HOST}" +echo "SMD port = ${SMD_PORT}" echo "subnets = ${SUBNETS}" echo "ports = ${PORTS}" echo "user = ${USER}"