warrant 1.0.0 → 1.1.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: 5c44e60e9d2c5fef31622621a356033848368ba16854759d81ec6797ba3a0dbe
4
- data.tar.gz: 146f08b5bac7ed1db618f39ef8e6c7f0a2884b8167e65c3812d2ee0d41fcf2c6
3
+ metadata.gz: 6fc7f30432a9ab516978da52e77811011ee0625a819124ad8dcb5b20d8610a34
4
+ data.tar.gz: 54dc068a58982fc5f8fdcc2d781ce5b6b5ec320c3f7a5dfdbd8338eaa20fac93
5
5
  SHA512:
6
- metadata.gz: 27f2a30747e35747387f294a05d221571488fc60f4c4522257770352eeea31ad1785c77b5579c2de031265c07ade7f9fe49b7cb91962282a662e53e3945ba758
7
- data.tar.gz: 59c909e93d57c04301bcf13600573e073ebe61c83493ceed1c280c9629745cfe1cc40e089d71a804608bd768d39039563cfae2cde9410c30d19a9d007f29a35a
6
+ metadata.gz: 4e892e951b8107a9d6bdeb621a1ee2fb1674c8a9195eb7271e127f77961d5cfa8fe673e93cfd6bb2784452630ade845b65aa3455379c169580ea8b32fb9dad2f
7
+ data.tar.gz: b7e7c396ff14cbc500b9bf1e1882db09b84002e78fc2ffa11a019de0cc3da25d60766f78b6650075baa648125c87ed9ed48e8cf250cc2a41818fef5b3d2b9209
@@ -164,5 +164,71 @@ module Warrant
164
164
  def update(params = {})
165
165
  return Tenant.update(tenant_id, params)
166
166
  end
167
+
168
+ # Add a user to a tenant
169
+ #
170
+ # @param user_id [String] The user_id of the user you want to add to the tenant.
171
+ #
172
+ # @return [Warrant] warrant assigning user to the tenant
173
+ #
174
+ # @raise [Warrant::InternalError]
175
+ # @raise [Warrant::InvalidParameterError]
176
+ # @raise [Warrant::InvalidRequestError]
177
+ # @raise [Warrant::NotFoundError]
178
+ # @raise [Warrant::UnauthorizedError]
179
+ # @raise [Warrant::WarrantError]
180
+ def add_user(user_id)
181
+ return User.add_to_tenant(tenant_id, user_id)
182
+ end
183
+
184
+ # Remove a user from a tenant
185
+ #
186
+ # @param user_id [String] The user_id of the user you want to remove from the tenant.
187
+ #
188
+ # @return [nil] if remove was successful
189
+ #
190
+ # @raise [Warrant::InternalError]
191
+ # @raise [Warrant::InvalidParameterError]
192
+ # @raise [Warrant::InvalidRequestError]
193
+ # @raise [Warrant::NotFoundError]
194
+ # @raise [Warrant::UnauthorizedError]
195
+ # @raise [Warrant::WarrantError]
196
+ def remove_user(user_id)
197
+ return User.remove_from_tenant(tenant_id, user_id)
198
+ end
199
+
200
+ # List all tenants for a user
201
+ #
202
+ # @param user_id [String] The user_id of the user from which to fetch tenants
203
+ #
204
+ # @return [Array<Tenant>] all tenants for the user
205
+ #
206
+ # @raise [Warrant::InternalError]
207
+ # @raise [Warrant::InvalidRequestError]
208
+ # @raise [Warrant::UnauthorizedError]
209
+ # @raise [Warrant::WarrantError]
210
+ def self.list_for_user(user_id)
211
+ res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/tenants"))
212
+
213
+ case res
214
+ when Net::HTTPSuccess
215
+ tenants = JSON.parse(res.body)
216
+ tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
217
+ else
218
+ APIOperations.raise_error(res)
219
+ end
220
+ end
221
+
222
+ # List all users for a tenant
223
+ #
224
+ # @return [Array<User>] all users for the tenant
225
+ #
226
+ # @raise [Warrant::InternalError]
227
+ # @raise [Warrant::InvalidRequestError]
228
+ # @raise [Warrant::UnauthorizedError]
229
+ # @raise [Warrant::WarrantError]
230
+ def list_users
231
+ return User.list_for_tenant(tenant_id)
232
+ end
167
233
  end
168
234
  end
@@ -249,7 +249,6 @@ module Warrant
249
249
 
250
250
  # Assign a permission to a user
251
251
  #
252
- # @param user_id [String] The user_id of the user you want to assign a permission to.
253
252
  # @param permission_id [String] The permission_id of the permission you want to assign to a user.
254
253
  #
255
254
  # @return [Permission] assigned permission
@@ -270,7 +269,6 @@ module Warrant
270
269
 
271
270
  # Remove a permission from a user
272
271
  #
273
- # @param user_id [String] The user_id of the user you want to assign a permission to.
274
272
  # @param permission_id [String] The permission_id of the permission you want to assign to a user.
275
273
  #
276
274
  # @return [nil] if remove was successful
@@ -319,5 +317,89 @@ module Warrant
319
317
  }]
320
318
  )
321
319
  end
320
+
321
+ # Add a user to a tenant
322
+ #
323
+ # @param tenant_id [String] The tenant_id of the tenant you want to assign a user to.
324
+ # @param user_id [String] The user_id of the user you want to add to the tenant.
325
+ #
326
+ # @return [Warrant] warrant assigning user to the tenant
327
+ #
328
+ # @raise [Warrant::InternalError]
329
+ # @raise [Warrant::InvalidParameterError]
330
+ # @raise [Warrant::InvalidRequestError]
331
+ # @raise [Warrant::NotFoundError]
332
+ # @raise [Warrant::UnauthorizedError]
333
+ # @raise [Warrant::WarrantError]
334
+ def self.add_to_tenant(tenant_id, user_id)
335
+ res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}/users/#{user_id}"))
336
+
337
+ case res
338
+ when Net::HTTPSuccess
339
+ res_json = JSON.parse(res.body)
340
+ subject = Subject.new(res_json['subject']['objectType'], res_json['subject']['objectId'])
341
+ Warrant.new(res_json['objectType'], res_json['objectId'], res_json['relation'], subject)
342
+ else
343
+ APIOperations.raise_error(res)
344
+ end
345
+ end
346
+
347
+ # Remove a user from a tenant
348
+ #
349
+ # @param tenant_id [String] The tenant_id of the tenant you want to remove the user from.
350
+ # @param user_id [String] The user_id of the user you want to remove from the tenant.
351
+ #
352
+ # @return [nil] if remove was successful
353
+ #
354
+ # @raise [Warrant::InternalError]
355
+ # @raise [Warrant::InvalidParameterError]
356
+ # @raise [Warrant::InvalidRequestError]
357
+ # @raise [Warrant::NotFoundError]
358
+ # @raise [Warrant::UnauthorizedError]
359
+ # @raise [Warrant::WarrantError]
360
+ def self.remove_from_tenant(tenant_id, user_id)
361
+ res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}/users/#{user_id}"))
362
+
363
+ case res
364
+ when Net::HTTPSuccess
365
+ return
366
+ else
367
+ APIOperations.raise_error(res)
368
+ end
369
+ end
370
+
371
+ # List all users for a tenant
372
+ #
373
+ # @param tenant_id [String] The tenant_id of the tenant from which to fetch users
374
+ #
375
+ # @return [Array<User>] all users for the tenant
376
+ #
377
+ # @raise [Warrant::InternalError]
378
+ # @raise [Warrant::InvalidRequestError]
379
+ # @raise [Warrant::UnauthorizedError]
380
+ # @raise [Warrant::WarrantError]
381
+ def self.list_for_tenant(tenant_id)
382
+ res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}/users"))
383
+
384
+ case res
385
+ when Net::HTTPSuccess
386
+ users = JSON.parse(res.body)
387
+ users.map{ |user| User.new(user['userId'], user['email'], user['createdAt']) }
388
+ else
389
+ APIOperations.raise_error(res)
390
+ end
391
+ end
392
+
393
+ # List all tenants for a user
394
+ #
395
+ # @return [Array<Tenant>] all tenants for the user
396
+ #
397
+ # @raise [Warrant::InternalError]
398
+ # @raise [Warrant::InvalidRequestError]
399
+ # @raise [Warrant::UnauthorizedError]
400
+ # @raise [Warrant::WarrantError]
401
+ def list_tenants
402
+ return Tenant.list_for_user(user_id)
403
+ end
322
404
  end
323
405
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Warrant
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Warrant
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-14 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby library for the Warrant API at https://warrant.dev.
14
14
  email: hello@warrant.dev
@@ -46,7 +46,7 @@ metadata:
46
46
  source_code_uri: https://github.com/warrant-dev/warrant-ruby
47
47
  changelog_uri: https://github.com/warrant-dev/warrant-ruby/CHANGELOG.md
48
48
  documentation_uri: https://docs.warrant.dev/
49
- post_install_message:
49
+ post_install_message:
50
50
  rdoc_options: []
51
51
  require_paths:
52
52
  - lib
@@ -61,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.2.14
65
- signing_key:
64
+ rubygems_version: 3.3.11
65
+ signing_key:
66
66
  specification_version: 4
67
67
  summary: Warrant Ruby Library
68
68
  test_files: []