Skip to content

Commit

Permalink
cloud: Extract storage.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
spbnick committed Jan 15, 2024
1 parent e25b8fb commit 3d05545
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
26 changes: 1 addition & 25 deletions cloud
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PATH="$(dirname "$(realpath "$0")")/kcidb/cloud:$PATH"
. sections.sh
. bigquery.sh
. psql.sh
. storage.sh
. pubsub.sh
. firestore.sh
. cloud_functions.sh
Expand Down Expand Up @@ -67,31 +68,6 @@ function app_deploy() {
mute gcloud app create --quiet --project="$project" --region=us-central
}

# Deploy a Google Cloud Storage Bucket
# Args: project bucket
function storage_deploy() {
declare -r project="$1"; shift
declare -r bucket="$1"; shift
# Check if the bucket exists
if ! TMPDIR="$TMPDIR_ORIG" gsutil ls "gs://$bucket" &>/dev/null; then
# Create the bucket if it doesn't exist
TMPDIR="$TMPDIR_ORIG" gsutil -q mb -p "$project" -c STANDARD \
-l "us-central1" -b on "gs://$bucket"
fi
TMPDIR="$TMPDIR_ORIG" gsutil -q iam ch allUsers:objectViewer "gs://$bucket/"
}

# Remove a Google Cloud Storage Bucket and its contents
# Args: bucket
function storage_withdraw() {
declare -r bucket="$1"; shift
# Check if the bucket exists
if TMPDIR="$TMPDIR_ORIG" gsutil ls "gs://$bucket" &>/dev/null; then
# Remove the bucket and its contents if it exists
TMPDIR="$TMPDIR_ORIG" gsutil -q -m rm -r "gs://$bucket"
fi
}

# Execute a deploy/withdraw command
# Args: --command=NAME
# --format=yaml|sh
Expand Down
33 changes: 33 additions & 0 deletions kcidb/cloud/storage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# KCIDB cloud deployment - storage
#
if [ -z "${_STORAGE_SH+set}" ]; then
declare _STORAGE_SH=

. misc.sh

# Deploy a Google Cloud Storage Bucket
# Args: project bucket
function storage_deploy() {
declare -r project="$1"; shift
declare -r bucket="$1"; shift
# Check if the bucket exists
if ! TMPDIR="$TMPDIR_ORIG" gsutil ls "gs://$bucket" &>/dev/null; then
# Create the bucket if it doesn't exist
TMPDIR="$TMPDIR_ORIG" gsutil -q mb -p "$project" -c STANDARD \
-l "us-central1" -b on "gs://$bucket"
fi
TMPDIR="$TMPDIR_ORIG" gsutil -q iam ch allUsers:objectViewer "gs://$bucket/"
}

# Remove a Google Cloud Storage Bucket and its contents
# Args: bucket
function storage_withdraw() {
declare -r bucket="$1"; shift
# Check if the bucket exists
if TMPDIR="$TMPDIR_ORIG" gsutil ls "gs://$bucket" &>/dev/null; then
# Remove the bucket and its contents if it exists
TMPDIR="$TMPDIR_ORIG" gsutil -q -m rm -r "gs://$bucket"
fi
}

fi # _STORAGE_SH

0 comments on commit 3d05545

Please sign in to comment.