Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(COR-1129): qovery demo up command set as origin 'API' in audit logs #402

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cmd/demo_scripts/create_qovery_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ QOVERY_API_URL=${QOVERY_API_URL:='https://api.qovery.com'}
CLUSTER_NAME=$1
ARCH=$2
ORGANIZATION_ID=$3
USER_AGENT=$6
case $3 in
qov_*)
AUTHORIZATION_HEADER="Authorization: Token $4"
Expand All @@ -29,10 +30,10 @@ esac
POWERSHELL_CMD='powershell.exe'

get_or_create_on_premise_account() {
accountId=$(curl -s --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/json' ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/onPremise/credentials | jq -r .results[0].id)
accountId=$(curl -s --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/json' -H "User-Agent: ${USER_AGENT}" ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/onPremise/credentials | jq -r .results[0].id)
if [ "$accountId" = "null" ]
then
accountId=$(curl -s -X POST --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/json' -d '{"name": "on-premise"}' ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/onPremise/credentials | jq -r .id)
accountId=$(curl -s -X POST --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/json' -H "User-Agent: ${USER_AGENT}" -d '{"name": "on-premise"}' ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/onPremise/credentials | jq -r .id)
fi

echo "$accountId"
Expand All @@ -41,20 +42,20 @@ get_or_create_on_premise_account() {
get_or_create_demo_cluster() {
accountId=$1
clusterName=$2
clusterId=$(curl -s -X GET --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/json' ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/cluster | jq -r '.results[] | select(.name=="'"$clusterName"'") | .id')
clusterId=$(curl -s -X GET --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/json' -H "User-Agent: ${USER_AGENT}" ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/cluster | jq -r '.results[] | select(.name=="'"$clusterName"'") | .id')

if [ "$clusterId" = "" ]
then
payload='{"name":"'$2'","region":"on-premise","cloud_provider":"ON_PREMISE","kubernetes":"SELF_MANAGED", "production": false, "is_demo": true, "features":[],"cloud_provider_credentials":{"cloud_provider":"ON_PREMISE","credentials":{"id":"'${accountId}'","name":"on-premise"},"region":"unknown"}}'
clusterId=$(curl -s -X POST --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/json' -d "${payload}" ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/cluster | jq -r .id)
clusterId=$(curl -s -X POST --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/json' -H "User-Agent: ${USER_AGENT}" -d "${payload}" ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/cluster | jq -r .id)
fi

echo "$clusterId"
}

get_cluster_values() {
clusterId=$1
curl -s -X GET --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/x-yaml' ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/cluster/"${clusterId}"/installationHelmValues
curl -s -X GET --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/x-yaml' -H "User-Agent: ${USER_AGENT}" ${QOVERY_API_URL}/organization/"${ORGANIZATION_ID}"/cluster/"${clusterId}"/installationHelmValues
}

get_or_create_cluster() {
Expand Down
5 changes: 3 additions & 2 deletions cmd/demo_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ var demoUpCmd = &cobra.Command{
os.Exit(1)
}

userAgent := "'CLI " + utils.Version+ "'"
cmdStr := `
set -eu
set -o pipefail
%s %s %s %s %s %t 2>&1 | tee %s
%s %s %s %s %s %t %s 2>&1 | tee %s
`
cmdArgs := fmt.Sprintf(cmdStr, scriptPath, demoClusterName, detectArchitecture(), string(orgId), string(token), demoDebug, debugLogsPath)
cmdArgs := fmt.Sprintf(cmdStr, scriptPath, demoClusterName, detectArchitecture(), string(orgId), string(token), demoDebug, userAgent, debugLogsPath)
shCmd := exec.Command("/bin/bash", "-c", cmdArgs)
shCmd.Stdout = os.Stdout
shCmd.Stderr = os.Stderr
Expand Down
Loading