Class: SDM::Nodes

Inherits:
Object
  • Object
show all
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:

  1. Relay: creates connectivity to your datasources, while maintaining the egress-only nature of your firewall

  2. Gateways: a relay that also listens for connections from strongDM clients

Instance Method Summary collapse

Constructor Details

#initialize(host, insecure, parent) ⇒ Nodes

Returns a new instance of Nodes.



504
505
506
507
508
509
510
511
512
513
514
515
516
# File 'lib/svc.rb', line 504

def initialize(host, insecure, parent)
    begin
        if insecure
            @stub = V1::Nodes::Stub.new(host, :this_channel_is_insecure)
        else
            cred = GRPC::Core::ChannelCredentials.new()
            @stub = V1::Nodes::Stub.new(host, cred)
        end
    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.



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/svc.rb', line 518

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.token = (plumbing_response.token)
    resp.rate_limit = Plumbing::(plumbing_response.rate_limit)
    resp
end

#delete(id, deadline: nil) ⇒ Object

Delete removes a Node by ID.



612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
# File 'lib/svc.rb', line 612

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.



550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/svc.rb', line 550

def get(
id \
,
 deadline:nil)
    req = V1::NodeGetRequest.new()
			
    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.



642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/svc.rb', line 642

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
			
    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 patches a Node by ID.



581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'lib/svc.rb', line 581

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