-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds scripts and charts updates that enable MAS deployments
Signed-off-by: Milton Moura <[email protected]>
- Loading branch information
Showing
7 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
charts/matrix-meetings-bot/files/shell-tools/create_bot_account_mas.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#/bin/sh | ||
set -x; | ||
|
||
while [ $(curl -k -sw '%{http_code}' "$HOMESERVER" -o /dev/null) -ne 302 ]; do | ||
sleep 1; | ||
done | ||
|
||
# Get Static Client Access Token | ||
ACCESS_TOKEN=$(curl -k -s \ | ||
-u "$MAS_CLIENT_ID:$MAS_CLIENT_SECRET" \ | ||
-d "grant_type=client_credentials&scope=urn:mas:admin" \ | ||
$MAS_URL/oauth2/token | grep -o '"access_token":"[^"]*"' | sed 's/"access_token":"\([^"]*\)"/\1/') | ||
|
||
echo "Bot User:\t$USERTOCREATE" | ||
|
||
# Create User | ||
USER_ID=$(curl -X POST -k -s \ | ||
-d "{\"username\": \"$USERTOCREATE\"}" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $ACCESS_TOKEN" \ | ||
$MAS_URL/api/admin/v1/users | grep -o '"id":"[^"]*"' | sed 's/"id":"\([^"]*\)"/\1/') | ||
|
||
if [ -n "$USER_ID" ] && [ "$USER_ID" != "null" ]; then | ||
echo "Bot User ID:\t$USER_ID" | ||
else | ||
echo "Error or user $USERTOCREATE already exists." | ||
return 1 | ||
fi | ||
|
||
export USER_ID | ||
|
||
# Set Password | ||
SET_PASSWORD_RESPONSE=$(curl -X POST -k -s \ | ||
-d "{\"password\": \"$BOT_PASSWORD\", \"skip_password_check\": true}" \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $ACCESS_TOKEN" \ | ||
$MAS_URL/api/admin/v1/users/$USER_ID/set-password) | ||
|
||
if [ -z "$SET_PASSWORD_RESPONSE" ]; then | ||
echo "Set-Password:\tsuccess" | ||
else | ||
echo "Set-Password:\t$SET_PASSWORD_RESPONSE" | ||
fi |
32 changes: 32 additions & 0 deletions
32
charts/matrix-meetings-bot/files/shell-tools/get_meetings_bot_token_mas.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#/bin/sh | ||
|
||
# Get Static Client Access Token | ||
ACCESS_TOKEN=$(curl -k -s \ | ||
-u "$MAS_CLIENT_ID:$MAS_CLIENT_SECRET" \ | ||
-d "grant_type=client_credentials&scope=urn:mas:admin urn:mas:graphql:*" \ | ||
$MAS_URL/oauth2/token | grep -o '"access_token":"[^"]*"' | sed 's/"access_token":"\([^"]*\)"/\1/') | ||
|
||
# Get Persistent Token | ||
TOKEN_RESPONSE=$(curl -X POST -k -s \ | ||
-H "Content-Type: application/json" \ | ||
-H "Authorization: Bearer $ACCESS_TOKEN" \ | ||
-d "{ \ | ||
\"query\": \"mutation CreateSession(\$userId: String!, \$scope: String!) { createOauth2Session(input: {userId: \$userId, permanent: true, scope: \$scope}) { accessToken refreshToken } }\", \ | ||
\"variables\": { \ | ||
\"userId\": \"user:$USER_ID\", \ | ||
\"scope\": \"urn:matrix:org.matrix.msc2967.client:api:*\" \ | ||
} \ | ||
}" \ | ||
$MAS_URL/graphql) | ||
|
||
PERSISTENT_TOKEN=$(echo "$TOKEN_RESPONSE" | grep -o '"accessToken":"[^"]*"' | sed 's/"accessToken":"\([^"]*\)"/\1/') | ||
|
||
if [ -n "$PERSISTENT_TOKEN" ] && [ "$PERSISTENT_TOKEN" != "null" ]; then | ||
echo "Persistent Token: $PERSISTENT_TOKEN" | ||
else | ||
echo "Unable to get a Persistent Token for $USERTOCREATE." | ||
exit 1 | ||
fi | ||
|
||
# Add it to the env file so it can be used by the bot | ||
echo "ACCESS_TOKEN=$PERSISTENT_TOKEN" > /work-dir/.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters