Class: SDM::Groups

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

Overview

A Group is a set of principals.

See Group.

Instance Method Summary collapse

Constructor Details

#initialize(channel, parent) ⇒ Groups

Returns a new instance of Groups.



2993
2994
2995
2996
2997
2998
2999
3000
# File 'lib/svc.rb', line 2993

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

Instance Method Details

#create(group, deadline: nil) ⇒ Object

Create registers a new Group.



3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
# File 'lib/svc.rb', line 3003

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

  req.group = Plumbing::convert_group_to_plumbing(group)
  # Execute before interceptor hooks
  req = @parent.interceptor.execute_before("Groups.Create", self, req)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.create(req, metadata: @parent.("Groups.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("Groups.Create", self, req, plumbing_response)

  resp = GroupCreateResponse.new()
  resp.group = Plumbing::convert_group_to_porcelain(plumbing_response.group)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

#create_from_roles(role_ids, commit, deadline: nil) ⇒ Object



3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
# File 'lib/svc.rb', line 3036

def create_from_roles(
  role_ids,
  commit,
  deadline: nil
)
  req = V1::GroupCreateFromRolesRequest.new()

  req.role_ids += (role_ids)
  req.commit = (commit)
  # Execute before interceptor hooks
  req = @parent.interceptor.execute_before("Groups.CreateFromRoles", self, req)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.create_from_roles(req, metadata: @parent.("Groups.CreateFromRoles", 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("Groups.CreateFromRoles", self, req, plumbing_response)

  resp = GroupCreateFromRolesResponse.new()
  resp.group_from_role = Plumbing::convert_repeated_group_from_role_to_porcelain(plumbing_response.group_from_role)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

#delete(id, deadline: nil) ⇒ Object

Delete removes a Group by ID.



3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
# File 'lib/svc.rb', line 3145

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

  req.id = (id)
  # Execute before interceptor hooks
  req = @parent.interceptor.execute_before("Groups.Delete", self, req)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.delete(req, metadata: @parent.("Groups.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("Groups.Delete", self, req, plumbing_response)

  resp = GroupDeleteResponse.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 Group by ID.



3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
# File 'lib/svc.rb', line 3072

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

  req.id = (id)
  # Execute before interceptor hooks
  req = @parent.interceptor.execute_before("Groups.Get", self, req)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.get(req, metadata: @parent.("Groups.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("Groups.Get", self, req, plumbing_response)

  resp = GroupGetResponse.new()
  resp.group = Plumbing::convert_group_to_porcelain(plumbing_response.group)
  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 Groups matching a given set of criteria.



3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
# File 'lib/svc.rb', line 3179

def list(
  filter,
  *args,
  deadline: nil
)
  req = V1::GroupListRequest.new()
  req.meta = V1::ListRequestMetadata.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.("Groups.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.groups.each do |plumbing_item|
        g.yield Plumbing::convert_group_to_porcelain(plumbing_item)
      end
      break if plumbing_response.meta.next_cursor == ""
      req.meta.cursor = plumbing_response.meta.next_cursor
    end
  }
  resp
end

#update(group, deadline: nil) ⇒ Object

Update replaces all the fields of a Group by ID.



3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
# File 'lib/svc.rb', line 3111

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

  req.group = Plumbing::convert_group_to_plumbing(group)
  # Execute before interceptor hooks
  req = @parent.interceptor.execute_before("Groups.Update", self, req)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.update(req, metadata: @parent.("Groups.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("Groups.Update", self, req, plumbing_response)

  resp = GroupUpdateResponse.new()
  resp.group = Plumbing::convert_group_to_porcelain(plumbing_response.group)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end