#!/usr/bin/env bash
set -euo pipefail

ROOT=$(cd $(dirname ${BASH_SOURCE[0]})/.. && pwd)

CLUSTER=${CLUSTER:-base}
PROVIDER_TYPE=${PROVIDER_TYPE:-eks}

usage() {
cat << EOF
"""
Setup a test environment for the monitoring stack
Mock some dependencies
"""
EOF
}

V1=${1:-""}
if [ "${V1}" == "--help" ];then
    usage
    exit
fi

yarn install
export PULUMI_CONFIG_PASSPHRASE="test"
export MOCK_STACK="true"
export REGION="us-west-1"
export CLUSTER=${CLUSTER}
export PROVIDER_TYPE=${PROVIDER_TYPE}
# thanos required AWS credencials, just disable it in local mode.
export NO_DEPLOY_THANOS="true"
# aws eks describe-cluster --name dev-base-us-west-2 --query "cluster.identity.oidc.issuer" --output text
export OIDC_PROVIDER="https://oidc.eks.us-west-2.amazonaws.com/id/000BD46AE9B425477A559A1381C535C0"

pulumi config set monitoring:env dev
pulumi config set monitoring:infra-stack test
pulumi config set monitoring:pagerduty_key test
pulumi config set monitoring:slack_url test
pulumi config set monitoring:datadog_apikey test
pulumi config set monitoring:oauth-proxy-client-secret test --secret
pulumi config set aws:region us-west-2
pulumi config set aws:gardener-project-name nightly
pulumi config set monitoring:portalAuth0Issuer "https://tidb-dev.us.auth0.com/"
pulumi config set monitoring:portalClientID "Z9mfdhVe0Nh3ylm6gr7OkwSUGLfToiux"
pulumi config set monitoring:grafanaAuth0ClientSecret test --secret
pulumi config set monitoring:grafanaAuth0ClientId test
pulumi config set aws_es_pwd test --secret
pulumi config set aws_es_host test
pulumi config set slowQueryTiDBDatabase test
pulumi config set slowQueryTiDBHost test
pulumi config set slowQueryTiDBPassword test --secret
pulumi config set slowQueryTiDBUser test
pulumi config set slowQueryTiDBCA test --secret
pulumi config set slowQueryTiDBCert test --secret
pulumi config set slowQueryTiDBKey test --secret

# pulumi oauth-proxy component will try get ingress loadbalancer hostname, it will failed in local env.
# but we can enable it just for generate yaml file.
# pulumi config set monitoring:oauth-proxy-client-ID test
# pulumi config set monitoring:oauth-proxy-cookie-secret test

exec "$@"
