govuk-connect 0.2.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/govuk_connect/cli.rb +218 -190
- data/lib/govuk_connect/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71cb0967c5cf0450aa63b5abbf25ce9d964d7ddfcb97a57fea0c011f59961624
|
4
|
+
data.tar.gz: ee788418b7e3e127bc4f5bd8ceb7cf35b37a9df889a4200f20fa392b37701882
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d684a2ef79be515cdb3c1f71abb8dc5ce34fe7ca4315d2e62403a583a8e220e03cfc7c5ef1980211a741e1ca7603b0063d20d35b4974eec378ecd26e67af242
|
7
|
+
data.tar.gz: d811b9e5403750cc048e78d8c440bddb0bf206690301b22a7d76f2ab306a2967078f0932d785f757366bd977a45d0befc01c2a6f4202edce79d41d0386d1df18
|
data/lib/govuk_connect/cli.rb
CHANGED
@@ -15,37 +15,38 @@ class GovukConnect::CLI
|
|
15
15
|
self.class.bold(string)
|
16
16
|
end
|
17
17
|
|
18
|
-
USAGE_BANNER = "Usage: govuk
|
18
|
+
USAGE_BANNER = "Usage: gds govuk connect TYPE TARGET [options]".freeze
|
19
19
|
|
20
20
|
EXAMPLES = <<-EXAMPLES.freeze
|
21
|
-
govuk
|
21
|
+
gds govuk connect ssh --environment integration backend
|
22
22
|
|
23
|
-
govuk
|
23
|
+
gds govuk connect scp-push --environment integration backend filename.txt /tmp/
|
24
24
|
|
25
|
-
govuk
|
25
|
+
gds govuk connect scp-pull --environment integration backend /tmp/filename.txt ~/Downloads/
|
26
26
|
|
27
|
-
govuk
|
27
|
+
gds govuk connect app-console --environment staging publishing-api
|
28
28
|
|
29
|
-
govuk
|
29
|
+
gds govuk connect app-dbconsole -e integration whitehall_backend/whitehall
|
30
|
+
|
31
|
+
gds govuk connect rabbitmq -e staging aws/rabbitmq
|
30
32
|
EXAMPLES
|
31
33
|
|
32
34
|
MACHINE_TARGET_DESCRIPTION = <<-DOCS.freeze
|
33
|
-
The ssh, rabbitmq
|
34
|
-
machines.
|
35
|
+
The ssh, scp-*, rabbitmq connection types target machines.
|
35
36
|
|
36
37
|
The machine can be specified by name, for example:
|
37
38
|
|
38
|
-
govuk
|
39
|
+
gds govuk connect ssh -e integration #{bold('backend')}
|
39
40
|
|
40
41
|
If the hosting provider is ambiguous, you'll need to specify it prior
|
41
42
|
to the name, for example:
|
42
43
|
|
43
|
-
govuk
|
44
|
+
gds govuk connect ssh -e staging #{bold('aws/')}backend
|
44
45
|
|
45
46
|
If you want to connect to a specific machine, you can specify a number
|
46
47
|
after the name, for example:
|
47
48
|
|
48
|
-
govuk
|
49
|
+
gds govuk connect ssh -e integration backend#{bold(':2')}
|
49
50
|
DOCS
|
50
51
|
|
51
52
|
APP_TARGET_DESCRIPTION = <<-DOCS.freeze
|
@@ -54,17 +55,17 @@ class GovukConnect::CLI
|
|
54
55
|
|
55
56
|
The application is specified by name, for example:
|
56
57
|
|
57
|
-
govuk
|
58
|
+
gds govuk connect app-console -e integration #{bold('publishing-api')}
|
58
59
|
|
59
60
|
If the node class is ambiguous, you'll need to specify it prior to
|
60
61
|
the name, for example:
|
61
62
|
|
62
|
-
govuk
|
63
|
+
gds govuk connect app-console -e integration #{bold('whitehall_backend/')}whitehall
|
63
64
|
|
64
65
|
If you want to connect to a specific machine, you can specify a
|
65
66
|
number after the name, for example:
|
66
67
|
|
67
|
-
govuk
|
68
|
+
gds govuk connect app-console -e integration publishing-api#{bold(':2')}
|
68
69
|
DOCS
|
69
70
|
|
70
71
|
CONNECTION_TYPE_DESCRIPTIONS = {
|
@@ -72,28 +73,21 @@ class GovukConnect::CLI
|
|
72
73
|
"app-console" => "Launch a console for an application. For example, a rails console when connecting to a Rails application.",
|
73
74
|
"app-dbconsole" => "Launch a console for the database for an application.",
|
74
75
|
"rabbitmq" => "Setup port forwarding to the RabbitMQ admin interface.",
|
75
|
-
"sidekiq-monitoring" => "Setup port forwarding to the Sidekiq Monitoring application.",
|
76
76
|
}.freeze
|
77
77
|
|
78
78
|
RABBITMQ_PORT = 15_672
|
79
|
-
SIDEKIQ_MONITORING_PORT = 3211
|
80
79
|
|
81
80
|
JUMPBOXES = {
|
82
81
|
test: {
|
83
82
|
aws: "jumpbox.pink.test.govuk.digital",
|
84
83
|
},
|
85
|
-
ci: {
|
86
|
-
carrenza: "ci-jumpbox.integration.publishing.service.gov.uk",
|
87
|
-
},
|
88
84
|
integration: {
|
89
85
|
aws: "jumpbox.integration.publishing.service.gov.uk",
|
90
86
|
},
|
91
87
|
staging: {
|
92
|
-
carrenza: "jumpbox.staging.publishing.service.gov.uk",
|
93
88
|
aws: "jumpbox.staging.govuk.digital",
|
94
89
|
},
|
95
90
|
production: {
|
96
|
-
carrenza: "jumpbox.publishing.service.gov.uk",
|
97
91
|
aws: "jumpbox.production.govuk.digital",
|
98
92
|
},
|
99
93
|
}.freeze
|
@@ -260,29 +254,7 @@ class GovukConnect::CLI
|
|
260
254
|
|
261
255
|
def govuk_node_list_classes(environment, hosting)
|
262
256
|
log "debug: looking up classes in #{hosting}/#{environment}"
|
263
|
-
|
264
|
-
"ssh",
|
265
|
-
"-o",
|
266
|
-
"ConnectTimeout=2", # Show a failure quickly
|
267
|
-
*ssh_identity_arguments,
|
268
|
-
user_at_host(
|
269
|
-
ssh_username,
|
270
|
-
jumpbox_for_environment_and_hosting(environment, hosting),
|
271
|
-
),
|
272
|
-
"govuk_node_list --classes",
|
273
|
-
].join(" ")
|
274
|
-
|
275
|
-
log "debug: running command: #{command}"
|
276
|
-
output, status = Open3.capture2(command)
|
277
|
-
|
278
|
-
unless status.success?
|
279
|
-
error "\nerror: command failed: #{command}"
|
280
|
-
print_empty_line
|
281
|
-
print_ssh_username_configuration_help
|
282
|
-
exit 1
|
283
|
-
end
|
284
|
-
|
285
|
-
classes = output.split("\n").sort
|
257
|
+
classes = ssh_capture("govuk_node_list --classes").sort
|
286
258
|
|
287
259
|
log "debug: classes:"
|
288
260
|
classes.each { |c| log " - #{c}" }
|
@@ -290,7 +262,16 @@ class GovukConnect::CLI
|
|
290
262
|
classes
|
291
263
|
end
|
292
264
|
|
293
|
-
def get_domains_for_node_class(target, environment, hosting
|
265
|
+
def get_domains_for_node_class(target, environment, hosting)
|
266
|
+
domains = ssh_capture(environment, hosting, "govuk_node_list -c #{target}")
|
267
|
+
if hosting == :aws
|
268
|
+
domains
|
269
|
+
else
|
270
|
+
domains.sort
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
def ssh_capture(environment, hosting, remote_command)
|
294
275
|
command = [
|
295
276
|
"ssh",
|
296
277
|
"-o",
|
@@ -300,19 +281,20 @@ class GovukConnect::CLI
|
|
300
281
|
ssh_username,
|
301
282
|
jumpbox_for_environment_and_hosting(environment, hosting),
|
302
283
|
),
|
303
|
-
|
284
|
+
remote_command,
|
304
285
|
].join(" ")
|
305
286
|
|
287
|
+
log "debug: running command: #{command}"
|
306
288
|
output, status = Open3.capture2(command)
|
307
289
|
|
308
290
|
unless status.success?
|
309
|
-
error "
|
291
|
+
error "\nerror: command failed: #{command}"
|
310
292
|
print_empty_line
|
311
293
|
print_ssh_username_configuration_help
|
312
294
|
exit 1
|
313
295
|
end
|
314
296
|
|
315
|
-
output.split("\n")
|
297
|
+
output.split("\n")
|
316
298
|
end
|
317
299
|
|
318
300
|
def govuk_directory
|
@@ -326,7 +308,6 @@ class GovukConnect::CLI
|
|
326
308
|
govuk_directory,
|
327
309
|
"govuk-puppet",
|
328
310
|
{
|
329
|
-
carrenza: "hieradata",
|
330
311
|
aws: "hieradata_aws",
|
331
312
|
}[hosting],
|
332
313
|
)
|
@@ -397,7 +378,7 @@ class GovukConnect::CLI
|
|
397
378
|
print_empty_line
|
398
379
|
info "specify the node class and application mame, for example: "
|
399
380
|
node_classes.each do |node_class|
|
400
|
-
info "\n govuk
|
381
|
+
info "\n gds govuk connect app-console -e #{environment} #{node_class}/#{app_name}"
|
401
382
|
end
|
402
383
|
print_empty_line
|
403
384
|
|
@@ -432,29 +413,13 @@ class GovukConnect::CLI
|
|
432
413
|
return hosting if hosting
|
433
414
|
|
434
415
|
aws_node_types = govuk_node_list_classes(environment, :aws)
|
435
|
-
carrenza_node_types = govuk_node_list_classes(environment, :carrenza)
|
436
416
|
|
437
|
-
if aws_node_types.include?(node_type)
|
438
|
-
carrenza_node_types.include?(node_type)
|
439
|
-
|
440
|
-
error "error: ambiguous hosting for #{node_type} in #{environment}"
|
441
|
-
print_empty_line
|
442
|
-
info "specify the hosting provider and node type, for example: "
|
443
|
-
hosting_providers.each do |hosting_provider|
|
444
|
-
info "\n govuk-connect ssh #{bold(hosting_provider)}/#{node_type}"
|
445
|
-
end
|
446
|
-
info "\n"
|
447
|
-
|
448
|
-
exit 1
|
449
|
-
elsif aws_node_types.include?(node_type)
|
417
|
+
if aws_node_types.include?(node_type)
|
450
418
|
:aws
|
451
|
-
elsif carrenza_node_types.include?(node_type)
|
452
|
-
:carrenza
|
453
419
|
else
|
454
420
|
error "error: couldn't find #{node_type} in #{environment}"
|
455
421
|
|
456
|
-
|
457
|
-
similar_node_types = strings_similar_to(node_type, all_node_types)
|
422
|
+
similar_node_types = strings_similar_to(node_type, aws_node_types)
|
458
423
|
|
459
424
|
if similar_node_types.any?
|
460
425
|
info "\ndid you mean:"
|
@@ -489,17 +454,6 @@ class GovukConnect::CLI
|
|
489
454
|
return :aws
|
490
455
|
end
|
491
456
|
|
492
|
-
carrenza_app_names = application_names_from_node_class_data(
|
493
|
-
environment,
|
494
|
-
:carrenza,
|
495
|
-
)
|
496
|
-
|
497
|
-
if carrenza_app_names.include? app_name
|
498
|
-
log "debug: #{app_name} is hosted in Carrenza"
|
499
|
-
|
500
|
-
return :carrenza
|
501
|
-
end
|
502
|
-
|
503
457
|
error "error: unknown hosting value '#{hosting}' for #{app_name}"
|
504
458
|
exit 1
|
505
459
|
end
|
@@ -565,71 +519,7 @@ class GovukConnect::CLI
|
|
565
519
|
)
|
566
520
|
log "debug: ssh to #{target} in #{environment}"
|
567
521
|
|
568
|
-
|
569
|
-
hosting, name, number = parse_hosting_name_and_number(target)
|
570
|
-
|
571
|
-
if name.end_with? ".internal"
|
572
|
-
ssh_target = name
|
573
|
-
hosting = :aws
|
574
|
-
elsif name.end_with? ".gov.uk"
|
575
|
-
ssh_target = name
|
576
|
-
hosting = :carrenza
|
577
|
-
else
|
578
|
-
# The hosting might not have been provided, so check if necessary
|
579
|
-
hosting ||= hosting_for_target_and_environment(target, environment)
|
580
|
-
|
581
|
-
domains = get_domains_for_node_class(
|
582
|
-
name,
|
583
|
-
environment,
|
584
|
-
hosting,
|
585
|
-
ssh_username,
|
586
|
-
)
|
587
|
-
|
588
|
-
if domains.length.zero?
|
589
|
-
error "error: couldn't find #{name} in #{hosting}/#{environment}"
|
590
|
-
|
591
|
-
node_types = govuk_node_list_classes(environment, hosting)
|
592
|
-
|
593
|
-
similar_node_types = strings_similar_to(name, node_types)
|
594
|
-
|
595
|
-
if similar_node_types.any?
|
596
|
-
info "\ndid you mean:"
|
597
|
-
similar_node_types.each { |s| info " - #{s}" }
|
598
|
-
else
|
599
|
-
info "\nall node types:"
|
600
|
-
node_types.each { |s| info " - #{s}" }
|
601
|
-
end
|
602
|
-
|
603
|
-
exit 1
|
604
|
-
elsif domains.length == 1
|
605
|
-
ssh_target = domains.first
|
606
|
-
|
607
|
-
info "There is #{bold('one machine')} to connect to"
|
608
|
-
else
|
609
|
-
n_machines = bold("#{domains.length} machines")
|
610
|
-
info "There are #{n_machines} of this class"
|
611
|
-
|
612
|
-
if number
|
613
|
-
unless number.positive?
|
614
|
-
print_empty_line
|
615
|
-
error "error: invalid machine number '#{number}', it must be > 0"
|
616
|
-
exit 1
|
617
|
-
end
|
618
|
-
|
619
|
-
unless number <= domains.length
|
620
|
-
print_empty_line
|
621
|
-
error "error: cannot connect to machine number: #{number}"
|
622
|
-
exit 1
|
623
|
-
end
|
624
|
-
|
625
|
-
ssh_target = domains[number - 1]
|
626
|
-
info "Connecting to number #{number}"
|
627
|
-
else
|
628
|
-
ssh_target = domains.sample
|
629
|
-
info "Connecting to a random machine (number #{domains.find_index(ssh_target) + 1})"
|
630
|
-
end
|
631
|
-
end
|
632
|
-
end
|
522
|
+
target, hosting = ssh_target(target, environment)
|
633
523
|
|
634
524
|
ssh_command = [
|
635
525
|
"ssh",
|
@@ -641,7 +531,7 @@ class GovukConnect::CLI
|
|
641
531
|
),
|
642
532
|
user_at_host(
|
643
533
|
ssh_username,
|
644
|
-
|
534
|
+
target,
|
645
535
|
),
|
646
536
|
]
|
647
537
|
|
@@ -669,10 +559,47 @@ class GovukConnect::CLI
|
|
669
559
|
exec(*ssh_command)
|
670
560
|
end
|
671
561
|
|
562
|
+
def scp(
|
563
|
+
target,
|
564
|
+
environment,
|
565
|
+
files,
|
566
|
+
push: false,
|
567
|
+
additional_arguments: []
|
568
|
+
)
|
569
|
+
log "debug: scp #{push ? 'push' : 'pull'} to #{target} in #{environment}"
|
570
|
+
|
571
|
+
target, hosting = ssh_target(target, environment)
|
572
|
+
|
573
|
+
sources = files[0, files.length - 1]
|
574
|
+
destination = files[-1]
|
575
|
+
|
576
|
+
if push
|
577
|
+
destination = "#{target}:#{destination}"
|
578
|
+
else
|
579
|
+
sources = sources.map { |source| "#{target}:#{source}" }
|
580
|
+
end
|
581
|
+
|
582
|
+
scp_command = [
|
583
|
+
"scp",
|
584
|
+
*ssh_identity_arguments,
|
585
|
+
"-o",
|
586
|
+
"ProxyJump=#{user_at_host(ssh_username, jumpbox_for_environment_and_hosting(environment, hosting))}",
|
587
|
+
"-o",
|
588
|
+
"User=#{ssh_username}",
|
589
|
+
*additional_arguments,
|
590
|
+
"--",
|
591
|
+
*sources,
|
592
|
+
destination,
|
593
|
+
]
|
594
|
+
|
595
|
+
info "\n#{bold('Running command:')} #{scp_command.join(' ')}\n\n"
|
596
|
+
|
597
|
+
exec(*scp_command)
|
598
|
+
end
|
599
|
+
|
672
600
|
def rabbitmq_root_password_command(hosting, environment)
|
673
601
|
hieradata_directory = {
|
674
602
|
aws: "puppet_aws",
|
675
|
-
carrenza: "puppet",
|
676
603
|
}[hosting]
|
677
604
|
|
678
605
|
directory = File.join(
|
@@ -688,14 +615,11 @@ class GovukConnect::CLI
|
|
688
615
|
uri = URI(url)
|
689
616
|
|
690
617
|
host_to_hosting_and_environment = {
|
691
|
-
"ci-alert.integration.publishing.service.gov.uk" => %i[carrenza ci],
|
692
618
|
"alert.integration.publishing.service.gov.uk" => %i[aws integration],
|
693
619
|
"alert.staging.govuk.digital" => %i[aws staging],
|
694
620
|
"alert.blue.staging.govuk.digital" => %i[aws staging],
|
695
|
-
"alert.staging.publishing.service.gov.uk" => %i[carrenza staging],
|
696
621
|
"alert.production.govuk.digital" => %i[aws production],
|
697
622
|
"alert.blue.production.govuk.digital" => %i[aws production],
|
698
|
-
"alert.publishing.service.gov.uk" => %i[carrenza production],
|
699
623
|
}
|
700
624
|
|
701
625
|
unless host_to_hosting_and_environment.key? uri.host
|
@@ -733,9 +657,12 @@ class GovukConnect::CLI
|
|
733
657
|
@verbose = true
|
734
658
|
end
|
735
659
|
|
736
|
-
opts.on("-h", "--help", "Prints usage
|
660
|
+
opts.on("-h", "--help", "Prints usage examples and information") do
|
737
661
|
info opts
|
738
662
|
print_empty_line
|
663
|
+
info bold("EXAMPLES")
|
664
|
+
info EXAMPLES
|
665
|
+
print_empty_line
|
739
666
|
info bold("CONNECTION TYPES")
|
740
667
|
types.keys.each do |x|
|
741
668
|
info " #{x}"
|
@@ -748,9 +675,6 @@ class GovukConnect::CLI
|
|
748
675
|
print_empty_line
|
749
676
|
info bold("APPLICATION TARGET")
|
750
677
|
info APP_TARGET_DESCRIPTION
|
751
|
-
print_empty_line
|
752
|
-
info bold("EXAMPLES")
|
753
|
-
info EXAMPLES
|
754
678
|
exit
|
755
679
|
end
|
756
680
|
opts.on("-V", "--version", "Prints version information") do
|
@@ -777,7 +701,7 @@ class GovukConnect::CLI
|
|
777
701
|
|
778
702
|
hosting = hosting.to_sym
|
779
703
|
|
780
|
-
unless %i[
|
704
|
+
unless %i[aws].include? hosting
|
781
705
|
error "error: unknown hosting provider: #{hosting}"
|
782
706
|
print_empty_line
|
783
707
|
info "available hosting providers are:"
|
@@ -829,6 +753,90 @@ class GovukConnect::CLI
|
|
829
753
|
[node_class, app_name, number]
|
830
754
|
end
|
831
755
|
|
756
|
+
def target_from_options(target, options)
|
757
|
+
if options.key? :hosting
|
758
|
+
hosting, name, number = parse_hosting_name_and_number(target)
|
759
|
+
if hosting
|
760
|
+
error "error: hosting specified twice"
|
761
|
+
exit 1
|
762
|
+
end
|
763
|
+
|
764
|
+
{
|
765
|
+
hosting: options[:hosting],
|
766
|
+
name: name,
|
767
|
+
number: number,
|
768
|
+
}
|
769
|
+
else
|
770
|
+
target
|
771
|
+
end
|
772
|
+
end
|
773
|
+
|
774
|
+
def ssh_target(target, environment)
|
775
|
+
# Split something like aws/backend:2 in to :aws, 'backend', 2
|
776
|
+
hosting, name, number = parse_hosting_name_and_number(target)
|
777
|
+
|
778
|
+
if name.end_with? ".internal"
|
779
|
+
target = name
|
780
|
+
hosting = :aws
|
781
|
+
else
|
782
|
+
# The hosting might not have been provided, so check if necessary
|
783
|
+
hosting ||= hosting_for_target_and_environment(target, environment)
|
784
|
+
|
785
|
+
domains = get_domains_for_node_class(
|
786
|
+
name,
|
787
|
+
environment,
|
788
|
+
hosting,
|
789
|
+
)
|
790
|
+
|
791
|
+
if domains.length.zero?
|
792
|
+
error "error: couldn't find #{name} in #{hosting}/#{environment}"
|
793
|
+
|
794
|
+
node_types = govuk_node_list_classes(environment, hosting)
|
795
|
+
|
796
|
+
similar_node_types = strings_similar_to(name, node_types)
|
797
|
+
|
798
|
+
if similar_node_types.any?
|
799
|
+
info "\ndid you mean:"
|
800
|
+
similar_node_types.each { |s| info " - #{s}" }
|
801
|
+
else
|
802
|
+
info "\nall node types:"
|
803
|
+
node_types.each { |s| info " - #{s}" }
|
804
|
+
end
|
805
|
+
|
806
|
+
exit 1
|
807
|
+
elsif domains.length == 1
|
808
|
+
target = domains.first
|
809
|
+
|
810
|
+
info "There is #{bold('one machine')} to connect to"
|
811
|
+
else
|
812
|
+
n_machines = bold("#{domains.length} machines")
|
813
|
+
info "There are #{n_machines} of this class"
|
814
|
+
|
815
|
+
if number
|
816
|
+
unless number.positive?
|
817
|
+
print_empty_line
|
818
|
+
error "error: invalid machine number '#{number}', it must be > 0"
|
819
|
+
exit 1
|
820
|
+
end
|
821
|
+
|
822
|
+
unless number <= domains.length
|
823
|
+
print_empty_line
|
824
|
+
error "error: cannot connect to machine number: #{number}"
|
825
|
+
exit 1
|
826
|
+
end
|
827
|
+
|
828
|
+
target = domains[number - 1]
|
829
|
+
info "Connecting to number #{number}"
|
830
|
+
else
|
831
|
+
target = domains.sample
|
832
|
+
info "Connecting to a random machine (number #{domains.find_index(target) + 1})"
|
833
|
+
end
|
834
|
+
end
|
835
|
+
end
|
836
|
+
|
837
|
+
[target, hosting]
|
838
|
+
end
|
839
|
+
|
832
840
|
def check_for_target(target)
|
833
841
|
unless target
|
834
842
|
error "error: you must specify the target\n"
|
@@ -848,20 +856,23 @@ class GovukConnect::CLI
|
|
848
856
|
|
849
857
|
def types
|
850
858
|
@types ||= {
|
851
|
-
"app-console" => proc do |target, environment, args, _options|
|
859
|
+
"app-console" => proc do |target, environment, args, extra_args, _options|
|
852
860
|
check_for_target(target)
|
853
861
|
check_for_additional_arguments("app-console", args)
|
862
|
+
check_for_additional_arguments("app-console", extra_args)
|
854
863
|
govuk_app_command(target, environment, "console")
|
855
864
|
end,
|
856
865
|
|
857
|
-
"app-dbconsole" => proc do |target, environment, args, _options|
|
866
|
+
"app-dbconsole" => proc do |target, environment, args, extra_args, _options|
|
858
867
|
check_for_target(target)
|
859
868
|
check_for_additional_arguments("app-dbconsole", args)
|
869
|
+
check_for_additional_arguments("app-dbconsole", extra_args)
|
860
870
|
govuk_app_command(target, environment, "dbconsole")
|
861
871
|
end,
|
862
872
|
|
863
|
-
"rabbitmq" => proc do |target, environment, args, _options|
|
873
|
+
"rabbitmq" => proc do |target, environment, args, extra_args, _options|
|
864
874
|
check_for_additional_arguments("rabbitmq", args)
|
875
|
+
check_for_additional_arguments("rabbitmq", extra_args)
|
865
876
|
|
866
877
|
target ||= "rabbitmq"
|
867
878
|
|
@@ -882,37 +893,50 @@ class GovukConnect::CLI
|
|
882
893
|
)
|
883
894
|
end,
|
884
895
|
|
885
|
-
"
|
886
|
-
|
896
|
+
"ssh" => proc do |target, environment, args, extra_args, options|
|
897
|
+
check_for_target(target)
|
898
|
+
target = target_from_options(target, options)
|
899
|
+
|
887
900
|
ssh(
|
888
|
-
target
|
901
|
+
target,
|
889
902
|
environment,
|
890
|
-
port_forward:
|
903
|
+
port_forward: options[:port_forward],
|
904
|
+
additional_arguments: [args, extra_args].flatten,
|
891
905
|
)
|
892
906
|
end,
|
893
907
|
|
894
|
-
"
|
908
|
+
"scp-pull" => proc do |target, environment, args, extra_args, options|
|
895
909
|
check_for_target(target)
|
910
|
+
target = target_from_options(target, options)
|
896
911
|
|
897
|
-
if
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
912
|
+
if args.length < 2
|
913
|
+
error "error: need at least two filenames"
|
914
|
+
exit 1
|
915
|
+
end
|
916
|
+
|
917
|
+
scp(
|
918
|
+
target,
|
919
|
+
environment,
|
920
|
+
args,
|
921
|
+
additional_arguments: extra_args,
|
922
|
+
)
|
923
|
+
end,
|
924
|
+
|
925
|
+
"scp-push" => proc do |target, environment, args, extra_args, options|
|
926
|
+
check_for_target(target)
|
927
|
+
target = target_from_options(target, options)
|
903
928
|
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
number: number,
|
908
|
-
}
|
929
|
+
if args.length < 2
|
930
|
+
error "error: need at least two filenames"
|
931
|
+
exit 1
|
909
932
|
end
|
910
933
|
|
911
|
-
|
934
|
+
scp(
|
912
935
|
target,
|
913
936
|
environment,
|
914
|
-
|
915
|
-
|
937
|
+
args,
|
938
|
+
push: true,
|
939
|
+
additional_arguments: extra_args,
|
916
940
|
)
|
917
941
|
end,
|
918
942
|
}
|
@@ -921,23 +945,21 @@ class GovukConnect::CLI
|
|
921
945
|
def main(argv)
|
922
946
|
check_ruby_version_greater_than(required_major: 2, required_minor: 0)
|
923
947
|
|
948
|
+
extra_arguments_after_double_dash = []
|
949
|
+
|
924
950
|
double_dash_index = argv.index "--"
|
925
951
|
if double_dash_index
|
926
|
-
# This is used in the case of passing extra options to ssh
|
927
|
-
# acts as a separator, so to avoid optparse
|
928
|
-
# options, split argv around -- before
|
929
|
-
|
952
|
+
# This is used in the case of passing extra options to ssh and
|
953
|
+
# scp, the -- acts as a separator, so to avoid optparse
|
954
|
+
# interpreting those as options, split argv around -- before
|
955
|
+
# parsing the options
|
956
|
+
extra_arguments_after_double_dash = argv[double_dash_index + 1, argv.length]
|
930
957
|
argv = argv[0, double_dash_index]
|
931
|
-
|
932
|
-
options = parse_options(argv)
|
933
|
-
|
934
|
-
type, target = argv
|
935
|
-
else
|
936
|
-
options = parse_options(argv)
|
937
|
-
|
938
|
-
type, target, *rest = argv
|
939
958
|
end
|
940
959
|
|
960
|
+
govuk_connect_options = parse_options(argv)
|
961
|
+
type, target, *extra_arguments_before_double_dash = argv
|
962
|
+
|
941
963
|
unless type
|
942
964
|
error "error: you must specify the connection type\n"
|
943
965
|
|
@@ -970,7 +992,7 @@ class GovukConnect::CLI
|
|
970
992
|
exit 1
|
971
993
|
end
|
972
994
|
|
973
|
-
environment =
|
995
|
+
environment = govuk_connect_options[:environment]&.to_sym
|
974
996
|
|
975
997
|
unless environment
|
976
998
|
error "error: you must specify the environment\n"
|
@@ -986,7 +1008,13 @@ class GovukConnect::CLI
|
|
986
1008
|
exit 1
|
987
1009
|
end
|
988
1010
|
|
989
|
-
handler.call(
|
1011
|
+
handler.call(
|
1012
|
+
target,
|
1013
|
+
environment,
|
1014
|
+
extra_arguments_before_double_dash,
|
1015
|
+
extra_arguments_after_double_dash,
|
1016
|
+
govuk_connect_options,
|
1017
|
+
)
|
990
1018
|
rescue Interrupt
|
991
1019
|
# Handle SIGTERM without printing a stacktrace
|
992
1020
|
exit 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk-connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Government Digital Service
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: climate_control
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.17.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.17.0
|
69
69
|
description: Command line tool to connect to GOV.UK infrastructure
|
70
70
|
email:
|
71
71
|
- govuk-dev@digital.cabinet-office.gov.uk
|
@@ -82,7 +82,7 @@ homepage: https://github.com/alphagov/govuk-connect
|
|
82
82
|
licenses:
|
83
83
|
- MIT
|
84
84
|
metadata: {}
|
85
|
-
post_install_message:
|
85
|
+
post_install_message:
|
86
86
|
rdoc_options: []
|
87
87
|
require_paths:
|
88
88
|
- lib
|
@@ -97,8 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
|
-
rubygems_version: 3.1
|
101
|
-
signing_key:
|
100
|
+
rubygems_version: 3.0.3.1
|
101
|
+
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: govuk-connect command line tool
|
104
104
|
test_files: []
|