Class: SDM::Nodes

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

Overview

Nodes make up the strongDM network, and allow your users to connect securely to your resources. There are two types of nodes:

  • Gateways are the entry points into network. They listen for connection from the strongDM client, and provide access to databases and servers.
  • Relays are used to extend the strongDM network into segmented subnets. They provide access to databases and servers but do not listen for incoming connections.

See: Gateway Relay

Instance Method Summary collapse

Constructor Details

#initialize(channel, parent) ⇒ Nodes

Returns a new instance of Nodes.



1169
1170
1171
1172
1173
1174
1175
1176
# File 'lib/svc.rb', line 1169

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

Instance Method Details

#create(node, deadline: nil) ⇒ Object

Create registers a new Node.



1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
# File 'lib/svc.rb', line 1179

def create(
  node,
  deadline: nil
)
  req = V1::NodeCreateRequest.new()

  req.node = Plumbing::convert_node_to_plumbing(node)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.create(req, metadata: @parent.("Nodes.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 = NodeCreateResponse.new()
  resp.meta = Plumbing::(plumbing_response.meta)
  resp.node = Plumbing::convert_node_to_porcelain(plumbing_response.node)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp.token = (plumbing_response.token)
  resp
end

#delete(id, deadline: nil) ⇒ Object

Delete removes a Node by ID.



1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
# File 'lib/svc.rb', line 1274

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

  req.id = (id)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.delete(req, metadata: @parent.("Nodes.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 = NodeDeleteResponse.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 Node by ID.



1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
# File 'lib/svc.rb', line 1210

def get(
  id,
  deadline: nil
)
  req = V1::NodeGetRequest.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.("Nodes.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 = NodeGetResponse.new()
  resp.meta = Plumbing::(plumbing_response.meta)
  resp.node = Plumbing::convert_node_to_porcelain(plumbing_response.node)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end

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

List gets a list of Nodes matching a given set of criteria.



1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
# File 'lib/svc.rb', line 1303

def list(
  filter,
  *args,
  deadline: nil
)
  req = V1::NodeListRequest.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.("Nodes.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.nodes.each do |plumbing_item|
        g.yield Plumbing::convert_node_to_porcelain(plumbing_item)
      end
      break if plumbing_response.meta.next_cursor == ""
      req.meta.cursor = plumbing_response.meta.next_cursor
    end
  }
  resp
end

#update(node, deadline: nil) ⇒ Object

Update replaces all the fields of a Node by ID.



1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
# File 'lib/svc.rb', line 1244

def update(
  node,
  deadline: nil
)
  req = V1::NodeUpdateRequest.new()

  req.node = Plumbing::convert_node_to_plumbing(node)
  tries = 0
  plumbing_response = nil
  loop do
    begin
      plumbing_response = @stub.update(req, metadata: @parent.("Nodes.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 = NodeUpdateResponse.new()
  resp.meta = Plumbing::(plumbing_response.meta)
  resp.node = Plumbing::convert_node_to_porcelain(plumbing_response.node)
  resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
  resp
end