-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from joshjohanning/organization-scripts
Add/update organization reconnaissance scripts
- Loading branch information
Showing
11 changed files
with
461 additions
and
71 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
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,47 @@ | ||
#!/bin/bash | ||
|
||
# gets the settings for all organizations in an enterprise | ||
|
||
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise` | ||
|
||
# note: tsv is the default format | ||
# tsv is a subset of fields, json is all fields | ||
|
||
if [ $# -lt 1 ] | ||
then | ||
echo "usage: $0 <enterprise-slug> <hostname> > output.tsv" | ||
exit 1 | ||
fi | ||
|
||
export PAGER="" | ||
enterpriseslug=$1 | ||
hostname=$2 | ||
|
||
# set hostname to github.com by default | ||
if [ -z "$hostname" ] | ||
then | ||
hostname="github.com" | ||
fi | ||
|
||
organizations=$(gh api graphql --paginate --hostname $hostname -f enterpriseName="$enterpriseslug" -f query=' | ||
query getEnterpriseOrganizations($enterpriseName: String! $endCursor: String) { | ||
enterprise(slug: $enterpriseName) { | ||
organizations(first: 100, after: $endCursor) { | ||
nodes { | ||
id | ||
login | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
} | ||
}' --jq '.data.enterprise.organizations.nodes[].login') | ||
|
||
echo -e "Org\tApp Count" | ||
|
||
for org in $organizations | ||
do | ||
gh api "orgs/$org/installations" --hostname $hostname --jq ". | [\"$org\", .total_count] | @tsv" | ||
done |
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,59 @@ | ||
#!/bin/bash | ||
|
||
# gets the settings for all organizations in an enterprise | ||
|
||
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise` | ||
|
||
# note: tsv is the default format | ||
# tsv is a subset of fields, json is all fields | ||
|
||
if [ $# -lt 1 ] | ||
then | ||
echo "usage: $0 <enterprise-slug> <hostname> <format: tsv|json> > output.tsv" | ||
exit 1 | ||
fi | ||
|
||
enterpriseslug=$1 | ||
hostname=$2 | ||
format=$3 | ||
export PAGER="" | ||
|
||
# set hostname to github.com by default | ||
if [ -z "$hostname" ] | ||
then | ||
hostname="github.com" | ||
fi | ||
|
||
if [ -z "$format" ] | ||
then | ||
format="tsv" | ||
fi | ||
|
||
organizations=$(gh api graphql --paginate --hostname $hostname -f enterpriseName="$enterpriseslug" -f query=' | ||
query getEnterpriseOrganizations($enterpriseName: String! $endCursor: String) { | ||
enterprise(slug: $enterpriseName) { | ||
organizations(first: 100, after: $endCursor) { | ||
nodes { | ||
id | ||
login | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
} | ||
}' --jq '.data.enterprise.organizations.nodes[].login') | ||
|
||
if [ "$format" == "tsv" ]; then | ||
echo -e "Org\tApp Slug\tApp ID\tCreated At\tUpdated At\tPermissions\tEvents" | ||
fi | ||
|
||
for org in $organizations | ||
do | ||
if [ "$format" == "tsv" ]; then | ||
gh api "orgs/$org/installations" --hostname $hostname --jq ".installations[] | [\"$org\", .app_slug, .app_id, .created_at, .updated_at, (.permissions | join(\",\")), (if .events | length == 0 then \"null\" else .events | join(\",\") end)] | @tsv" | ||
else | ||
gh api "orgs/$org/installations" --hostname $hostname --jq '.installations[]' | ||
fi | ||
done |
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,72 @@ | ||
#!/bin/bash | ||
|
||
# gets the discussions count for all organizations in an enterprise | ||
|
||
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise` | ||
|
||
if [ $# -lt 1 ]; then | ||
echo "usage: $0 <enterprise slug> <hostname> > output.tsv" | ||
exit 1 | ||
fi | ||
|
||
enterprise=$1 | ||
hostname=$2 | ||
export PAGER="" | ||
|
||
# set hostname to github.com by default | ||
if [ -z "$hostname" ] | ||
then | ||
hostname="github.com" | ||
fi | ||
|
||
echo -e "Repository\tUses Codeowners" | ||
|
||
# we can't do everything in a single call b/c we need to paginate orgs and then paginate repos in the next query (can't do double pagination with gh api) | ||
organizations=$(gh api graphql --paginate --hostname $hostname -f enterpriseName="$enterprise" -f query=' | ||
query getEnterpriseOrganizations($enterpriseName: String! $endCursor: String) { | ||
enterprise(slug: $enterpriseName) { | ||
organizations(first: 100, after: $endCursor) { | ||
nodes { | ||
id | ||
login | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
} | ||
}' --jq '.data.enterprise.organizations.nodes[].login') | ||
|
||
for org in $organizations | ||
do | ||
gh api graphql --paginate --hostname $hostname -f orgName="$org" -f query=' | ||
query getOrganizationRepositories($orgName: String! $endCursor: String) { | ||
organization(login: $orgName) { | ||
repositories(first: 100, after: $endCursor) { | ||
nodes { | ||
nameWithOwner | ||
root: object(expression: "HEAD:CODEOWNERS") { | ||
... on Blob { | ||
text | ||
} | ||
} | ||
github: object(expression: "HEAD:.github/CODEOWNERS") { | ||
... on Blob { | ||
text | ||
} | ||
} | ||
docs: object(expression: "HEAD:docs/CODEOWNERS") { | ||
... on Blob { | ||
text | ||
} | ||
} | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
} | ||
}' --jq '.data.organization.repositories.nodes[] | {nameWithOwner: .nameWithOwner, hasCodeowners: if .root.text or .github.text or .docs.text then "TRUE" else "FALSE" end} | [.nameWithOwner, .hasCodeowners] | @tsv' | ||
done |
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,60 @@ | ||
#!/bin/bash | ||
|
||
# gets the discussions count for all organizations in an enterprise | ||
|
||
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise` | ||
|
||
if [ $# -lt 1 ]; then | ||
echo "usage: $0 <enterprise slug> <hostname> > output.tsv" | ||
exit 1 | ||
fi | ||
|
||
enterprise=$1 | ||
hostname=$2 | ||
export PAGER="" | ||
|
||
# set hostname to github.com by default | ||
if [ -z "$hostname" ] | ||
then | ||
hostname="github.com" | ||
fi | ||
|
||
echo -e "Repository\tDiscussion Count" | ||
|
||
# we can't do everything in a single call b/c we need to paginate orgs and then paginate repos in the next query (can't do double pagination with gh api) | ||
organizations=$(gh api graphql --paginate --hostname $hostname -f enterpriseName="$enterprise" -f query=' | ||
query getEnterpriseOrganizations($enterpriseName: String! $endCursor: String) { | ||
enterprise(slug: $enterpriseName) { | ||
organizations(first: 100, after: $endCursor) { | ||
nodes { | ||
id | ||
login | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
} | ||
}' --jq '.data.enterprise.organizations.nodes[].login') | ||
|
||
for org in $organizations | ||
do | ||
gh api graphql --paginate --hostname $hostname -f orgName="$org" -f query=' | ||
query getOrganizationRepositories($orgName: String! $endCursor: String) { | ||
organization(login: $orgName) { | ||
repositories(first: 100, after: $endCursor) { | ||
nodes { | ||
nameWithOwner | ||
discussions { | ||
totalCount | ||
} | ||
} | ||
pageInfo { | ||
endCursor | ||
hasNextPage | ||
} | ||
} | ||
} | ||
}' --jq '.data.organization.repositories.nodes[] | [.nameWithOwner, .discussions.totalCount] | @tsv' | ||
done |
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,34 @@ | ||
#!/bin/bash | ||
|
||
# gets the projects count (classic) for all organizations in an enterprise | ||
|
||
# need: `gh auth refresh -h github.com -s read:org -s read:enterprise` | ||
|
||
if [ $# -lt 1 ]; then | ||
echo "usage: $0 <enterprise slug> <hostname> > output.tsv" | ||
exit 1 | ||
fi | ||
|
||
enterprise=$1 | ||
hostname=$2 | ||
export PAGER="" | ||
|
||
# set hostname to github.com by default | ||
if [ -z "$hostname" ] | ||
then | ||
hostname="github.com" | ||
fi | ||
|
||
echo -e "Organization\tProjects Count (classic)" | ||
|
||
gh api graphql -f enterprise="$enterprise" --paginate --hostname $hostname -f query='query($enterprise:String!, $endCursor: String) { | ||
enterprise(slug:$enterprise) { | ||
organizations(first:100, after: $endCursor) { | ||
pageInfo { hasNextPage endCursor } | ||
nodes { | ||
name | ||
projects { totalCount } | ||
} | ||
} | ||
} | ||
}' --jq '.data.enterprise.organizations.nodes[] | [.name, .projects.totalCount] | @tsv' |
Oops, something went wrong.