Introduction
After successfully installing and creating your AWS EC2 instance, let's delve into the world of shell scripting by implementing a popular GitHub API. This script will allow you to view the list of collaborators and remove someone from it, addressing the common issue of revoking permissions when a person leaves an organization or a project.
AWS EC2 Instance Setup
Start by creating an AWS instance using the following image:
Connect your CLI to your EC2 instance and clone the GitHub repository with the following command:
git clone https://github.com/surajvast1/shell-script
GitHub Collaboration Test
Create a GitHub organization and add a collaborator to test your script. Run the following set of commands in your terminal:
cd shell-scripting-projects/github-api
export username="<organization_username>"
export token="<github_access_token>"
./list-users.sh <repo_owner> <repo_name>
For example:
cd shell-scripting-projects/github-api
export username="surajvast1"
export token="ghp_sAJKxxxxxxxxxxxxxxxxxxxxxxxxxx"
./list-users.sh surajvast1 shell-script
jq Information
The script utilizes jq
to access only the names of collaborators from the JSON response.
Advanced Scripting with Helper Function
To enhance the shell script, a helper function can be added. Here is an example:
function helper {
expected_cmd_args=2
if [ $# -ne $expected_cmd_args ]; then
echo "Please execute the script with the required cmd and args"
echo "./list-users.sh <repo_owner> <repo_name>"
fi
}
This function ensures that the script is executed with the correct number of command-line arguments.
ππ©βπ»
Top comments (0)