Class: SDM::Policies

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

Overview

Policies are the collection of one or more statements that enforce fine-grained access control for the users of an organization.

See Policy.

Instance Method Summary collapse

Constructor Details

#initialize(channel, parent) ⇒ Policies



5907
5908
5909
5910
5911
5912
5913
5914
# File 'lib/svc.rb', line 5907

def initialize(channel, parent)
  begin
    @stub = V1::Policies::Stub.new(nil, nil, channel_override: channel)
  rescue => exception
    raise Plumbing::convert_error_to_porcelain(exception)
  end
  @parent = parent
end

Instance Method Details

#create(policy, deadline: nil) ⇒ Object

Create creates a new Policy.



5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
# File 'lib/svc.rb', line 5917

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

  req.policy = Plumbing::convert_policy_to_plumbing(policy)
  # Execute before interceptor hooks
  req = @parent.interceptor.execute_before("Policies.Create", self, req)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.create(req, metadata: @parent.("Policies.Create", req), deadline: deadline)
    rescue => exception
      if (@parent.shouldRetry(tries, exception, deadline))
        tries + +sleep(@parent.exponentialBackoff(tries, deadline))
        next
      end
      raise Plumbing::convert_error_to_porcelain(exception)
    end
    break
  end

  # Execute after interceptor hooks
  plumbing_response = @parent.interceptor.execute_after("Policies.Create", self, req, plumbing_response)

  resp = PolicyCreateResponse.new()
  resp.policy = Plumbing::convert_policy_to_porcelain(plumbing_response.policy)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

#delete(id, deadline: nil) ⇒ Object

Delete removes a Policy by ID.



5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
# File 'lib/svc.rb', line 5951

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

  req.id = (id)
  # Execute before interceptor hooks
  req = @parent.interceptor.execute_before("Policies.Delete", self, req)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.delete(req, metadata: @parent.("Policies.Delete", req), deadline: deadline)
    rescue => exception
      if (@parent.shouldRetry(tries, exception, deadline))
        tries + +sleep(@parent.exponentialBackoff(tries, deadline))
        next
      end
      raise Plumbing::convert_error_to_porcelain(exception)
    end
    break
  end

  # Execute after interceptor hooks
  plumbing_response = @parent.interceptor.execute_after("Policies.Delete", self, req, plumbing_response)

  resp = PolicyDeleteResponse.new()
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

#get(id, deadline: nil) ⇒ Object

Get reads one Policy by ID.



6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
# File 'lib/svc.rb', line 6018

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

  req.id = (id)
  # Execute before interceptor hooks
  req = @parent.interceptor.execute_before("Policies.Get", self, req)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.get(req, metadata: @parent.("Policies.Get", req), deadline: deadline)
    rescue => exception
      if (@parent.shouldRetry(tries, exception, deadline))
        tries + +sleep(@parent.exponentialBackoff(tries, deadline))
        next
      end
      raise Plumbing::convert_error_to_porcelain(exception)
    end
    break
  end

  # Execute after interceptor hooks
  plumbing_response = @parent.interceptor.execute_after("Policies.Get", self, req, plumbing_response)

  resp = PolicyGetResponse.new()
  resp.meta = Plumbing::(plumbing_response.meta)
  resp.policy = Plumbing::convert_policy_to_porcelain(plumbing_response.policy)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

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

List gets a list of Policy matching a given set of criteria



6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
# File 'lib/svc.rb', line 6057

def list(
  filter,
  *args,
  deadline: nil
)
  req = V1::PolicyListRequest.new()
  req.meta = V1::.new()
  if not @parent.page_limit.nil?
    req.meta.limit = @parent.page_limit
  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.("Policies.List", req), deadline: deadline)
      rescue => exception
        if (@parent.shouldRetry(tries, exception, deadline))
          tries + +sleep(@parent.exponentialBackoff(tries, deadline))
          next
        end
        raise Plumbing::convert_error_to_porcelain(exception)
      end
      tries = 0
      plumbing_response.policies.each do |plumbing_item|
        g.yield Plumbing::convert_policy_to_porcelain(plumbing_item)
      end
      break if plumbing_response.meta.next_cursor == ""
      req.meta.cursor = plumbing_response.meta.next_cursor
    end
  }
  resp
end

#update(policy, deadline: nil) ⇒ Object

Update replaces all the fields of a Policy by ID.



5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
# File 'lib/svc.rb', line 5984

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

  req.policy = Plumbing::convert_policy_to_plumbing(policy)
  # Execute before interceptor hooks
  req = @parent.interceptor.execute_before("Policies.Update", self, req)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.update(req, metadata: @parent.("Policies.Update", req), deadline: deadline)
    rescue => exception
      if (@parent.shouldRetry(tries, exception, deadline))
        tries + +sleep(@parent.exponentialBackoff(tries, deadline))
        next
      end
      raise Plumbing::convert_error_to_porcelain(exception)
    end
    break
  end

  # Execute after interceptor hooks
  plumbing_response = @parent.interceptor.execute_after("Policies.Update", self, req, plumbing_response)

  resp = PolicyUpdateResponse.new()
  resp.policy = Plumbing::convert_policy_to_porcelain(plumbing_response.policy)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end