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(channel, parent) ⇒ Accounts

Returns a new instance of Accounts.



731
732
733
734
735
736
737
738
# File 'lib/svc.rb', line 731

def initialize(channel, parent)
  begin
    @stub = V1::Accounts::Stub.new(nil, nil, channel_override: channel)
  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.



741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
# File 'lib/svc.rb', line 741

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.



836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
# File 'lib/svc.rb', line 836

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.



772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
# File 'lib/svc.rb', line 772

def get(
  id,
  deadline: nil
)
  req = V1::AccountGetRequest.new()
  if not @parent.snapshot_time.nil?
    req.meta = V1::GetRequestMetadata.new()
    req.meta.snapshot_at = @parent.snapshot_time
  end

  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.



865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
# File 'lib/svc.rb', line 865

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
  if not @parent.snapshot_time.nil?
    req.meta.snapshot_at = @parent.snapshot_time
  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.



806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'lib/svc.rb', line 806

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