entitlements-github-plugin 0.6.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c8e5d4e8e883e7e4eb58cc3a8617ce223c6213ead611893bef473b5c95f509f
4
- data.tar.gz: 45f3ca22502cffb65002c5bd651f60bab30e98c14c4f9588dfae0d43565abe73
3
+ metadata.gz: 693affbe3d5a82f2de418c8d892e3348543de2b11ade01021c5d70e1604e7737
4
+ data.tar.gz: a1275a50c6e8c02b9394b4198f88aeb8a2fe5916182e02784c32ea81ef095a97
5
5
  SHA512:
6
- metadata.gz: d1ae84a3fa11c39758e813f6ce8ab1c7d4309ca3b3133ac05d324cfbb9a82161dc075892ff8970ef18c5b141e0b94fa3466cd6f2735c4cd57e5ac62f1df519e5
7
- data.tar.gz: ea80b29e5bac4d316549ead1d04baaa3e8111f5baa69c97530c50089dbbafcdd86db1f1558976d4681199217ccc82c8411581f02e8f03d1d324a5956d5ca0540
6
+ metadata.gz: 1a1da49e107045a502174d53e751fba158fe76712d2f777027b12648f9587cdfef265fcfef65228a03f7ce426d0ceaa6d10b58d74628ed2f2f7f9b07f6cdf483
7
+ data.tar.gz: 98bf9fbf07473e4cf09da1a2d44433ff7801a52fd7073e8e5042a33fb15438f11a88647d1c71fbb4c893a0219ae209d4089d621e48619d4839562057af9ba0de
@@ -32,7 +32,7 @@ module Entitlements
32
32
  ou: String,
33
33
  ignore_not_found: C::Maybe[C::Bool],
34
34
  ] => C::Any
35
- def initialize(addr: nil, org:, token:, ou:, ignore_not_found: false)
35
+ def initialize(org:, token:, ou:, addr: nil, ignore_not_found: false)
36
36
  super
37
37
  Entitlements.cache[:github_team_members] ||= {}
38
38
  Entitlements.cache[:github_team_members][org_signature] ||= {}
@@ -107,8 +107,8 @@ module Entitlements
107
107
  end
108
108
 
109
109
  maintainers = teamdata[:members].select { |u| teamdata[:roles][u] == "maintainer" }
110
- team_metadata = team_metadata || {}
111
- team_metadata = team_metadata.merge({"team_maintainers" => maintainers.any? ? maintainers.join(",") : nil})
110
+ team_metadata ||= {}
111
+ team_metadata = team_metadata.merge({ "team_maintainers" => maintainers.any? ? maintainers.join(",") : nil })
112
112
 
113
113
  team = Entitlements::Backend::GitHubTeam::Models::Team.new(
114
114
  team_id: teamdata[:team_id],
@@ -139,7 +139,7 @@ module Entitlements
139
139
  def from_predictive_cache?(entitlement_group)
140
140
  team_identifier = entitlement_group.cn.downcase
141
141
  read_team(entitlement_group) unless @team_cache[team_identifier]
142
- (@team_cache[team_identifier] && @team_cache[team_identifier][:cache]) ? true : false
142
+ @team_cache[team_identifier] && @team_cache[team_identifier][:cache] ? true : false
143
143
  end
144
144
 
145
145
  # Declare the entry to be invalid for a specific team, and if the prior knowledge
@@ -192,7 +192,7 @@ module Entitlements
192
192
  if desired_metadata["parent_team_name"].nil?
193
193
  Entitlements.logger.debug "sync_team(team=#{current_state.team_name}): IGNORING GitHub Parent Team DELETE"
194
194
  else
195
- # :nocov:
195
+ # :nocov:
196
196
  Entitlements.logger.debug "sync_team(#{current_state.team_name}=#{current_state.team_id}): Parent team change found - From #{current_metadata["parent_team_name"] || "No Parent Team"} to #{desired_metadata["parent_team_name"]}"
197
197
  desired_parent_team_id = team_by_name(org_name: org, team_name: desired_metadata["parent_team_name"])[:id]
198
198
  unless desired_parent_team_id.nil?
@@ -240,17 +240,20 @@ module Entitlements
240
240
  Entitlements.logger.debug "sync_team(#{current_state.team_name}=#{current_state.team_id}): Textual change but no semantic change in maintainers. It is remains: #{current_maintainers.to_a}."
241
241
  else
242
242
  Entitlements.logger.debug "sync_team(#{current_state.team_name}=#{current_state.team_id}): Maintainer members change found - From #{current_maintainers.to_a} to #{desired_maintainers.to_a}"
243
- added_maintainers.select! { |username| add_user_to_team(user: username, team: current_state, role: "maintainer") }
243
+ added_maintainers.select! do |username|
244
+ add_user_to_team(user: username, team: current_state, role: "maintainer")
245
+ end
244
246
 
245
247
  ## We only touch previous maintainers who are actually still going to be members of the team
246
248
  removed_maintainers = removed_maintainers.intersection(desired_team_members)
247
249
  ## Downgrade membership to default (role: "member")
248
- removed_maintainers.select! { |username| add_user_to_team(user: username, team: current_state, role: "member") }
250
+ removed_maintainers.select! do |username|
251
+ add_user_to_team(user: username, team: current_state, role: "member")
252
+ end
249
253
  end
250
254
  end
251
255
  end
252
256
 
253
-
254
257
  Entitlements.logger.debug "sync_team(#{current_state.team_name}=#{current_state.team_id}): Added #{added_members.count}, removed #{removed_members.count}"
255
258
  added_members.any? || removed_members.any? || added_maintainers.any? || removed_maintainers.any? || changed_parent_team
256
259
  end
@@ -264,28 +267,41 @@ module Entitlements
264
267
  entitlement_group: Entitlements::Models::Group,
265
268
  ] => C::Bool
266
269
  def create_team(entitlement_group:)
270
+ team_name = entitlement_group.cn.downcase
271
+ team_options = { name: team_name, repo_names: [], privacy: "closed" }
272
+
267
273
  begin
268
- team_name = entitlement_group.cn.downcase
269
- team_options = { name: team_name, repo_names: [], privacy: "closed" }
274
+ entitlement_metadata = entitlement_group.metadata
275
+ unless entitlement_metadata["parent_team_name"].nil?
270
276
 
271
- begin
272
- entitlement_metadata = entitlement_group.metadata
273
- unless entitlement_metadata["parent_team_name"].nil?
277
+ begin
274
278
  parent_team_data = graphql_team_data(entitlement_metadata["parent_team_name"])
275
279
  team_options[:parent_team_id] = parent_team_data[:team_id]
276
- Entitlements.logger.debug "create_team(team=#{team_name}) Parent team #{entitlement_metadata["parent_team_name"]} with id #{parent_team_data[:team_id]} found"
280
+ rescue TeamNotFound
281
+ # if the parent team does not exist, create it (think `mkdir -p` logic here)
282
+ result = octokit.create_team(
283
+ org,
284
+ { name: entitlement_metadata["parent_team_name"], repo_names: [], privacy: "closed" }
285
+ )
286
+
287
+ Entitlements.logger.debug "created parent team #{entitlement_metadata["parent_team_name"]} with id #{result[:id]}"
288
+
289
+ team_options[:parent_team_id] = result[:id]
277
290
  end
278
- rescue Entitlements::Models::Group::NoMetadata
279
- Entitlements.logger.debug "create_team(team=#{team_name}) No metadata found"
280
- end
281
291
 
282
- Entitlements.logger.debug "create_team(team=#{team_name})"
283
- octokit.create_team(org, team_options)
284
- true
285
- rescue Octokit::UnprocessableEntity => e
286
- Entitlements.logger.debug "create_team(team=#{team_name}) ERROR - #{e.message}"
287
- false
292
+ Entitlements.logger.debug "create_team(team=#{team_name}) Parent team #{entitlement_metadata["parent_team_name"]} with id #{team_options[:parent_team_id]} found"
293
+ end
294
+ rescue Entitlements::Models::Group::NoMetadata
295
+ Entitlements.logger.debug "create_team(team=#{team_name}) No metadata found"
288
296
  end
297
+
298
+ Entitlements.logger.debug "create_team(team=#{team_name})"
299
+ result = octokit.create_team(org, team_options)
300
+ Entitlements.logger.debug "created team #{team_name} with id #{result[:id]}"
301
+ true
302
+ rescue Octokit::UnprocessableEntity => e
303
+ Entitlements.logger.debug "create_team(team=#{team_name}) ERROR - #{e.message}"
304
+ false
289
305
  end
290
306
 
291
307
  # Update a team
@@ -298,15 +314,14 @@ module Entitlements
298
314
  metadata: C::Or[Hash, nil]
299
315
  ] => C::Bool
300
316
  def update_team(team:, metadata: {})
301
- begin
302
- Entitlements.logger.debug "update_team(team=#{team.team_name})"
303
- options = { name: team.team_name, repo_names: [], privacy: "closed", parent_team_id: metadata[:parent_team_id] }
304
- octokit.update_team(team.team_id, options)
305
- true
306
- rescue Octokit::UnprocessableEntity => e
307
- Entitlements.logger.debug "update_team(team=#{team.team_name}) ERROR - #{e.message}"
308
- false
309
- end
317
+ Entitlements.logger.debug "update_team(team=#{team.team_name})"
318
+ options = { name: team.team_name, repo_names: [], privacy: "closed",
319
+ parent_team_id: metadata[:parent_team_id] }
320
+ octokit.update_team(team.team_id, options)
321
+ true
322
+ rescue Octokit::UnprocessableEntity => e
323
+ Entitlements.logger.debug "update_team(team=#{team.team_name}) ERROR - #{e.message}"
324
+ false
310
325
  end
311
326
 
312
327
  # Gets a team by name
@@ -332,7 +347,8 @@ module Entitlements
332
347
  # team_slug - Identifier of the team to retrieve.
333
348
  #
334
349
  # Returns a data structure with team data.
335
- Contract String => { members: C::ArrayOf[String], team_id: Integer, parent_team_name: C::Or[String, nil], roles: C::HashOf[String => String] }
350
+ Contract String => { members: C::ArrayOf[String], team_id: Integer, parent_team_name: C::Or[String, nil],
351
+ roles: C::HashOf[String => String] }
336
352
  def graphql_team_data(team_slug)
337
353
  cursor = nil
338
354
  team_id = nil
@@ -370,9 +386,7 @@ module Entitlements
370
386
  end
371
387
 
372
388
  team = response[:data].fetch("data").fetch("organization").fetch("team")
373
- if team.nil?
374
- raise TeamNotFound, "Requested team #{team_slug} does not exist in #{org}!"
375
- end
389
+ raise TeamNotFound, "Requested team #{team_slug} does not exist in #{org}!" if team.nil?
376
390
 
377
391
  team_id = team.fetch("databaseId")
378
392
  parent_team_name = team.dig("parentTeam", "slug")
@@ -390,6 +404,7 @@ module Entitlements
390
404
 
391
405
  cursor = edges.last.fetch("cursor")
392
406
  next if cursor && buffer.size == max_graphql_results
407
+
393
408
  break
394
409
  end
395
410
 
@@ -415,6 +430,7 @@ module Entitlements
415
430
  team_data[:slug]
416
431
  end
417
432
  return if @validation_cache[team_id] == team_slug
433
+
418
434
  raise "validate_team_id_and_slug! mismatch: team_id=#{team_id} expected=#{team_slug.inspect} got=#{@validation_cache[team_id].inspect}"
419
435
  end
420
436
 
@@ -432,10 +448,11 @@ module Entitlements
432
448
  ] => C::Bool
433
449
  def add_user_to_team(user:, team:, role: "member")
434
450
  return false unless org_members.include?(user.downcase)
435
- unless role == "member" || role == "maintainer"
451
+ unless ["member", "maintainer"].include?(role)
436
452
  # :nocov:
437
453
  raise "add_user_to_team role mismatch: team_id=#{team.team_id} user=#{user} expected role=maintainer/member got=#{role}"
438
454
  end
455
+
439
456
  Entitlements.logger.debug "#{identifier} add_user_to_team(user=#{user}, org=#{org}, team_id=#{team.team_id}, role=#{role})"
440
457
  validate_team_id_and_slug!(team.team_id, team.team_name)
441
458
 
@@ -462,6 +479,7 @@ module Entitlements
462
479
  ] => C::Bool
463
480
  def remove_user_from_team(user:, team:)
464
481
  return false unless org_members.include?(user.downcase)
482
+
465
483
  Entitlements.logger.debug "#{identifier} remove_user_from_team(user=#{user}, org=#{org}, team_id=#{team.team_id})"
466
484
  validate_team_id_and_slug!(team.team_id, team.team_name)
467
485
  octokit.remove_team_membership(team.team_id, user)
data/lib/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Entitlements
4
4
  module Version
5
- VERSION = "0.6.0"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: entitlements-github-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub, Inc. Security Ops
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-03 00:00:00.000000000 Z
11
+ date: 2024-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts
@@ -72,98 +72,104 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.3'
75
+ version: '1.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.3'
82
+ version: '1.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 13.0.6
89
+ version: '13.2'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 13.2.1
90
93
  type: :development
91
94
  prerelease: false
92
95
  version_requirements: !ruby/object:Gem::Requirement
93
96
  requirements:
94
97
  - - "~>"
95
98
  - !ruby/object:Gem::Version
96
- version: 13.0.6
99
+ version: '13.2'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 13.2.1
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: rspec
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
- - - "~>"
107
+ - - '='
102
108
  - !ruby/object:Gem::Version
103
109
  version: 3.8.0
104
110
  type: :development
105
111
  prerelease: false
106
112
  version_requirements: !ruby/object:Gem::Requirement
107
113
  requirements:
108
- - - "~>"
114
+ - - '='
109
115
  - !ruby/object:Gem::Version
110
116
  version: 3.8.0
111
117
  - !ruby/object:Gem::Dependency
112
- name: rspec-core
118
+ name: rubocop
113
119
  requirement: !ruby/object:Gem::Requirement
114
120
  requirements:
115
121
  - - "~>"
116
122
  - !ruby/object:Gem::Version
117
- version: 3.8.0
123
+ version: '1.64'
118
124
  type: :development
119
125
  prerelease: false
120
126
  version_requirements: !ruby/object:Gem::Requirement
121
127
  requirements:
122
128
  - - "~>"
123
129
  - !ruby/object:Gem::Version
124
- version: 3.8.0
130
+ version: '1.64'
125
131
  - !ruby/object:Gem::Dependency
126
- name: rubocop
132
+ name: rubocop-github
127
133
  requirement: !ruby/object:Gem::Requirement
128
134
  requirements:
129
- - - '='
135
+ - - "~>"
130
136
  - !ruby/object:Gem::Version
131
- version: 1.62.1
137
+ version: '0.20'
132
138
  type: :development
133
139
  prerelease: false
134
140
  version_requirements: !ruby/object:Gem::Requirement
135
141
  requirements:
136
- - - '='
142
+ - - "~>"
137
143
  - !ruby/object:Gem::Version
138
- version: 1.62.1
144
+ version: '0.20'
139
145
  - !ruby/object:Gem::Dependency
140
- name: rubocop-github
146
+ name: rubocop-performance
141
147
  requirement: !ruby/object:Gem::Requirement
142
148
  requirements:
143
- - - '='
149
+ - - "~>"
144
150
  - !ruby/object:Gem::Version
145
- version: 0.20.0
151
+ version: '1.21'
146
152
  type: :development
147
153
  prerelease: false
148
154
  version_requirements: !ruby/object:Gem::Requirement
149
155
  requirements:
150
- - - '='
156
+ - - "~>"
151
157
  - !ruby/object:Gem::Version
152
- version: 0.20.0
158
+ version: '1.21'
153
159
  - !ruby/object:Gem::Dependency
154
- name: rubocop-performance
160
+ name: ruby-lsp
155
161
  requirement: !ruby/object:Gem::Requirement
156
162
  requirements:
157
- - - '='
163
+ - - "~>"
158
164
  - !ruby/object:Gem::Version
159
- version: 1.20.2
165
+ version: 0.16.7
160
166
  type: :development
161
167
  prerelease: false
162
168
  version_requirements: !ruby/object:Gem::Requirement
163
169
  requirements:
164
- - - '='
170
+ - - "~>"
165
171
  - !ruby/object:Gem::Version
166
- version: 1.20.2
172
+ version: 0.16.7
167
173
  - !ruby/object:Gem::Dependency
168
174
  name: rugged
169
175
  requirement: !ruby/object:Gem::Requirement
@@ -188,28 +194,34 @@ dependencies:
188
194
  name: simplecov
189
195
  requirement: !ruby/object:Gem::Requirement
190
196
  requirements:
191
- - - '='
197
+ - - "~>"
192
198
  - !ruby/object:Gem::Version
193
- version: 0.16.1
199
+ version: 0.22.0
194
200
  type: :development
195
201
  prerelease: false
196
202
  version_requirements: !ruby/object:Gem::Requirement
197
203
  requirements:
198
- - - '='
204
+ - - "~>"
199
205
  - !ruby/object:Gem::Version
200
- version: 0.16.1
206
+ version: 0.22.0
201
207
  - !ruby/object:Gem::Dependency
202
208
  name: simplecov-erb
203
209
  requirement: !ruby/object:Gem::Requirement
204
210
  requirements:
205
- - - '='
211
+ - - "~>"
212
+ - !ruby/object:Gem::Version
213
+ version: '1.0'
214
+ - - ">="
206
215
  - !ruby/object:Gem::Version
207
216
  version: 1.0.1
208
217
  type: :development
209
218
  prerelease: false
210
219
  version_requirements: !ruby/object:Gem::Requirement
211
220
  requirements:
212
- - - '='
221
+ - - "~>"
222
+ - !ruby/object:Gem::Version
223
+ version: '1.0'
224
+ - - ">="
213
225
  - !ruby/object:Gem::Version
214
226
  version: 1.0.1
215
227
  - !ruby/object:Gem::Dependency
@@ -233,6 +245,9 @@ dependencies:
233
245
  - - "~>"
234
246
  - !ruby/object:Gem::Version
235
247
  version: '3.23'
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: 3.23.1
236
251
  type: :development
237
252
  prerelease: false
238
253
  version_requirements: !ruby/object:Gem::Requirement
@@ -240,6 +255,9 @@ dependencies:
240
255
  - - "~>"
241
256
  - !ruby/object:Gem::Version
242
257
  version: '3.23'
258
+ - - ">="
259
+ - !ruby/object:Gem::Version
260
+ version: 3.23.1
243
261
  description: Entitlements plugin to manage GitHub Orgs and Team memberships and access
244
262
  email: security@github.com
245
263
  executables: []
@@ -269,14 +287,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
269
287
  requirements:
270
288
  - - ">="
271
289
  - !ruby/object:Gem::Version
272
- version: '0'
290
+ version: 3.0.0
273
291
  required_rubygems_version: !ruby/object:Gem::Requirement
274
292
  requirements:
275
293
  - - ">="
276
294
  - !ruby/object:Gem::Version
277
295
  version: '0'
278
296
  requirements: []
279
- rubygems_version: 3.5.3
297
+ rubygems_version: 3.5.9
280
298
  signing_key:
281
299
  specification_version: 4
282
300
  summary: GitHub dotcom provider for entitlements-app