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 ProxyCluster Relay

Instance Method Summary collapse

Constructor Details

#initialize(channel, parent) ⇒ Nodes

Returns a new instance of Nodes.



3064
3065
3066
3067
3068
3069
3070
3071
# File 'lib/svc.rb', line 3064

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.



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
# File 'lib/svc.rb', line 3074

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.



3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
# File 'lib/svc.rb', line 3169

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.



3105
3106
3107
3108
3109
3110
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
# File 'lib/svc.rb', line 3105

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.



3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
# File 'lib/svc.rb', line 3198

def list(
  filter,
  *args,
  deadline: nil
)
  req = V1::NodeListRequest.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.("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.



3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
# File 'lib/svc.rb', line 3139

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