Skip to content

Commit

Permalink
cloud: Add check for bucket existence before creation
Browse files Browse the repository at this point in the history
  • Loading branch information
octonawish-akcodes authored and spbnick committed Jul 26, 2023
1 parent 2e6e038 commit ce4234c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cloud
Original file line number Diff line number Diff line change
Expand Up @@ -1257,16 +1257,24 @@ function pubsub_withdraw() {
function storage_deploy() {
declare -r project="$1"; shift
declare -r bucket="$1"; shift
TMPDIR="$TMPDIR_ORIG" gsutil -q mb -p "$project" -c STANDARD \
-l "us-central1" -b on "gs://$bucket"
# 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 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
TMPDIR="$TMPDIR_ORIG" gsutil -q -m rm -r "gs://$bucket"
# 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
}

# Deploy a Cloud Function
Expand Down

0 comments on commit ce4234c

Please sign in to comment.