gitlab_support_readiness 1.0.0

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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/lib/support_readiness/client.rb +108 -0
  3. data/lib/support_readiness/gitlab/client.rb +64 -0
  4. data/lib/support_readiness/gitlab/configuration.rb +46 -0
  5. data/lib/support_readiness/gitlab/groups.rb +180 -0
  6. data/lib/support_readiness/gitlab/issues.rb +410 -0
  7. data/lib/support_readiness/gitlab/namespaces.rb +190 -0
  8. data/lib/support_readiness/gitlab/projects.rb +510 -0
  9. data/lib/support_readiness/gitlab/repositories.rb +267 -0
  10. data/lib/support_readiness/gitlab/users.rb +488 -0
  11. data/lib/support_readiness/gitlab.rb +19 -0
  12. data/lib/support_readiness/pagerduty/client.rb +66 -0
  13. data/lib/support_readiness/pagerduty/configuration.rb +43 -0
  14. data/lib/support_readiness/pagerduty/escalation_policies.rb +123 -0
  15. data/lib/support_readiness/pagerduty/schedules.rb +223 -0
  16. data/lib/support_readiness/pagerduty/services.rb +132 -0
  17. data/lib/support_readiness/pagerduty.rb +16 -0
  18. data/lib/support_readiness/redis.rb +90 -0
  19. data/lib/support_readiness/zendesk/articles.rb +210 -0
  20. data/lib/support_readiness/zendesk/automations.rb +304 -0
  21. data/lib/support_readiness/zendesk/client.rb +84 -0
  22. data/lib/support_readiness/zendesk/configuration.rb +49 -0
  23. data/lib/support_readiness/zendesk/group_memberships.rb +256 -0
  24. data/lib/support_readiness/zendesk/groups.rb +249 -0
  25. data/lib/support_readiness/zendesk/job_statuses.rb +188 -0
  26. data/lib/support_readiness/zendesk/macros.rb +267 -0
  27. data/lib/support_readiness/zendesk/organization_fields.rb +233 -0
  28. data/lib/support_readiness/zendesk/organization_memberships.rb +257 -0
  29. data/lib/support_readiness/zendesk/organizations.rb +515 -0
  30. data/lib/support_readiness/zendesk/roles.rb +194 -0
  31. data/lib/support_readiness/zendesk/search.rb +159 -0
  32. data/lib/support_readiness/zendesk/sla_policies.rb +232 -0
  33. data/lib/support_readiness/zendesk/ticket_fields.rb +222 -0
  34. data/lib/support_readiness/zendesk/ticket_forms.rb +290 -0
  35. data/lib/support_readiness/zendesk/tickets.rb +854 -0
  36. data/lib/support_readiness/zendesk/triggers.rb +269 -0
  37. data/lib/support_readiness/zendesk/users.rb +946 -0
  38. data/lib/support_readiness/zendesk/views.rb +469 -0
  39. data/lib/support_readiness/zendesk.rb +31 -0
  40. data/lib/support_readiness.rb +29 -0
  41. metadata +215 -0
@@ -0,0 +1,488 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module GitLab
6
+ module GitLab
7
+ ##
8
+ # Defines the class Projects within the module {Readiness::GitLab}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @todo Anything listed on https://docs.gitlab.com/ee/api/users.html not currently here
13
+ class Users < Readiness::Client
14
+ attr_accessor :avatar_url, :bio, :bot, :can_create_group, :can_create_project, :color_scheme_id, :commit_email, :confirmed_at, :created_at, :created_by, :current_sign_in_at, :current_sign_in_ip, :discord, :email, :email_reset_offered_at, :enterprise_group_associated_at, :enterprise_group_id, :external, :extra_shared_runners_minutes_limit, :followers, :following, :highest_role, :id, :identities, :is_admin, :is_auditor, :is_followed, :job_title, :last_activity_on, :last_sign_in_at, :last_sign_in_ip, :linkedin, :local_time, :location, :locked, :name, :namespace_id, :note, :organization, :plan, :private_profile, :projects_limit, :pronouns, :provisioned_by_group_id, :public_email, :scim_identities, :shared_runners_minutes_limit, :sign_in_count, :skype, :state, :theme_id, :trial, :twitter, :two_factor_enabled, :username, :using_license_seat, :website_url, :web_url, :work_information
15
+
16
+ ##
17
+ # Creates a new {Readiness::GitLab::Users} instance
18
+ #
19
+ # @author Jason Colyer
20
+ # @since 1.0.0
21
+ # @param object [Object] An instance of {Readiness::GitLab::Users}
22
+ # @example
23
+ # require 'support_readiness'
24
+ # Readiness::GitLab::Users.new
25
+ def initialize(object = {})
26
+ @avatar_url = object['avatar_url']
27
+ @bio = object['bio']
28
+ @bot = object['bot']
29
+ @can_create_group = object['can_create_group']
30
+ @can_create_project = object['can_create_project']
31
+ @color_scheme_id = object['color_scheme_id']
32
+ @commit_email = object['commit_email']
33
+ @confirmed_at = object['confirmed_at']
34
+ @created_at = object['created_at']
35
+ @created_by = object['created_by']
36
+ @current_sign_in_at = object['current_sign_in_at']
37
+ @current_sign_in_ip = object['current_sign_in_ip']
38
+ @discord = object['discord']
39
+ @email = object['email']
40
+ @email_reset_offered_at = object['email_reset_offered_at']
41
+ @enterprise_group_associated_at = object['enterprise_group_associated_at']
42
+ @enterprise_group_id = object['enterprise_group_id']
43
+ @external = object['external']
44
+ @extra_shared_runners_minutes_limit = object['extra_shared_runners_minutes_limit']
45
+ @followers = object['followers']
46
+ @following = object['following']
47
+ @highest_role = object['highest_role']
48
+ @id = object['id']
49
+ @identities = object['identities']
50
+ @is_admin = object['is_admin']
51
+ @is_auditor = object['is_auditor']
52
+ @is_followed = object['is_followed']
53
+ @job_title = object['job_title']
54
+ @last_activity_on = object['last_activity_on']
55
+ @last_sign_in_at = object['last_sign_in_at']
56
+ @last_sign_in_ip = object['last_sign_in_ip']
57
+ @linkedin = object['linkedin']
58
+ @local_time = object['local_time']
59
+ @location = object['location']
60
+ @locked = object['locked']
61
+ @name = object['name']
62
+ @namespace_id = object['namespace_id']
63
+ @note = object['note']
64
+ @organization = object['organization']
65
+ @plan = object['plan']
66
+ @private_profile = object['private_profile']
67
+ @projects_limit = object['projects_limit']
68
+ @pronouns = object['pronouns']
69
+ @provisioned_by_group_id = object['provisioned_by_group_id']
70
+ @public_email = object['public_email']
71
+ @scim_identities = object['scim_identities']
72
+ @shared_runners_minutes_limit = object['shared_runners_minutes_limit']
73
+ @sign_in_count = object['sign_in_count']
74
+ @skype = object['skype']
75
+ @state = object['state']
76
+ @theme_id = object['theme_id']
77
+ @trial = object['trial']
78
+ @twitter = object['twitter']
79
+ @two_factor_enabled = object['two_factor_enabled']
80
+ @username = object['username']
81
+ @using_license_seat = object['using_license_seat']
82
+ @website_url = object['website_url']
83
+ @web_url = object['web_url']
84
+ @work_information = object['work_information']
85
+ end
86
+
87
+ ##
88
+ # Locates a user within GitLab. This will not exit on error (except Authentication errors)
89
+ #
90
+ # @author Jason Colyer
91
+ # @since 1.0.0
92
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
93
+ # @param uid [Integer] The user ID to find
94
+ # @return [Hash]
95
+ # @see https://docs.gitlab.com/ee/api/users.html#get-a-single-user GitLab API > Users > Get a single user
96
+ # @example
97
+ # require 'support_readiness'
98
+ # config = Readiness::GitLab::Configuration.new
99
+ # config.token = 'test123abc'
100
+ # client = Readiness::GitLab::Client.new(config)
101
+ # user = Readiness::GitLab::Users.find(client, 123456)
102
+ # pp user.username
103
+ # # => 'test_user123456'
104
+ def self.find(client, uid)
105
+ response = client.connection.get "users/#{uid}"
106
+ handle_request_error(0, 'GitLab', response.status, { action: 'get', id: uid }) unless response.status == 200
107
+ return Users.new(Oj.load(response.body)) if response.status == 200
108
+
109
+ Oj.load(response.body)
110
+ end
111
+
112
+ ##
113
+ # Locates a user within GitLab. This will exit on error
114
+ #
115
+ # @author Jason Colyer
116
+ # @since 1.0.0
117
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
118
+ # @param uid [Integer] The user ID to find
119
+ # @return [Object] An instance of {Readiness::GitLab::Users}
120
+ # @see https://docs.gitlab.com/ee/api/users.html#get-a-single-user GitLab API > Users > Get a single user
121
+ # @example
122
+ # require 'support_readiness'
123
+ # config = Readiness::GitLab::Configuration.new
124
+ # config.token = 'test123abc'
125
+ # client = Readiness::GitLab::Client.new(config)
126
+ # user = Readiness::GitLab::Users.find!(client, 123456)
127
+ # pp user.username
128
+ # # => 'test_user123456'
129
+ def self.find!(client, uid, attributes = [])
130
+ response = client.connection.get "users/#{uid}"
131
+ handle_request_error(1, 'GitLab', response.status, { action: 'Find user', id: uid }) unless response.status == 200
132
+ Users.new(Oj.load(response.body))
133
+ end
134
+
135
+ ##
136
+ # Locates the first 20 users matching a username within GitLab.
137
+ #
138
+ # @author Jason Colyer
139
+ # @since 1.0.0
140
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
141
+ # @param username [String] The username to look for
142
+ # @return [Array]
143
+ # @see https://docs.gitlab.com/ee/api/users.html#list-users GitLab API > Users > List users
144
+ # @example
145
+ # require 'support_readiness'
146
+ # config = Readiness::GitLab::Configuration.new
147
+ # config.token = 'test123abc'
148
+ # client = Readiness::GitLab::Client.new(config)
149
+ # users = Readiness::GitLab::Users.search_by_username(client, 'test_user123456')
150
+ # pp users.first.id
151
+ # # => 123456
152
+ def self.search_by_username(client, username)
153
+ response = client.connection.get "users?username=#{username}"
154
+ handle_request_error(0, 'GitLab', response.status, { action: 'Find user by username', id: username }) unless response.status == 200
155
+ Oj.load(response.body).map { |u| Users.new(u) }
156
+ end
157
+
158
+ ##
159
+ # Locates the first 20 users matching a email within GitLab.
160
+ #
161
+ # @author Jason Colyer
162
+ # @since 1.0.0
163
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
164
+ # @param email [String] The email to look for
165
+ # @return [Array]
166
+ # @see https://docs.gitlab.com/ee/api/users.html#list-users GitLab API > Users > List users
167
+ # @example
168
+ # require 'support_readiness'
169
+ # config = Readiness::GitLab::Configuration.new
170
+ # config.token = 'test123abc'
171
+ # client = Readiness::GitLab::Client.new(config)
172
+ # users = Readiness::GitLab::Users.search_by_email(client, 'test_user123456@example.com')
173
+ # pp users.first.name
174
+ # # => "test_user_123456"
175
+ def self.search_by_email(client, email)
176
+ response = client.connection.get "users?search=#{CGI.escape(email)}"
177
+ handle_request_error(0, 'GitLab', response.status, { action: 'Find user by email', id: email }) unless response.status == 200
178
+ Oj.load(response.body).map { |u| Users.new(u) }
179
+ end
180
+
181
+ ##
182
+ # Updates a user within GitLab. This will exit on error
183
+ #
184
+ # @author Jason Colyer
185
+ # @since 1.0.0
186
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
187
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
188
+ # @return [Object] An instance of {Readiness::GitLab::Users}
189
+ # @see https://docs.gitlab.com/ee/api/users.html#modify-a-user GitLab API > Users > Modify a user
190
+ # @example
191
+ # require 'support_readiness'
192
+ # config = Readiness::GitLab::Configuration.new
193
+ # config.token = 'test123abc'
194
+ # client = Readiness::GitLab::Client.new(config)
195
+ # user = Readiness::GitLab::Users.find!(client, 123456)
196
+ # user.name = 'Test User 123456'
197
+ # update = Readiness::GitLab::Users.update!(client, user)
198
+ # pp update.name
199
+ # # => "Test User 123456"
200
+ def self.update!(client, user)
201
+ response = client.connection.put "users/#{user.id}", to_clean_json(user)
202
+ handle_request_error(1, 'GitLab', response.status, { action: 'Update an user', id: "#{user.id}" }) unless response.status == 200
203
+ Users.new(Oj.load(response.body))
204
+ end
205
+
206
+ ##
207
+ # Lists all memberships for a user.
208
+ # This method can take a long time to run depending on the parameters used.
209
+ #
210
+ # @author Jason Colyer
211
+ # @since 1.0.0
212
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
213
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
214
+ # @param params [Array] An array of filter Strings to use. Should be in the format of key=value
215
+ # @return [Array]
216
+ # @see https://docs.gitlab.com/ee/api/users.html#user-memberships GitLab API > Users > Get memberships
217
+ # @example
218
+ # require 'support_readiness'
219
+ # config = Readiness::GitLab::Configuration.new
220
+ # config.token = 'test123abc'
221
+ # client = Readiness::GitLab::Client.new(config)
222
+ # user = Readiness::GitLab::Users.find!(client, 123456)
223
+ # memberships = Readiness::GitLab::Users.memberships(client, user)
224
+ # pp memberships.select { |m| m['access_level'] == 50 }.count
225
+ # # => 28
226
+ def self.memberships(client, user, params = [])
227
+ array = []
228
+ page = 1
229
+ loop do
230
+ response = client.connection.get "users/#{user.id}/memberships?per_page=100&page=#{page}&#{to_param_string(filters)}"
231
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
232
+ body = Oj.load(response.body)
233
+ array += body
234
+ break if body.count < 100
235
+
236
+ page += 1
237
+ end
238
+ array
239
+ end
240
+
241
+ ##
242
+ # Lists all user projects.
243
+ # This method can take a long time to run depending on the parameters used.
244
+ #
245
+ # @author Jason Colyer
246
+ # @since 1.0.0
247
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
248
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
249
+ # @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
250
+ # @return [Array]
251
+ # @see https://docs.gitlab.com/ee/api/projects.html#list-user-projects GitLab API > Projects > List user projects
252
+ # @example
253
+ # require 'support_readiness'
254
+ # config = Readiness::GitLab::Configuration.new
255
+ # config.token = 'test123abc'
256
+ # client = Readiness::GitLab::Client.new(config)
257
+ # user = Readiness::GitLab::Users.find!(client, 123456)
258
+ # memberships = Readiness::GitLab::Users.projects(client, user)
259
+ # pp projects.first.web_url
260
+ # # => "https://gitlab.com/test_user123456/awesome_project"
261
+ def self.projects(client, user, filters = [])
262
+ array = []
263
+ page = 1
264
+ loop do
265
+ response = client.connection.get "users/#{user.id}/projects?per_page=100&page=#{page}&#{to_param_string(filters)}"
266
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
267
+ body = Oj.load(response.body)
268
+ array += body.map { |p| Projects.new(p) }
269
+ break if body.count < 100
270
+
271
+ page += 1
272
+ end
273
+ array
274
+ end
275
+
276
+ ##
277
+ # Lists SSH keys for a user.
278
+ #
279
+ # @author Jason Colyer
280
+ # @since 1.0.0
281
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
282
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
283
+ # @return [Array]
284
+ # @see https://docs.gitlab.com/ee/api/user_keys.html#list-ssh-keys-for-a-user GitLab API > Users > SSH and GPG keys > List SSH keys for a user
285
+ # @example
286
+ # require 'support_readiness'
287
+ # config = Readiness::GitLab::Configuration.new
288
+ # config.token = 'test123abc'
289
+ # client = Readiness::GitLab::Client.new(config)
290
+ # user = Readiness::GitLab::Users.find!(client, 2672834)
291
+ # keys = Readiness::GitLab::Users.ssh_keys(client, user)
292
+ # pp keys.last['title']
293
+ # # => "Linux Laptop"
294
+ def self.ssh_keys(client, user)
295
+ response = client.connection.get "users/#{user.id}/keys"
296
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
297
+ Oj.load(response.body)
298
+ end
299
+
300
+ ##
301
+ # Lists SSH keys for a user.
302
+ #
303
+ # @author Jason Colyer
304
+ # @since 1.0.0
305
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
306
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
307
+ # @return [Array]
308
+ # @see https://docs.gitlab.com/ee/api/user_keys.html#list-gpg-keys-for-a-user GitLab API > Users > SSH and GPG keys > List GPG keys for a user
309
+ # @example
310
+ # require 'support_readiness'
311
+ # config = Readiness::GitLab::Configuration.new
312
+ # config.token = 'test123abc'
313
+ # client = Readiness::GitLab::Client.new(config)
314
+ # user = Readiness::GitLab::Users.find!(client, 2672834)
315
+ # keys = Readiness::GitLab::Users.gpg_keys(client, user)
316
+ # pp keys.count
317
+ # # => 1
318
+ def self.gpg_keys(client, user)
319
+ response = client.connection.get "users/#{user.id}/gpg_keys"
320
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
321
+ Oj.load(response.body)
322
+ end
323
+
324
+ ##
325
+ # Lists all personal access tokens for a user.
326
+ # This method can take a long time to run depending on the parameters used.
327
+ #
328
+ # @author Jason Colyer
329
+ # @since 1.0.0
330
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
331
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
332
+ # @param filters [Array] An array of filter Strings to use. Should be in the format of key=value
333
+ # @return [Array]
334
+ # @see https://docs.gitlab.com/ee/api/personal_access_tokens.html#list-personal-access-tokens GitLab API > Personal access tokens > List personal access tokens
335
+ # @example
336
+ # require 'support_readiness'
337
+ # config = Readiness::GitLab::Configuration.new
338
+ # config.token = 'test123abc'
339
+ # client = Readiness::GitLab::Client.new(config)
340
+ # user = Readiness::GitLab::Users.find!(client, 2672834)
341
+ # tokens = Readiness::GitLab::Users.tokens(client, user)
342
+ # pp tokens.select { |t| Date.parse(t['expires_at']) <= (Date.today + 7.days) }.count
343
+ # # => 3
344
+ def self.tokens(client, user, filters = [])
345
+ array = []
346
+ page = 1
347
+ loop do
348
+ response = client.connection.get "personal_access_tokens?user_id=#{user.id}&per_page=100&page=#{page}&#{to_param_string(filters)}"
349
+ handle_request_error(0, 'GitLab', response.status) unless response.status == 200
350
+ body = Oj.load(response.body)
351
+ array += body
352
+ break if body.count < 100
353
+
354
+ page += 1
355
+ end
356
+ array
357
+ end
358
+
359
+ ##
360
+ # Creates a personal access token for a user within GitLab. This will exit on error
361
+ #
362
+ # @author Jason Colyer
363
+ # @since 1.0.0
364
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
365
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
366
+ # @param params [Hash] The parameters to create the token with. At a minimum needs { name: 'xxx' }.
367
+ # @return [Object] An instance of {Readiness::GitLab::Users}
368
+ # @see https://docs.gitlab.com/ee/api/user_tokens.html#create-a-personal-access-token GitLab API > Users > User tokens
369
+ # @example
370
+ # require 'support_readiness'
371
+ # config = Readiness::GitLab::Configuration.new
372
+ # config.token = 'test123abc'
373
+ # client = Readiness::GitLab::Client.new(config)
374
+ # user = Readiness::GitLab::Users.find!(client, 2672834)
375
+ # token_params = {
376
+ # name: 'Token for updating submodule of test_user123456/awesome_project',
377
+ # expires_at: '2024-10-13',
378
+ # scopes: [
379
+ # 'api'
380
+ # ]
381
+ # }
382
+ # token = Readiness::GitLab::Users.create_token!(client, user, token_params)
383
+ # pp token['token']
384
+ # # => "s3cr3t1"
385
+ def self.create_token!(client, user, params)
386
+ response = client.connection.post "users/#{user.id}/personal_access_tokens", to_clean_json(params)
387
+ handle_request_error(1, 'GitLab', response.status, { action: 'Create PAT for a user', id: "#{user.id}" }) unless response.status == 200
388
+ Oj.load(response.body)
389
+ end
390
+
391
+ ##
392
+ # Revokes a personal access token within GitLab. This will exit on error
393
+ #
394
+ # @author Jason Colyer
395
+ # @since 1.0.0
396
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
397
+ # @param tid [Integer] The personal access token ID
398
+ # @return [Boolean]
399
+ # @see https://docs.gitlab.com/ee/api/personal_access_tokens.html#revoke-a-personal-access-token GitLab API > Personal access tokens > Revoke a personal access token
400
+ # @example
401
+ # require 'support_readiness'
402
+ # config = Readiness::GitLab::Configuration.new
403
+ # config.token = 'test123abc'
404
+ # client = Readiness::GitLab::Client.new(config)
405
+ # user = Readiness::GitLab::Users.find!(client, 2672834)
406
+ # token = Readiness::GitLab::Users.revoke_token!(client, 123456)
407
+ # pp token
408
+ # # => true
409
+ def self.revoke_token!(client, tid)
410
+ response = client.connection.delete "personal_access_tokens/#{tid}"
411
+ handle_request_error(1, 'GitLab', response.status, { action: 'Revoke PAT', id: tid }) unless response.status == 204
412
+ true
413
+ end
414
+
415
+ ##
416
+ # Rotates a personal access token (revokes it and makes a new one with the same user). This will exit on error
417
+ #
418
+ # @author Jason Colyer
419
+ # @since 1.0.0
420
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
421
+ # @param tid [Integer] The personal access token ID
422
+ # @return [Hash]
423
+ # @see https://docs.gitlab.com/ee/api/personal_access_tokens.html#rotate-a-personal-access-token GitLab API > Personal access tokens > Rotate a personal access token
424
+ # @example
425
+ # require 'support_readiness'
426
+ # config = Readiness::GitLab::Configuration.new
427
+ # config.token = 'test123abc'
428
+ # client = Readiness::GitLab::Client.new(config)
429
+ # user = Readiness::GitLab::Users.find!(client, 2672834)
430
+ # token = Readiness::GitLab::Users.rotate_token!(client, 123456)
431
+ # pp token['token']
432
+ # # => "s3cr3t2"
433
+ def self.rotate_token!(client, tid)
434
+ response = client.connection.post "personal_access_tokens/#{tid}/rotate"
435
+ handle_request_error(1, 'GitLab', response.status, { action: 'Rotate PAT', id: tid }) unless response.status == 200
436
+ Oj.load(response.body)
437
+ end
438
+
439
+ ##
440
+ # Blocks a user in GitLab. This will exit on error
441
+ #
442
+ # @author Jason Colyer
443
+ # @since 1.0.0
444
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
445
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
446
+ # @return [Boolean]
447
+ # @see https://docs.gitlab.com/ee/api/user_moderation.html#block-a-user GitLab API > Users > Block a user
448
+ # @example
449
+ # require 'support_readiness'
450
+ # config = Readiness::GitLab::Configuration.new
451
+ # config.token = 'test123abc'
452
+ # client = Readiness::GitLab::Client.new(config)
453
+ # user = Readiness::GitLab::Users.find!(client, 2672834)
454
+ # block = Readiness::GitLab::Users.block!(client, user)
455
+ # pp block
456
+ # # => true
457
+ def self.block!(client, user)
458
+ response = client.connection.post "users/#{user.id}/block"
459
+ handle_request_error(1, 'GitLab', response.status, { action: 'Block a user', id: user.id }) unless response.status == 201
460
+ true
461
+ end
462
+
463
+ ##
464
+ # Unblocks a user in GitLab. This will exit on error
465
+ #
466
+ # @author Jason Colyer
467
+ # @since 1.0.0
468
+ # @param client [Object] An instance of {Readiness::GitLab::Client}
469
+ # @param user [Object] An instance of {Readiness::GitLab::Users}
470
+ # @return [Boolean]
471
+ # @see https://docs.gitlab.com/ee/api/user_moderation.html#unblock-a-user GitLab API > Users > Unblock a user
472
+ # @example
473
+ # require 'support_readiness'
474
+ # config = Readiness::GitLab::Configuration.new
475
+ # config.token = 'test123abc'
476
+ # client = Readiness::GitLab::Client.new(config)
477
+ # user = Readiness::GitLab::Users.find!(client, 2672834)
478
+ # block = Readiness::GitLab::Users.unblock!(client, user)
479
+ # pp block
480
+ # # => true
481
+ def self.unblock!(client, user)
482
+ response = client.connection.post "users/#{user.id}/unblock"
483
+ handle_request_error(1, 'GitLab', response.status, { action: 'Unblock a user', id: user.id }) unless response.status == 201
484
+ true
485
+ end
486
+ end
487
+ end
488
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ ##
6
+ # Defines the module GitLab
7
+ # @author Jason Colyer
8
+ # @since 1.0.0
9
+ module GitLab
10
+ require "#{__dir__}/gitlab/client"
11
+ require "#{__dir__}/gitlab/configuration"
12
+ require "#{__dir__}/gitlab/groups"
13
+ require "#{__dir__}/gitlab/issues"
14
+ require "#{__dir__}/gitlab/namespaces"
15
+ require "#{__dir__}/gitlab/projects"
16
+ require "#{__dir__}/gitlab/repositories"
17
+ require "#{__dir__}/gitlab/users"
18
+ end
19
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Pagerduty
6
+ module Pagerduty
7
+ ##
8
+ # Defines the class Client within the module {Readiness::Pagerduty}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Client
13
+ attr_reader :connection, :upload_connection
14
+
15
+ ##
16
+ # Creates a new {Readiness::Pagerduty::Client} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @param config [Object] An instance of {Readiness::Pagerduty::Configuration}
21
+ # @example
22
+ # require 'support_readiness'
23
+ # config = Readiness::Pagerduty::Configuration.new
24
+ # config.token = 'test123abc'
25
+ # Readiness::Pagerduty::Client.new(config)
26
+ def initialize(config = Readiness::Pagerduty::Configuration.new)
27
+ @connection = generate_connection(config)
28
+ end
29
+
30
+ ##
31
+ # Used to generate the retry options passed to Faraday via faraday-retry
32
+ #
33
+ # @author Jason Colyer
34
+ # @since 1.0.0
35
+ # @param config [Object] An instance of {Readiness::Zendesk::Configuration}
36
+ # @return [Hash]
37
+ def retry_options(config)
38
+ {
39
+ max: config.retry_max,
40
+ interval: config.retry_interval,
41
+ interval_randomness: config.retry_randomness,
42
+ backoff_factor: config.retry_backoff,
43
+ exceptions: config.retry_exceptions
44
+ }
45
+ end
46
+
47
+ ##
48
+ # Used to generate a Faraday connection
49
+ #
50
+ # @author Jason Colyer
51
+ # @since 1.0.0
52
+ # @param config [Object] An instance of {Readiness::Zendesk::Configuration}
53
+ # @return [Object]
54
+ def generate_connection(config)
55
+ Faraday.new('https://api.pagerduty.com') do |c|
56
+ c.request :retry, retry_options(config)
57
+ c.adapter Faraday.default_adapter
58
+ c.request :url_encoded
59
+ c.headers['Content-Type'] = 'application/json'
60
+ c.headers['Accept'] = 'application/vnd.pagerduty+json;version=2'
61
+ c.headers['Authorization'] = "Token token=#{config.token}"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module Readiness.
4
+ module Readiness
5
+ # Defines the module Pagerduty
6
+ module Pagerduty
7
+ ##
8
+ # Defines the class Configuration within the module {Readiness::Pagerduty}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Configuration
13
+ attr_accessor :token, :retry_options, :retry_max, :retry_interval, :retry_randomness, :retry_backoff, :retry_exceptions
14
+
15
+ ##
16
+ # Creates a new {Readiness::Pagerduty::Configuration} instance
17
+ #
18
+ # @author Jason Colyer
19
+ # @since 1.0.0
20
+ # @example
21
+ # require 'support_readiness'
22
+ # config = Readiness::GitLab::Configuration.new
23
+ # config.token = 'test123abc'
24
+ # pp config
25
+ # # => #<Readiness::GitLab::Configuration:0x00007f352fdd1420
26
+ # @retry_backoff=2,
27
+ # @retry_exceptions=
28
+ # [Errno::ETIMEDOUT, "Timeout::Error", Faraday::TimeoutError, Faraday::RetriableResponse, Faraday::ConnectionFailed],
29
+ # @retry_interval=1,
30
+ # @retry_max=5,
31
+ # @retry_randomness=0.5,
32
+ # @token="test123abc">
33
+ def initialize
34
+ @token = ''
35
+ @retry_max = 5
36
+ @retry_interval = 1
37
+ @retry_randomness = 0.5
38
+ @retry_backoff = 2
39
+ @retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed]
40
+ end
41
+ end
42
+ end
43
+ end