Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions apisnoop.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/usr/bin/env bash

# Our main command line script
DEFAULT_SOURCE="./data-gen/sources.yaml"
DEFAULT_CACHE="./data-gen/cache"
DEFAULT_DEST="./data-gen/processed"
DEFAULT_GCS_PREFIX="gs://apisnoop/dev/"
APISNOOP_SOURCE=${APISNOOP_SOURCE:-"./data-gen/sources.yaml"}
APISNOOP_CACHE=${APISNOOP_CACHE:-"./data-gen/cache"}
APISNOOP_DEST=${APISNOOP_DEST:-"./data-gen/processed"}
APISNOOP_GCS_PREFIX=${APISNOOP_GCS_PREFIX:-"gs://apisnoop/dev/"}

print_help() {
cat << EOF
Usage: apisnoop [parameters]
This utility can fetch and process Kubernetes audit logs.
By default:
source is $DEFAULT_SOURCE
cache is $DEFAULT_CACHE
destination is $DEFAULT_DEST
gcs_prefix is $DEFAULT_GCS_PREFIX
source is $APISNOOP_SOURCE
cache is $APISNOOP_CACHE
destination is $APISNOOP_DEST
gcs_prefix is $APISNOOP_GCS_PREFIX
Defaults can be overwritten with optional arguments.

Parameters:
Expand All @@ -26,6 +26,16 @@ Parameters:
--process-cache Process raw audit-logs and save apiusage results to disk
--upload-apiusage Upload apiusage results to a gcs bucket
--download-apiusage Download apiusage results from gcs bucket

Enironment Variables:
=======

APISNOOP_SOURCE Current value: ${APISNOOP_SOURCE}
APISNOOP_CACHE Current value: ${APISNOOP_CACHE}
APISNOOP_DEST Current value: ${APISNOOP_DEST}
APISNOOP_GCS_PREFIX Current value: ${APISNOOP_GCS_PREFIX}


EOF
}

Expand All @@ -36,23 +46,23 @@ elif [ $1 = "--install" ]; then
elif [ $1 = "--update-sources" ]; then
./data-gen/updateSources.py ./data-gen/sources.yaml
elif [ $1 = "--update-cache" ]; then
./data-gen/downloadArtifacts.py ${2:-$DEFAULT_SOURCE} ${3:-$DEFAULT_CACHE}
./data-gen/downloadArtifacts.py ${2:-$APISNOOP_SOURCE} ${3:-$APISNOOP_CACHE}
elif [ $1 = "--process-cache" ]; then
./data-gen/processArtifacts.py ${2:-$DEFAULT_CACHE} ${3:-$DEFAULT_DEST} > ./data-gen/processArtifacts.sh
./data-gen/processArtifacts.py ${2:-$APISNOOP_CACHE} ${3:-$APISNOOP_DEST} > ./data-gen/processArtifacts.sh
bash ./data-gen/processArtifacts.sh
elif [ $1 = "--upload-apiusage" ]; then
cd $DEFAULT_DEST
gsutil -m cp -R -n ./ $DEFAULT_GCS_PREFIX
cd $APISNOOP_DEST
gsutil -m cp -R -n ./ $APISNOOP_GCS_PREFIX
elif [ $1 = "--download-apiusage" ]; then
mkdir -p $DEFAULT_DEST
gsutil -m cp -R -n $DEFAULT_GCS_PREFIX $DEFAULT_DEST
mkdir -p $APISNOOP_DEST
gsutil -m cp -R -n $APISNOOP_GCS_PREFIX $APISNOOP_DEST
elif [ $1 = "--all" ]; then
echo "Installing necessary dependendies"
echo "Installing necessary dependencies"
pip install -r ./data-gen/requirements.txt
echo "Fetching latest artifacts"
./data-gen/downloadArtifacts.py ${2:-$DEFAULT_SOURCE} ${3:-$DEFAULT_CACHE}
./data-gen/downloadArtifacts.py ${2:-$APISNOOP_SOURCE} ${3:-$APISNOOP_CACHE}
echo "Generating shell script to process artifacts"
./data-gen/processArtifacts.py ${3:-$DEFAULT_CACHE} ${4:-$DEFAULT_DEST} > ./data-gen/processArtifacts.sh
./data-gen/processArtifacts.py ${3:-$APISNOOP_CACHE} ${4:-$APISNOOP_DEST} > ./data-gen/processArtifacts.sh
echo "Processing Artifacts"
bash ./data-gen/processArtifacts.sh
else
Expand Down