-
Notifications
You must be signed in to change notification settings - Fork 62
feat: add script to create enterprise team tied to IdP group via SCIM #150
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,133 @@ | ||||||
| #!/bin/bash | ||||||
|
|
||||||
| # | ||||||
| # Description: | ||||||
| # Creates an enterprise team in GitHub and ties it to an Identity Provider (IdP) | ||||||
| # group via SCIM. The script first paginates through all SCIM groups in the | ||||||
| # enterprise to find the target IdP group by display name, then creates an | ||||||
| # enterprise team linked to that group. | ||||||
| # | ||||||
| # Usage: | ||||||
| # ./create-enterprise-team-tied-to-idp-group.sh <enterprise> <team-name> <idp-group-name> [api-url] | ||||||
| # | ||||||
| # Parameters: | ||||||
| # enterprise - The enterprise slug (e.g., "fabrikam") | ||||||
| # team-name - The name of the enterprise team to create (e.g., "MyTeam") | ||||||
| # idp-group-name - The display name of the IdP group to link (e.g., "Engineering Team") | ||||||
| # api-url - (Optional) The GitHub API base URL (default: https://api.github.com) | ||||||
| # | ||||||
| # Prerequisites: | ||||||
| # 1. curl and jq must be installed | ||||||
| # 2. Set the GH_PAT environment variable: export GH_PAT=ghp_abc | ||||||
| # - Token must have the `admin:enterprise` scope | ||||||
| # 3. SCIM/SSO must be configured for the enterprise with IdP groups provisioned | ||||||
| # | ||||||
| # Notes: | ||||||
| # - The script paginates through SCIM groups (100 per page) to find the target group | ||||||
| # - If the IdP group is not found, the script exits with an error | ||||||
| # - For GitHub Enterprise Server, pass the API URL as the 4th parameter | ||||||
| # (e.g., https://github.example.com/api/v3) | ||||||
| # | ||||||
|
|
||||||
| set -e | ||||||
|
|
||||||
| # --- Input parameters --- | ||||||
| ENTERPRISE=$1 # Enterprise slug | ||||||
| TEAM=$2 # Enterprise team name to create | ||||||
| IDP_GROUP=$3 # IdP group display name to search for | ||||||
| API=${4:-"https://api.github.com"} # GitHub API base URL (optional, defaults to github.com) | ||||||
|
|
||||||
| # --- Input validation --- | ||||||
| if [ "$#" -lt 3 ]; then | ||||||
| echo "Usage: $0 <enterprise> <team-name> <idp-group-name> [api-url]" | ||||||
| echo "" | ||||||
| echo "Example: $0 fabrikam MyTeam \"Engineering Team\"" | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| if [ -z "$ENTERPRISE" ]; then | ||||||
| echo "Error: enterprise slug (first argument) must not be empty." | ||||||
| echo "Usage: $0 <enterprise> <team-name> <idp-group-name> [api-url]" | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| if [ -z "$TEAM" ]; then | ||||||
| echo "Error: team name (second argument) must not be empty." | ||||||
| echo "Usage: $0 <enterprise> <team-name> <idp-group-name> [api-url]" | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| if [ -z "$IDP_GROUP" ]; then | ||||||
| echo "Error: IdP group name (third argument) must not be empty." | ||||||
| echo "Usage: $0 <enterprise> <team-name> <idp-group-name> [api-url]" | ||||||
| exit 1 | ||||||
| fi | ||||||
| if [ -z "$GH_PAT" ]; then | ||||||
| echo "Error: GH_PAT environment variable is not set." | ||||||
| echo "Set it with: export GH_PAT=ghp_abc" | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| # --- Paginate through SCIM groups to find the target IdP group --- | ||||||
| PAGE_SIZE=100 # Number of SCIM groups to fetch per page | ||||||
| START_INDEX=1 # SCIM pagination start index (1-based) | ||||||
| GROUP_ID="" # Will hold the SCIM group ID once found | ||||||
|
|
||||||
| while true; do | ||||||
| RESPONSE=$(curl -s \ | ||||||
| -H "Authorization: Bearer $GH_PAT" \ | ||||||
| -H "Accept: application/scim+json" \ | ||||||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||||||
| "$API/scim/v2/enterprises/$ENTERPRISE/Groups?startIndex=$START_INDEX&count=$PAGE_SIZE") | ||||||
|
|
||||||
| # Try to find the group in this page by matching the display name | ||||||
| GROUP_ID=$(echo "$RESPONSE" | jq -r ".Resources[] | select(.displayName==\"$IDP_GROUP\") | .id") | ||||||
|
||||||
| GROUP_ID=$(echo "$RESPONSE" | jq -r ".Resources[] | select(.displayName==\"$IDP_GROUP\") | .id") | |
| GROUP_ID=$(echo "$RESPONSE" | jq -r --arg idp "$IDP_GROUP" '.Resources[] | select(.displayName == $idp) | .id') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script lists curl/jq as prerequisites but doesn’t verify they’re installed, which can lead to hard-to-diagnose failures later. Add explicit dependency checks (command -v curl/jq) early with install hints, consistent with other scripts in this repo.