-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash -e | ||
|
||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" | ||
|
||
if [ -z "$PIPELINE" ] | ||
then | ||
printf "Missing PIPELINE environment variable.\nValue must match a file in the ./config folder\n" | ||
exit 1 | ||
fi | ||
|
||
CONFIG_FILE="$SCRIPTDIR/config/$PIPELINE.cfg" | ||
|
||
if [ ! -f "$CONFIG_FILE" ] | ||
then | ||
printf "Unable to find config file %s\n" "$CONFIG_FILE" | ||
exit 1 | ||
fi | ||
|
||
source "$CONFIG_FILE" 2> /dev/null | ||
|
||
printf "Successfully read config file (%s)\n" "$CONFIG_FILE" | ||
|
||
gh secret delete "$GH_CLIENT_SECRET_NAME" --user | ||
|
||
# Check if the curl command was successful | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to delete the secret (%s)" "$GH_CLIENT_SECRET_NAME" | ||
exit 1 | ||
fi | ||
|
||
printf "Successfully deleted the secret (%s)\n" "$GH_CLIENT_SECRET_NAME" |
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,61 @@ | ||
#!/bin/bash -e | ||
|
||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" | ||
|
||
if [ -z "$PIPELINE" ] | ||
then | ||
printf "Missing PIPELINE environment variable.\nValue must match a file in the ./config folder\n" | ||
exit 1 | ||
fi | ||
|
||
CONFIG_FILE="$SCRIPTDIR/config/$PIPELINE.cfg" | ||
|
||
if [ ! -f "$CONFIG_FILE" ] | ||
then | ||
printf "Unable to find config file %s\n" "$CONFIG_FILE" | ||
exit 1 | ||
fi | ||
|
||
source "$CONFIG_FILE" 2> /dev/null | ||
|
||
printf "Successfully read config file (%s)\n" "$CONFIG_FILE" | ||
|
||
# Ask the user for the content Client client_secret | ||
printf "Enter the content of client_secret for the Client App Registration: " | ||
read -r AAD_CLIENT_CLIENT_SECRET | ||
|
||
echo "$AAD_CLIENT_CLIENT_SECRET" | gh secret set "$GH_CLIENT_SECRET_NAME" --user | ||
|
||
# Grant access to the secret for the Codespace | ||
|
||
REPO_INFO=$(curl --silent -H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/repos/$GITHUB_REPOSITORY) | ||
|
||
# Check if the curl command was successful | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to fetch repository information" | ||
exit 1 | ||
fi | ||
|
||
REPO_ID=$(echo $REPO_INFO | jq .id) | ||
|
||
# Check if the jq command was successful | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to parse repository information" | ||
exit 1 | ||
fi | ||
|
||
|
||
curl -X PUT \ | ||
-H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
https://api.github.com/user/codespaces/secrets/$GH_CLIENT_SECRET_NAME/repositories/$REPO_ID | ||
|
||
# Check if the curl command was successful | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to give repository access to the secret" | ||
exit 1 | ||
fi | ||
|
||
printf "Sucessfully granted the repo %s (%s) access to %s\'s user secret %s containing the Client appreg client_secret\n" "$GITHUB_REPOSITORY" "$REPO_ID" "$GITHUB_USER" "$GH_CLIENT_SECRET_NAME" |
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