#/bin/bash

# Creates the service account for alert-to-pubsub.

set -e -x
source ../kube/config.sh
source ../bash/ramdisk.sh

# New service account we will create. Name must be the same for all clusters
# that alert-to-pubsub runs in.
SA_NAME=skia-alert-to-pubsub

cd /tmp/ramdisk

gcloud iam service-accounts create "${SA_NAME}" --display-name="alert-to-pubsub service account."

gcloud beta iam service-accounts keys create ${SA_NAME}.json --iam-account="${SA_NAME}@${PROJECT_SUBDOMAIN}.iam.gserviceaccount.com"

gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
  --member "serviceAccount:${SA_NAME}@${PROJECT_SUBDOMAIN}.iam.gserviceaccount.com" \
  --role roles/pubsub.editor

kubectl create secret generic "${SA_NAME}" --from-file=key.json=${SA_NAME}.json

cd -

#/bin/bash

# Creates the service account for alert-to-pubsub.

set -e -x
source ../kube/config.sh

# New service account we will create. Name must be the same for all clusters
# that alert-to-pubsub runs in.
SA_NAME=skia-alert-to-pubsub

gcloud iam service-accounts create "${SA_NAME}" --display-name="alert-to-pubsub service account."

gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
  --member "serviceAccount:${SA_NAME}@${PROJECT_SUBDOMAIN}.iam.gserviceaccount.com" \
  --role roles/pubsub.editor

gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
  --member "serviceAccount:${SA_NAME}@${PROJECT_SUBDOMAIN}.iam.gserviceaccount.com" \
  --role roles/logging.logWriter
Add logWriter permissions to alert-to-pubsub SA
Add logWriter permissions to alert-to-pubsub SA

This also removes the process of creating a k8s secret from JSON.

Change-Id: I7b5383e9e95334c3dd301887bb61d519e799b492
Bug: skia:12320
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/444366
Reviewed-by: Joe Gregorio <b9cf2471ff6d33504cafe8e6f356b732b2cadced@google.com>
