Skip to content

Commit cc581a0

Browse files
committed
Merge pull request github#54 from github/instance-audit
Add full instance auditor
2 parents 4a7e2bf + 2bc8db1 commit cc581a0

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

api/ruby/instance-auditing/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.xlsx

api/ruby/instance-auditing/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Instance auditor
2+
3+
This script creates an spreadsheet file that will allow you to audit the access of each team and user with all of the organizations across your GitHub Enterprise instance.
4+
5+
## Getting started
6+
7+
The user who is going to run the script must be on the "Owners" team of every organization you wish to audit. You can promote all users with Site Admin access to owners of every organization by running [`ghe-org-admin-promote`](https://help.github.com/enterprise/admin/articles/command-line-utilities/#ghe-org-admin-promote).
8+
9+
You will also need to [generate a Personal Access Token](https://help.github.com/enterprise/user/articles/creating-an-access-token-for-command-line-use/) for that user with the `admin:org` permission.
10+
11+
## Output
12+
13+
This utility will create a file in the same directory called `audit.xlsx` containing the audit data.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
# GitHub & GitHub Enterprise Instance auditor
3+
# =======================================
4+
#
5+
# Usage: ruby instance_audit.rb
6+
#
7+
# These environment variables must be set:
8+
# - GITHUB_TOKEN: A valid personal access token with Organzation admin priviliges
9+
# - GITHUB_API_ENDPOINT: A valid GitHub/GitHub Enterprise API endpoint URL
10+
# (use http://api.github.com for GitHub.com auditing)
11+
#
12+
# Requires the Octokit Rubygem: https://github.com/octokit/octokit.rb
13+
# Requires the axlsx Rubygem: https://github.com/randym/axlsx
14+
15+
require 'octokit.rb'
16+
require 'axlsx'
17+
18+
begin
19+
ACCESS_TOKEN = ENV.fetch("GITHUB_TOKEN")
20+
API_ENDPOINT = ENV.fetch("GITHUB_API_ENDPOINT")
21+
rescue KeyError
22+
$stderr.puts "To run this script, please set the following environment variables:"
23+
$stderr.puts "- GITHUB_TOKEN: A valid personal access token with Organzation admin priviliges"
24+
$stderr.puts "- GITHUB_API_ENDPOINT: A valid GitHub/GitHub Enterprise API endpoint URL"
25+
$stderr.puts " (use http://api.github.com for GitHub.com auditing)"
26+
exit 1
27+
end
28+
29+
Octokit.configure do |kit|
30+
kit.api_endpoint = API_ENDPOINT
31+
kit.access_token = ACCESS_TOKEN
32+
kit.auto_paginate = true
33+
end
34+
35+
client = Octokit::Client.new
36+
37+
Axlsx::Package.new do |p|
38+
client.organizations.each do |org|
39+
p.workbook.add_worksheet(:name => org[:login]) do |sheet|
40+
sheet.add_row %w{Organization Team Repo User Access}
41+
client.organization_teams(org[:login]).each do |team|
42+
client.team_repos(team[:id]).each do |repo|
43+
client.team_members(team[:id]).each do |user|
44+
sheet.add_row [org[:login], team[:name], repo[:name], user[:login], team[:permission]]
45+
end
46+
end
47+
end
48+
end
49+
end
50+
p.use_shared_strings = true
51+
p.serialize("#{Time.now.strftime "%Y-%m-%d"}-audit.xlsx")
52+
end

0 commit comments

Comments
 (0)