entitlements-github-plugin 1.2.6 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f2b0df98e7f69e4f2189cf5a2e4edf7308faf18c8c307263c21bbf03e6e25e32
|
|
4
|
+
data.tar.gz: 411e9f69958ffc3685613befb69bce451a1ff18e4b087782ef143e9e7ce989a2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed27dd9f70d393b25a3cc8b0f3b5bac2c013d5aafe2030e423ee0a2d40476e2f90e81f61e5e46a6848bddc524b14da987f7dec9eed1ab8b4ee24ed2d2aa7312e
|
|
7
|
+
data.tar.gz: 344da39e0b7af4638393a4ffe21ee15ebbe70b90172edc0b8b674d93b08e92035b53fea1f20062953de7f6249c873ad0280205074d877c324cb18febf7373fe6
|
|
@@ -46,7 +46,7 @@ module Entitlements
|
|
|
46
46
|
Entitlements.logger.debug "#{identifier} add_user_to_organization(user=#{user}, org=#{org}, role=#{role})"
|
|
47
47
|
|
|
48
48
|
begin
|
|
49
|
-
new_membership = Retryable.with_context(:default, not: [Octokit::NotFound]) do
|
|
49
|
+
new_membership = Retryable.with_context(:default, not: [Octokit::NotFound, Octokit::Forbidden]) do
|
|
50
50
|
octokit.update_organization_membership(org, user:, role:)
|
|
51
51
|
end
|
|
52
52
|
rescue Octokit::NotFound => e
|
|
@@ -54,9 +54,12 @@ module Entitlements
|
|
|
54
54
|
|
|
55
55
|
Entitlements.logger.warn "User #{user} not found in GitHub instance #{identifier}, ignoring."
|
|
56
56
|
return false
|
|
57
|
-
rescue Octokit::UnprocessableEntity => e
|
|
57
|
+
rescue Octokit::UnprocessableEntity => e # code 422
|
|
58
58
|
Entitlements.logger.warn "Unprocessable entity when adding #{user} to organization #{org} with role #{role}: #{e.message}. This likely means the user blocked the invite, so we're ignoring them, but someone should check it."
|
|
59
59
|
return false
|
|
60
|
+
rescue Octokit::Forbidden => e # code 403
|
|
61
|
+
Entitlements.logger.warn "Forbidden from adding #{user} to organization #{org} with role #{role}: #{e.message}."
|
|
62
|
+
return false
|
|
60
63
|
end
|
|
61
64
|
|
|
62
65
|
# Happy path
|
|
@@ -363,12 +363,14 @@ module Entitlements
|
|
|
363
363
|
def graphql_team_data(team_slug)
|
|
364
364
|
cursor = nil
|
|
365
365
|
team_id = nil
|
|
366
|
+
parent_team_name = nil
|
|
366
367
|
result = []
|
|
367
368
|
roles = {}
|
|
368
369
|
sanity_counter = 0
|
|
369
370
|
|
|
370
|
-
|
|
371
|
+
loop do
|
|
371
372
|
sanity_counter += 1
|
|
373
|
+
raise_if_too_many_pages(sanity_counter, "members of team #{org}/#{team_slug}")
|
|
372
374
|
first_str = cursor.nil? ? "first: #{max_graphql_results}" : "first: #{max_graphql_results}, after: \"#{cursor}\""
|
|
373
375
|
query = "{
|
|
374
376
|
organization(login: \"#{org}\") {
|
|
@@ -15,6 +15,7 @@ module Entitlements
|
|
|
15
15
|
|
|
16
16
|
# This is a limitation of the GitHub API
|
|
17
17
|
MAX_GRAPHQL_RESULTS = 100
|
|
18
|
+
MAX_GRAPHQL_PAGES = 100
|
|
18
19
|
|
|
19
20
|
# Retries to smooth over transient network blips
|
|
20
21
|
MAX_GRAPHQL_RETRIES = 3
|
|
@@ -182,7 +183,7 @@ module Entitlements
|
|
|
182
183
|
end
|
|
183
184
|
|
|
184
185
|
# Get data from the predictive updates cache if it's available and valid, or else get it
|
|
185
|
-
# from
|
|
186
|
+
# from the API. This is a shim between readers and `members_and_roles_from_api`.
|
|
186
187
|
#
|
|
187
188
|
# Takes no parameters.
|
|
188
189
|
#
|
|
@@ -193,7 +194,7 @@ module Entitlements
|
|
|
193
194
|
member_from_cache = Entitlements::Data::Groups::Cached.members("cn=member,#{ou}")
|
|
194
195
|
|
|
195
196
|
# If we do not have *both* admins and members, we need to call the API
|
|
196
|
-
return [
|
|
197
|
+
return [members_and_roles_from_api, false] unless admin_from_cache && member_from_cache
|
|
197
198
|
|
|
198
199
|
# Convert the Sets of strings into the expected hash structure.
|
|
199
200
|
Entitlements.logger.debug "Loading organization members and roles for #{org} from cache"
|
|
@@ -202,6 +203,16 @@ module Entitlements
|
|
|
202
203
|
[result, true]
|
|
203
204
|
end
|
|
204
205
|
|
|
206
|
+
# Use GraphQL in GitHub Actions, where entitlements-caches can answer it, and REST elsewhere.
|
|
207
|
+
#
|
|
208
|
+
# Takes no parameters.
|
|
209
|
+
#
|
|
210
|
+
# Returns Hash of { "username" => "ROLE" } where "ROLE" is from GraphQL Enum.
|
|
211
|
+
Contract C::None => C::HashOf[String => String]
|
|
212
|
+
def members_and_roles_from_api
|
|
213
|
+
ENV["GITHUB_RUN_ID"] ? members_and_roles_from_graphql : members_and_roles_from_rest
|
|
214
|
+
end
|
|
215
|
+
|
|
205
216
|
# Query GraphQL API to get a list of members and their roles.
|
|
206
217
|
#
|
|
207
218
|
# Takes no parameters.
|
|
@@ -215,8 +226,9 @@ module Entitlements
|
|
|
215
226
|
result = {}
|
|
216
227
|
sanity_counter = 0
|
|
217
228
|
|
|
218
|
-
|
|
229
|
+
loop do
|
|
219
230
|
sanity_counter += 1
|
|
231
|
+
raise_if_too_many_pages(sanity_counter, "organization members of #{org}")
|
|
220
232
|
first_str = cursor.nil? ? "first: #{max_graphql_results}" : "first: #{max_graphql_results}, after: \"#{cursor}\""
|
|
221
233
|
query = "{
|
|
222
234
|
organization(login: \"#{org}\") {
|
|
@@ -294,8 +306,9 @@ module Entitlements
|
|
|
294
306
|
result = Set.new
|
|
295
307
|
sanity_counter = 0
|
|
296
308
|
|
|
297
|
-
|
|
309
|
+
loop do
|
|
298
310
|
sanity_counter += 1
|
|
311
|
+
raise_if_too_many_pages(sanity_counter, "pending members of #{org}")
|
|
299
312
|
first_str = cursor.nil? ? "first: #{max_graphql_results}" : "first: #{max_graphql_results}, after: \"#{cursor}\""
|
|
300
313
|
query = "{
|
|
301
314
|
organization(login: \"#{org}\") {
|
|
@@ -378,6 +391,8 @@ module Entitlements
|
|
|
378
391
|
request = Net::HTTP::Post.new(uri)
|
|
379
392
|
request.add_field("Authorization", "bearer #{token}")
|
|
380
393
|
request.add_field("Content-Type", "application/json")
|
|
394
|
+
# Lets a proxy such as entitlements-caches tie each request to a CI run.
|
|
395
|
+
request.add_field("X-Entitlements-Run-Id", ENV["GITHUB_RUN_ID"]) if ENV["GITHUB_RUN_ID"]
|
|
381
396
|
request.body = JSON.generate("query" => query)
|
|
382
397
|
|
|
383
398
|
begin
|
|
@@ -476,6 +491,35 @@ module Entitlements
|
|
|
476
491
|
MAX_GRAPHQL_RESULTS
|
|
477
492
|
end
|
|
478
493
|
# :nocov:
|
|
494
|
+
|
|
495
|
+
# Helper method: Determine the maximum number of pages to read from a paginated
|
|
496
|
+
# GraphQL query. Stubbed in tests.
|
|
497
|
+
#
|
|
498
|
+
# Takes no arguments.
|
|
499
|
+
#
|
|
500
|
+
# Returns an Integer.
|
|
501
|
+
# :nocov:
|
|
502
|
+
Contract C::None => Integer
|
|
503
|
+
def max_graphql_pages
|
|
504
|
+
MAX_GRAPHQL_PAGES
|
|
505
|
+
end
|
|
506
|
+
# :nocov:
|
|
507
|
+
|
|
508
|
+
# Helper method: Raise rather than return a truncated result when a paginated
|
|
509
|
+
# GraphQL query needs more pages than allowed. A partial list of members would
|
|
510
|
+
# cause entitlements to skip removals for anyone not returned.
|
|
511
|
+
#
|
|
512
|
+
# page - Integer number of the page about to be requested.
|
|
513
|
+
# what - String describing what is being read, for the error message.
|
|
514
|
+
#
|
|
515
|
+
# Returns nothing.
|
|
516
|
+
Contract Integer, String => nil
|
|
517
|
+
def raise_if_too_many_pages(page, what)
|
|
518
|
+
return if page <= max_graphql_pages
|
|
519
|
+
|
|
520
|
+
Entitlements.logger.fatal "Abort reading #{what}: more than #{max_graphql_pages} pages of results"
|
|
521
|
+
raise "GraphQL pagination limit exceeded"
|
|
522
|
+
end
|
|
479
523
|
end
|
|
480
524
|
end
|
|
481
525
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: entitlements-github-plugin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GitHub, Inc. Security Ops
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: contracts
|
|
@@ -314,7 +313,6 @@ homepage: https://github.com/github/entitlements-github-plugin
|
|
|
314
313
|
licenses:
|
|
315
314
|
- MIT
|
|
316
315
|
metadata: {}
|
|
317
|
-
post_install_message:
|
|
318
316
|
rdoc_options: []
|
|
319
317
|
require_paths:
|
|
320
318
|
- lib
|
|
@@ -329,8 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
329
327
|
- !ruby/object:Gem::Version
|
|
330
328
|
version: '0'
|
|
331
329
|
requirements: []
|
|
332
|
-
rubygems_version: 3.
|
|
333
|
-
signing_key:
|
|
330
|
+
rubygems_version: 3.6.9
|
|
334
331
|
specification_version: 4
|
|
335
332
|
summary: GitHub dotcom provider for entitlements-app
|
|
336
333
|
test_files: []
|