Class: SDM::Workflows

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

Overview

Workflows are the collection of rules that define the resources to which access can be requested, the users that can request that access, and the mechanism for approving those requests which can either be automatic approval or a set of users authorized to approve the requests.

See Workflow.

Instance Method Summary collapse

Constructor Details

#initialize(channel, parent) ⇒ Workflows

Returns a new instance of Workflows.



6202
6203
6204
6205
6206
6207
6208
6209
# File 'lib/svc.rb', line 6202

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

Instance Method Details

#create(workflow, deadline: nil) ⇒ Object

Create creates a new workflow and requires a name for the workflow.



6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
# File 'lib/svc.rb', line 6212

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

  req.workflow = Plumbing::convert_workflow_to_plumbing(workflow)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.create(req, metadata: @parent.("Workflows.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 = WorkflowCreateResponse.new()
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp.workflow = Plumbing::convert_workflow_to_porcelain(plumbing_response.workflow)
  resp
end

#delete(id, deadline: nil) ⇒ Object

Delete deletes an existing workflow.



6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
# File 'lib/svc.rb', line 6275

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

  req.id = (id)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.delete(req, metadata: @parent.("Workflows.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 = WorkflowDeleteResponse.new()
  resp.id = (plumbing_response.id)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

#get(id, deadline: nil) ⇒ Object

Get reads one workflow by ID.



6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
# File 'lib/svc.rb', line 6241

def get(
  id,
  deadline: nil
)
  req = V1::WorkflowGetRequest.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.("Workflows.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 = WorkflowGetResponse.new()
  resp.meta = Plumbing::(plumbing_response.meta)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp.workflow = Plumbing::convert_workflow_to_porcelain(plumbing_response.workflow)
  resp
end

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

Lists existing workflows.



6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
# File 'lib/svc.rb', line 6333

def list(
  filter,
  *args,
  deadline: nil
)
  req = V1::WorkflowListRequest.new()
  req.meta = V1::ListRequestMetadata.new()
  if @parent.page_limit > 0
    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.("Workflows.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.workflows.each do |plumbing_item|
        g.yield Plumbing::convert_workflow_to_porcelain(plumbing_item)
      end
      break if plumbing_response.meta.next_cursor == ""
      req.meta.cursor = plumbing_response.meta.next_cursor
    end
  }
  resp
end

#update(workflow, deadline: nil) ⇒ Object

Update updates an existing workflow.



6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
# File 'lib/svc.rb', line 6304

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

  req.workflow = Plumbing::convert_workflow_to_plumbing(workflow)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.update(req, metadata: @parent.("Workflows.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 = WorkflowUpdateResponse.new()
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp.workflow = Plumbing::convert_workflow_to_porcelain(plumbing_response.workflow)
  resp
end