github.com/redhat-appstudio/e2e-tests@v0.0.0-20230619105049-9a422b2094d7/scripts/spi-e2e-setup.sh (about) 1 #!/bin/bash 2 # exit immediately when a command fails 3 set -e 4 # only exit with zero if all commands of the pipeline exit successfully 5 set -o pipefail 6 # error on unset variables 7 set -u 8 VAULT_NAMESPACE=${VAULT_NAMESPACE:-spi-vault} 9 VAULT_PODNAME=${VAULT_PODNAME:-vault-0} 10 11 echo '[INFO] Deploying SPI OAuth2 config' 12 13 export OAUTH_URL='spi-oauth-route-spi-system.'$( oc get ingresses.config/cluster -o jsonpath={.spec.domain}) 14 export tmpfile=$(mktemp -d)/config.yaml 15 16 # We are injecting the token manually for the e2e. No need a real secret for now 17 export SPI_GITHUB_CLIENT_ID=${SPI_GITHUB_CLIENT_ID:-"app-client-id"} 18 export SPI_GITHUB_CLIENT_SECRET=${SPI_GITHUB_CLIENT_SECRET:-"app-secret"} 19 export SPI_QUAY_CLIENT_ID=${SPI_QUAY_CLIENT_ID:-"app-client-id"} 20 export SPI_QUAY_CLIENT_SECRET=${SPI_QUAY_CLIENT_SECRET:-"app-secret"} 21 22 # The legacy stuff can be removed once https://github.com/redhat-appstudio/infra-deployments/pull/638 is merged 23 # in infra-deployments 24 legacySpiConfig=$(cat <<EOF 25 sharedSecret: $(openssl rand -hex 20) 26 serviceProviders: 27 - type: GitHub 28 clientId: $SPI_GITHUB_CLIENT_ID 29 clientSecret: $SPI_GITHUB_CLIENT_SECRET 30 - type: Quay 31 clientId: $SPI_QUAY_CLIENT_ID 32 clientSecret: $SPI_QUAY_CLIENT_SECRET 33 baseUrl: https://spi-oauth-route-spi-system.$( oc get ingresses.config/cluster -o jsonpath={.spec.domain}) 34 EOF 35 ) 36 37 spiConfig=$(cat <<EOF 38 sharedSecret: $(openssl rand -hex 20) 39 serviceProviders: 40 - type: GitHub 41 clientId: $SPI_GITHUB_CLIENT_ID 42 clientSecret: $SPI_GITHUB_CLIENT_SECRET 43 - type: Quay 44 clientId: $SPI_QUAY_CLIENT_ID 45 clientSecret: $SPI_QUAY_CLIENT_SECRET 46 EOF 47 ) 48 49 echo "Please go to https://github.com/settings/developers." 50 echo "And register new Github OAuth application for callback https://"$OAUTH_URL"/github/callback" 51 52 oc create namespace spi-system --dry-run=client -o yaml | oc apply -f - 53 54 # legacy config file 55 echo "$legacySpiConfig" > "$tmpfile" 56 oc create secret generic oauth-config \ 57 --save-config --dry-run=client \ 58 --from-file="$tmpfile" \ 59 -n spi-system \ 60 -o yaml | 61 oc apply -f - 62 63 # new-form config file 64 echo "$spiConfig" > "$tmpfile" 65 oc create secret generic shared-configuration-file \ 66 --save-config --dry-run=client \ 67 --from-file="$tmpfile" \ 68 -n spi-system \ 69 -o yaml | 70 oc apply -f - 71 72 rm "$tmpfile" 73 74 curl https://raw.githubusercontent.com/redhat-appstudio/service-provider-integration-operator/main/hack/vault-init.sh | VAULT_PODNAME=${VAULT_PODNAME} VAULT_NAMESPACE=${VAULT_NAMESPACE} bash -s 75 76 oc rollout restart deployment/spi-controller-manager -n spi-system 77 oc rollout restart deployment/spi-oauth-service -n spi-system