Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create repsetdata script #111

Open
wants to merge 14 commits into
base: sel-rep-codi
Choose a base branch
from
73 changes: 73 additions & 0 deletions repsetdata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

kmacinnis marked this conversation as resolved.
Show resolved Hide resolved
OUTPUT_NAME="variables-by-replication-set-$(date +"%Y_%m_%d_%I_%M_%s").csv"
SELECT_STATEMENT=$(cat <<EOF
SELECT
RTRIM(LTRIM(REPLACE(CAST(replication_sets AS varchar), '{}', 'Full' ), '{'),'}') AS "ReplicationSets",
imheresamir marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replication_sets column is of the format {repset1,repset2,repset3}

Since the script outputs a CSV, we may want to confirm that if a variable belongs to multiple replication sets, the output does not get mangled if each replication set is considered a separate column.

Copy link

@adamouamani adamouamani Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imheresamir We looked at this yesterday and multiple replication sets will be in a single column. However that was before we removed the leading or trailing { }. I'll let @kmacinnis confirm and check if this will causes issue..

Copy link
Contributor

@imheresamir imheresamir Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local testing results in the following:

ReplicationSets,Policy,Variable
"follower1,follower2",default:policy:root,vault-synchronizer/lob-1/safe-1/variable-1

Which could be ok depending on requirements. I would expect there to be separate lines for each replication set for each variable belonging to multiple replication sets, like this:

ReplicationSet,Policy,Variable
follower1,default:policy:root,vault-synchronizer/lob-1/safe-1/variable-1
follower2,default:policy:root,vault-synchronizer/lob-1/safe-1/variable-1

That way the ReplicationSet column can be filtered in Excel.

policy_id AS "Policy",
account(resource_id) as "Account",
kind(resource_id) as "Kind",
identifier(resource_id) as "Variable"
FROM resources
WHERE policy_id NOT LIKE 'system%'
AND resource_id LIKE '%:variable:%'
ORDER BY replication_sets, resource_id ASC
EOF
)

parse_parameters() {
POSITIONAL_ARGS=()

while [[ $# -gt 0 ]]; do
case "${1:-}" in
--podman)
CONTAINERS_PLATFORM="podman"
shift ;;
--docker)
CONTAINERS_PLATFORM="docker"
shift ;;
-h | --help ) print_help
shift ;;
--) shift;
break
;;
-*|--*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
if [ ${#POSITIONAL_ARGS[@]} -eq 1 ]; then
CONTAINER_NAME=${POSITIONAL_ARGS[0]}
kmacinnis marked this conversation as resolved.
Show resolved Hide resolved
else
echo "There must be exacly one positional argument. Run $0 for more information."
imheresamir marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
}

print_help() {
cat <<EOF
Runs the acceptance tests for the appliance.
Usage: repsetdata.sh <appliance-container> [options]
--podman Indicates container is Podman
kmacinnis marked this conversation as resolved.
Show resolved Hide resolved
-h, --help Shows this help message.
EOF
exit
}


main() {
parse_parameters "$@"
CONTAINERS_PLATFORM="${CONTAINERS_PLATFORM:-docker}"
CONTAINER_NAME="${CONTAINER_NAME:-ERROR}"
"$CONTAINERS_PLATFORM" exec --user conjur "$CONTAINER_NAME" psql -c "COPY ($SELECT_STATEMENT) TO STDOUT CSV HEADER" > $OUTPUT_NAME && {
echo "Saved to $OUTPUT_NAME"
}
kmacinnis marked this conversation as resolved.
Show resolved Hide resolved
}


main "$@"