Class: SDM::Accounts

Inherits:
Object
  • Object
show all
Defined in:
lib/svc.rb

Overview

Accounts are users that have access to strongDM. There are two types of accounts:

  1. **Regular users:** humans who are authenticated through username and password or SSO

  2. **Service users:** machines that are authneticated using a service token

Instance Method Summary collapse

Constructor Details

#initialize(host, insecure, parent) ⇒ Accounts

Returns a new instance of Accounts.



320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/svc.rb', line 320

def initialize(host, insecure, parent)
  begin
    if insecure
      @stub = V1::Accounts::Stub.new(host, :this_channel_is_insecure)
    else
      cred = GRPC::Core::ChannelCredentials.new()
      @stub = V1::Accounts::Stub.new(host, cred)
    end
  rescue => exception
    raise Plumbing::convert_error_to_porcelain(exception)
  end
  @parent = parent
end

Instance Method Details

#create(account, deadline: nil) ⇒ Object

Create registers a new Account.



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/svc.rb', line 335

def create(
  ,
  deadline: nil
)
  req = V1::AccountCreateRequest.new()

  req. = Plumbing::()
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.create(req, metadata: @parent.("Accounts.Create", req), deadline: deadline)
    rescue => exception
      if (@parent.shouldRetry(tries, exception))
        tries + +@parent.jitterSleep(tries)
        next
      end
      raise Plumbing::convert_error_to_porcelain(exception)
    end
    break
  end

  resp = AccountCreateResponse.new()
  resp.meta = Plumbing::(plumbing_response.meta)
  resp. = Plumbing::(plumbing_response.)
  resp.token = (plumbing_response.token)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

#delete(id, deadline: nil) ⇒ Object

Delete removes a Account by ID.



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/svc.rb', line 426

def delete(
  id,
  deadline: nil
)
  req = V1::AccountDeleteRequest.new()

  req.id = (id)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.delete(req, metadata: @parent.("Accounts.Delete", req), deadline: deadline)
    rescue => exception
      if (@parent.shouldRetry(tries, exception))
        tries + +@parent.jitterSleep(tries)
        next
      end
      raise Plumbing::convert_error_to_porcelain(exception)
    end
    break
  end

  resp = AccountDeleteResponse.new()
  resp.meta = Plumbing::(plumbing_response.meta)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

#get(id, deadline: nil) ⇒ Object

Get reads one Account by ID.



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/svc.rb', line 366

def get(
  id,
  deadline: nil
)
  req = V1::AccountGetRequest.new()

  req.id = (id)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.get(req, metadata: @parent.("Accounts.Get", req), deadline: deadline)
    rescue => exception
      if (@parent.shouldRetry(tries, exception))
        tries + +@parent.jitterSleep(tries)
        next
      end
      raise Plumbing::convert_error_to_porcelain(exception)
    end
    break
  end

  resp = AccountGetResponse.new()
  resp.meta = Plumbing::(plumbing_response.meta)
  resp. = Plumbing::(plumbing_response.)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

#list(filter, *args, deadline: nil) ⇒ Object

List gets a list of Accounts matching a given set of criteria.



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/svc.rb', line 455

def list(
  filter,
  *args,
  deadline: nil
)
  req = V1::AccountListRequest.new()
  req.meta = V1::ListRequestMetadata.new()
  page_size_option = @parent._test_options["PageSize"]
  if page_size_option.is_a? Integer
    req.meta.limit = page_size_option
  end

  req.filter = Plumbing::quote_filter_args(filter, *args)
  resp = Enumerator::Generator.new { |g|
    tries = 0
    loop do
      begin
        plumbing_response = @stub.list(req, metadata: @parent.("Accounts.List", req), deadline: deadline)
      rescue => exception
        if (@parent.shouldRetry(tries, exception))
          tries + +@parent.jitterSleep(tries)
          next
        end
        raise Plumbing::convert_error_to_porcelain(exception)
      end
      tries = 0
      plumbing_response.accounts.each do |plumbing_item|
        g.yield Plumbing::(plumbing_item)
      end
      break if plumbing_response.meta.next_cursor == ""
      req.meta.cursor = plumbing_response.meta.next_cursor
    end
  }
  resp
end

#update(account, deadline: nil) ⇒ Object

Update patches a Account by ID.



396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/svc.rb', line 396

def update(
  ,
  deadline: nil
)
  req = V1::AccountUpdateRequest.new()

  req. = Plumbing::()
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.update(req, metadata: @parent.("Accounts.Update", req), deadline: deadline)
    rescue => exception
      if (@parent.shouldRetry(tries, exception))
        tries + +@parent.jitterSleep(tries)
        next
      end
      raise Plumbing::convert_error_to_porcelain(exception)
    end
    break
  end

  resp = AccountUpdateResponse.new()
  resp.meta = Plumbing::(plumbing_response.meta)
  resp. = Plumbing::(plumbing_response.)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end