Class: SDM::Accounts

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Defined in:
lib/svc.rb

Overview

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

  1. Users: humans who are authenticated through username and password or SSO.
  2. Service Accounts: machines that are authenticated using a service token.

See: Service User

Instance Method Summary collapse

Constructor Details

#initialize(host, insecure, parent) ⇒ Accounts

Returns a new instance of Accounts.



331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/svc.rb', line 331

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.



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/svc.rb', line 346

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. = Plumbing::(plumbing_response.)
  resp.meta = Plumbing::(plumbing_response.meta)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp.token = (plumbing_response.token)
  resp
end

#delete(id, deadline: nil) ⇒ Object

Delete removes an Account by ID.



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# File 'lib/svc.rb', line 437

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.



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/svc.rb', line 377

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. = Plumbing::(plumbing_response.)
  resp.meta = Plumbing::(plumbing_response.meta)
  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.



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/svc.rb', line 466

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 replaces all the fields of an Account by ID.



407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/svc.rb', line 407

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. = Plumbing::(plumbing_response.)
  resp.meta = Plumbing::(plumbing_response.meta)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end