govuk-connect 0.1.0 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b8646130db048f402534738fffea6fca312d926909b4bfaf96a99a0d87a6625
4
- data.tar.gz: d4011ee86eddef1e2f0ac7e643bfaaf757baf713612cd808822c84eef715ac5d
3
+ metadata.gz: 0a1b3a80c3eec55973d5a21f131f0a12d836578d702488f9eed8cf20acf1042d
4
+ data.tar.gz: d91a53b4f152ba3609e71b4e4bdbe0918bb8090443b950ddefd3811dc19cbe6d
5
5
  SHA512:
6
- metadata.gz: 0cf8916a2150a946b616cfed84feae2b9333116cec946bb77179ea3074e64758552dde756872857178596a3163a5dce898daf11ca2c363223d714aef845abf94
7
- data.tar.gz: 809217f4589312c5fad4fa008f9eba535c622f87d0fe2222d944528b25c7772bb3d5d029be8d4c3f97a6e637c0e9c444afefe59cdc35532c5b3c9d4f6513f264
6
+ metadata.gz: ff8f442e71c562b001119fb5c5eb92958d3e1b2a1da7dd31f9ca2d6483e693a62ca383797ced30d2130662ef1ce94a8aa3c5d6e890124066bbc914edfdcef52e
7
+ data.tar.gz: fa0ecc08631861e15aa2cfd6dacb3299e1783df665b2e3e4b0b9eec9c45019819fbb40c7e9a491fc66bf03a72b44da1bb88428efebadbe5955f58676e2cbd69c
@@ -15,37 +15,41 @@ class GovukConnect::CLI
15
15
  self.class.bold(string)
16
16
  end
17
17
 
18
- USAGE_BANNER = "Usage: govuk-connect TYPE TARGET [options]".freeze
18
+ USAGE_BANNER = "Usage: gds govuk connect TYPE TARGET [options]".freeze
19
19
 
20
20
  EXAMPLES = <<-EXAMPLES.freeze
21
- govuk-connect ssh --environment integration backend
21
+ gds govuk connect ssh --environment integration backend
22
22
 
23
- govuk-connect app-console --environment staging publishing-api
23
+ gds govuk connect scp-push --environment integration backend filename.txt /tmp/
24
24
 
25
- govuk-connect app-dbconsole -e integration whitehall_backend/whitehall
25
+ gds govuk connect scp-pull --environment integration backend /tmp/filename.txt ~/Downloads/
26
26
 
27
- govuk-connect rabbitmq -e staging aws/rabbitmq
27
+ gds govuk connect app-console --environment staging publishing-api
28
28
 
29
- govuk-connect sidekiq-monitoring -e integration
29
+ gds govuk connect app-dbconsole -e integration whitehall_backend/whitehall
30
+
31
+ gds govuk connect rabbitmq -e staging aws/rabbitmq
32
+
33
+ gds govuk connect sidekiq-monitoring -e integration
30
34
  EXAMPLES
31
35
 
32
36
  MACHINE_TARGET_DESCRIPTION = <<-DOCS.freeze
33
- The ssh, rabbitmq and sidekiq-monitoring connection types target
37
+ The ssh, scp-*, rabbitmq and sidekiq-monitoring connection types target
34
38
  machines.
35
39
 
36
40
  The machine can be specified by name, for example:
37
41
 
38
- govuk-connect ssh -e integration #{bold('backend')}
42
+ gds govuk connect ssh -e integration #{bold('backend')}
39
43
 
40
44
  If the hosting provider is ambiguous, you'll need to specify it prior
41
45
  to the name, for example:
42
46
 
43
- govuk-connect ssh -e staging #{bold('aws/')}backend
47
+ gds govuk connect ssh -e staging #{bold('aws/')}backend
44
48
 
45
49
  If you want to connect to a specific machine, you can specify a number
46
50
  after the name, for example:
47
51
 
48
- govuk-connect ssh -e integration backend#{bold(':2')}
52
+ gds govuk connect ssh -e integration backend#{bold(':2')}
49
53
  DOCS
50
54
 
51
55
  APP_TARGET_DESCRIPTION = <<-DOCS.freeze
@@ -54,17 +58,17 @@ class GovukConnect::CLI
54
58
 
55
59
  The application is specified by name, for example:
56
60
 
57
- govuk-connect app-console -e integration #{bold('publishing-api')}
61
+ gds govuk connect app-console -e integration #{bold('publishing-api')}
58
62
 
59
63
  If the node class is ambiguous, you'll need to specify it prior to
60
64
  the name, for example:
61
65
 
62
- govuk-connect app-console -e integration #{bold('whitehall_backend/')}whitehall
66
+ gds govuk connect app-console -e integration #{bold('whitehall_backend/')}whitehall
63
67
 
64
68
  If you want to connect to a specific machine, you can specify a
65
69
  number after the name, for example:
66
70
 
67
- govuk-connect app-console -e integration publishing-api#{bold(':2')}
71
+ gds govuk connect app-console -e integration publishing-api#{bold(':2')}
68
72
  DOCS
69
73
 
70
74
  CONNECTION_TYPE_DESCRIPTIONS = {
@@ -75,10 +79,13 @@ class GovukConnect::CLI
75
79
  "sidekiq-monitoring" => "Setup port forwarding to the Sidekiq Monitoring application.",
76
80
  }.freeze
77
81
 
78
- RABBITMQ_PORT = 15672
82
+ RABBITMQ_PORT = 15_672
79
83
  SIDEKIQ_MONITORING_PORT = 3211
80
84
 
81
85
  JUMPBOXES = {
86
+ test: {
87
+ aws: "jumpbox.pink.test.govuk.digital",
88
+ },
82
89
  ci: {
83
90
  carrenza: "ci-jumpbox.integration.publishing.service.gov.uk",
84
91
  },
@@ -96,7 +103,7 @@ class GovukConnect::CLI
96
103
  }.freeze
97
104
 
98
105
  def log(message)
99
- warn message if $verbose
106
+ warn message if @verbose
100
107
  end
101
108
 
102
109
  def print_empty_line
@@ -125,10 +132,12 @@ class GovukConnect::CLI
125
132
  costs[0] = i
126
133
  nw = i - 1 # j == 0; nw is lev(i-1, j)
127
134
  (1..string2.length).each do |j|
128
- costs[j], nw = [
129
- costs[j] + 1, costs[j - 1] + 1,
130
- string1[i - 1] == string2[j - 1] ? nw : nw + 1
131
- ].min, costs[j]
135
+ costs[j] = [
136
+ costs[j] + 1,
137
+ costs[j - 1] + 1,
138
+ string1[i - 1] == string2[j - 1] ? nw : nw + 1,
139
+ ].min
140
+ nw = costs[j]
132
141
  end
133
142
  end
134
143
  costs[string2.length]
@@ -176,7 +185,7 @@ class GovukConnect::CLI
176
185
  tries = 0
177
186
 
178
187
  while tries <= 10
179
- port = rand(32768...61000)
188
+ port = rand(32_768...61_000)
180
189
 
181
190
  return port if port_free? port
182
191
 
@@ -228,7 +237,7 @@ class GovukConnect::CLI
228
237
  def ssh_username
229
238
  @ssh_username ||= begin
230
239
  if File.exist? config_file
231
- config_ssh_username = YAML::load_file(config_file)["ssh_username"]
240
+ config_ssh_username = YAML.load_file(config_file)["ssh_username"]
232
241
  end
233
242
 
234
243
  config_ssh_username || ENV["USER"]
@@ -237,7 +246,7 @@ class GovukConnect::CLI
237
246
 
238
247
  def ssh_identity_file
239
248
  @ssh_identity_file ||= begin
240
- YAML::load_file(config_file)["ssh_identity_file"] if File.exist? config_file
249
+ YAML.load_file(config_file)["ssh_identity_file"] if File.exist? config_file
241
250
  end
242
251
  end
243
252
 
@@ -257,13 +266,14 @@ class GovukConnect::CLI
257
266
  log "debug: looking up classes in #{hosting}/#{environment}"
258
267
  command = [
259
268
  "ssh",
260
- "-o", "ConnectTimeout=2", # Show a failure quickly
269
+ "-o",
270
+ "ConnectTimeout=2", # Show a failure quickly
261
271
  *ssh_identity_arguments,
262
272
  user_at_host(
263
273
  ssh_username,
264
274
  jumpbox_for_environment_and_hosting(environment, hosting),
265
275
  ),
266
- "govuk_node_list --classes"
276
+ "govuk_node_list --classes",
267
277
  ].join(" ")
268
278
 
269
279
  log "debug: running command: #{command}"
@@ -287,13 +297,14 @@ class GovukConnect::CLI
287
297
  def get_domains_for_node_class(target, environment, hosting, ssh_username)
288
298
  command = [
289
299
  "ssh",
290
- "-o", "ConnectTimeout=2", # Show a failure quickly
300
+ "-o",
301
+ "ConnectTimeout=2", # Show a failure quickly
291
302
  *ssh_identity_arguments,
292
303
  user_at_host(
293
304
  ssh_username,
294
305
  jumpbox_for_environment_and_hosting(environment, hosting),
295
306
  ),
296
- "govuk_node_list -c #{target}"
307
+ "govuk_node_list -c #{target}",
297
308
  ].join(" ")
298
309
 
299
310
  output, status = Open3.capture2(command)
@@ -305,7 +316,11 @@ class GovukConnect::CLI
305
316
  exit 1
306
317
  end
307
318
 
308
- output.split("\n").sort
319
+ if hosting == :aws
320
+ output.split("\n")
321
+ else
322
+ output.split("\n").sort
323
+ end
309
324
  end
310
325
 
311
326
  def govuk_directory
@@ -327,12 +342,12 @@ class GovukConnect::CLI
327
342
  hieradata_file = File.join(local_hieradata_root, "#{environment}.yaml")
328
343
  log "debug: reading #{hieradata_file}"
329
344
 
330
- environment_specific_hieradata = YAML::load_file(hieradata_file)
345
+ environment_specific_hieradata = YAML.load_file(hieradata_file)
331
346
 
332
347
  if environment_specific_hieradata["node_class"]
333
348
  environment_specific_hieradata["node_class"]
334
349
  else
335
- common_hieradata = YAML::load_file(
350
+ common_hieradata = YAML.load_file(
336
351
  File.join(local_hieradata_root, "common.yaml"),
337
352
  )
338
353
 
@@ -390,7 +405,7 @@ class GovukConnect::CLI
390
405
  print_empty_line
391
406
  info "specify the node class and application mame, for example: "
392
407
  node_classes.each do |node_class|
393
- info "\n govuk-connect app-console -e #{environment} #{node_class}/#{app_name}"
408
+ info "\n gds govuk connect app-console -e #{environment} #{node_class}/#{app_name}"
394
409
  end
395
410
  print_empty_line
396
411
 
@@ -434,7 +449,7 @@ class GovukConnect::CLI
434
449
  print_empty_line
435
450
  info "specify the hosting provider and node type, for example: "
436
451
  hosting_providers.each do |hosting_provider|
437
- info "\n govuk-connect ssh #{bold(hosting_provider)}/#{node_type}"
452
+ info "\n gds govuk connect ssh #{bold(hosting_provider)}/#{node_type}"
438
453
  end
439
454
  info "\n"
440
455
 
@@ -511,7 +526,7 @@ class GovukConnect::CLI
511
526
  app_name,
512
527
  environment,
513
528
  hosting,
514
- )
529
+ )
515
530
 
516
531
  unless node_class
517
532
  error "error: application '#{app_name}' not found."
@@ -551,90 +566,27 @@ class GovukConnect::CLI
551
566
 
552
567
  def ssh(
553
568
  target,
554
- environment,
555
- command: false,
556
- port_forward: false,
557
- additional_arguments: []
558
- )
569
+ environment,
570
+ command: false,
571
+ port_forward: false,
572
+ additional_arguments: []
573
+ )
559
574
  log "debug: ssh to #{target} in #{environment}"
560
575
 
561
- # Split something like aws/backend:2 in to :aws, 'backend', 2
562
- hosting, name, number = parse_hosting_name_and_number(target)
563
-
564
- if name.end_with? ".internal"
565
- ssh_target = name
566
- hosting = :aws
567
- elsif name.end_with? ".gov.uk"
568
- ssh_target = name
569
- hosting = :carrenza
570
- else
571
- # The hosting might not have been provided, so check if necessary
572
- hosting ||= hosting_for_target_and_environment(target, environment)
573
-
574
- domains = get_domains_for_node_class(
575
- name,
576
- environment,
577
- hosting,
578
- ssh_username,
579
- )
580
-
581
- if domains.length.zero?
582
- error "error: couldn't find #{name} in #{hosting}/#{environment}"
583
-
584
- node_types = govuk_node_list_classes(environment, hosting)
585
-
586
- similar_node_types = strings_similar_to(name, node_types)
587
-
588
- if similar_node_types.any?
589
- info "\ndid you mean:"
590
- similar_node_types.each { |s| info " - #{s}" }
591
- else
592
- info "\nall node types:"
593
- node_types.each { |s| info " - #{s}" }
594
- end
595
-
596
- exit 1
597
- elsif domains.length == 1
598
- ssh_target = domains.first
599
-
600
- info "There is #{bold('one machine')} to connect to"
601
- else
602
- n_machines = bold("#{domains.length} machines")
603
- info "There are #{n_machines} of this class"
604
-
605
- if number
606
- unless number.positive?
607
- print_empty_line
608
- error "error: invalid machine number '#{number}', it must be > 0"
609
- exit 1
610
- end
611
-
612
- unless number <= domains.length
613
- print_empty_line
614
- error "error: cannot connect to machine number: #{number}"
615
- exit 1
616
- end
617
-
618
- ssh_target = domains[number - 1]
619
- info "Connecting to number #{number}"
620
- else
621
- ssh_target = domains.sample
622
- info "Connecting to a random machine (number #{domains.find_index(ssh_target) + 1})"
623
- end
624
- end
625
- end
576
+ target, hosting = ssh_target(target, environment)
626
577
 
627
578
  ssh_command = [
628
579
  "ssh",
629
580
  *ssh_identity_arguments,
630
- "-J", user_at_host(
581
+ "-J",
582
+ user_at_host(
631
583
  ssh_username,
632
584
  jumpbox_for_environment_and_hosting(environment, hosting),
633
585
  ),
634
586
  user_at_host(
635
587
  ssh_username,
636
- ssh_target,
637
- )
588
+ target,
589
+ ),
638
590
  ]
639
591
 
640
592
  if command
@@ -647,7 +599,8 @@ class GovukConnect::CLI
647
599
 
648
600
  ssh_command += [
649
601
  "-N",
650
- "-L", "#{localhost_port}:127.0.0.1:#{port_forward}"
602
+ "-L",
603
+ "#{localhost_port}:127.0.0.1:#{port_forward}",
651
604
  ]
652
605
 
653
606
  info "Port forwarding setup, access:\n\n http://127.0.0.1:#{localhost_port}/\n\n"
@@ -660,6 +613,44 @@ class GovukConnect::CLI
660
613
  exec(*ssh_command)
661
614
  end
662
615
 
616
+ def scp(
617
+ target,
618
+ environment,
619
+ files,
620
+ push: false,
621
+ additional_arguments: []
622
+ )
623
+ log "debug: scp #{push ? 'push' : 'pull'} to #{target} in #{environment}"
624
+
625
+ target, hosting = ssh_target(target, environment)
626
+
627
+ sources = files[0, files.length - 1]
628
+ destination = files[-1]
629
+
630
+ if push
631
+ destination = "#{target}:#{destination}"
632
+ else
633
+ sources = sources.map { |source| "#{target}:#{source}" }
634
+ end
635
+
636
+ scp_command = [
637
+ "scp",
638
+ *ssh_identity_arguments,
639
+ "-o",
640
+ "ProxyJump=#{user_at_host(ssh_username, jumpbox_for_environment_and_hosting(environment, hosting))}",
641
+ "-o",
642
+ "User=#{ssh_username}",
643
+ *additional_arguments,
644
+ "--",
645
+ *sources,
646
+ destination,
647
+ ]
648
+
649
+ info "\n#{bold('Running command:')} #{scp_command.join(' ')}\n\n"
650
+
651
+ exec(*scp_command)
652
+ end
653
+
663
654
  def rabbitmq_root_password_command(hosting, environment)
664
655
  hieradata_directory = {
665
656
  aws: "puppet_aws",
@@ -679,14 +670,14 @@ class GovukConnect::CLI
679
670
  uri = URI(url)
680
671
 
681
672
  host_to_hosting_and_environment = {
682
- "ci-alert.integration.publishing.service.gov.uk" => %i[carrenza ci],
683
- "alert.integration.publishing.service.gov.uk" => %i[aws integration],
684
- "alert.staging.govuk.digital" => %i[aws staging],
685
- "alert.blue.staging.govuk.digital" => %i[aws staging],
686
- "alert.staging.publishing.service.gov.uk" => %i[carrenza staging],
687
- "alert.production.govuk.digital" => %i[aws production],
688
- "alert.blue.production.govuk.digital" => %i[aws production],
689
- "alert.publishing.service.gov.uk" => %i[carrenza production],
673
+ "ci-alert.integration.publishing.service.gov.uk" => %i[carrenza ci],
674
+ "alert.integration.publishing.service.gov.uk" => %i[aws integration],
675
+ "alert.staging.govuk.digital" => %i[aws staging],
676
+ "alert.blue.staging.govuk.digital" => %i[aws staging],
677
+ "alert.staging.publishing.service.gov.uk" => %i[carrenza staging],
678
+ "alert.production.govuk.digital" => %i[aws production],
679
+ "alert.blue.production.govuk.digital" => %i[aws production],
680
+ "alert.publishing.service.gov.uk" => %i[carrenza production],
690
681
  }
691
682
 
692
683
  unless host_to_hosting_and_environment.key? uri.host
@@ -699,8 +690,6 @@ class GovukConnect::CLI
699
690
 
700
691
  def parse_options(argv)
701
692
  options = {}
702
-
703
- # rubocop:disable Metrics/BlockLength
704
693
  @option_parser = OptionParser.new do |opts|
705
694
  opts.banner = USAGE_BANNER
706
695
 
@@ -723,12 +712,15 @@ class GovukConnect::CLI
723
712
  options[:port_forward] = o
724
713
  end
725
714
  opts.on("-v", "--verbose", "Enable more detailed logging") do
726
- $verbose = true
715
+ @verbose = true
727
716
  end
728
717
 
729
- opts.on("-h", "--help", "Prints usage information and examples") do
718
+ opts.on("-h", "--help", "Prints usage examples and information") do
730
719
  info opts
731
720
  print_empty_line
721
+ info bold("EXAMPLES")
722
+ info EXAMPLES
723
+ print_empty_line
732
724
  info bold("CONNECTION TYPES")
733
725
  types.keys.each do |x|
734
726
  info " #{x}"
@@ -741,9 +733,6 @@ class GovukConnect::CLI
741
733
  print_empty_line
742
734
  info bold("APPLICATION TARGET")
743
735
  info APP_TARGET_DESCRIPTION
744
- print_empty_line
745
- info bold("EXAMPLES")
746
- info EXAMPLES
747
736
  exit
748
737
  end
749
738
  opts.on("-V", "--version", "Prints version information") do
@@ -751,7 +740,6 @@ class GovukConnect::CLI
751
740
  exit
752
741
  end
753
742
  end
754
- # rubocop:enable Metrics/BlockLength
755
743
 
756
744
  @option_parser.parse!(argv)
757
745
 
@@ -823,6 +811,94 @@ class GovukConnect::CLI
823
811
  [node_class, app_name, number]
824
812
  end
825
813
 
814
+ def target_from_options(target, options)
815
+ if options.key? :hosting
816
+ hosting, name, number = parse_hosting_name_and_number(target)
817
+ if hosting
818
+ error "error: hosting specified twice"
819
+ exit 1
820
+ end
821
+
822
+ {
823
+ hosting: options[:hosting],
824
+ name: name,
825
+ number: number,
826
+ }
827
+ else
828
+ target
829
+ end
830
+ end
831
+
832
+ def ssh_target(target, environment)
833
+ # Split something like aws/backend:2 in to :aws, 'backend', 2
834
+ hosting, name, number = parse_hosting_name_and_number(target)
835
+
836
+ if name.end_with? ".internal"
837
+ target = name
838
+ hosting = :aws
839
+ elsif name.end_with? ".gov.uk"
840
+ target = name
841
+ hosting = :carrenza
842
+ else
843
+ # The hosting might not have been provided, so check if necessary
844
+ hosting ||= hosting_for_target_and_environment(target, environment)
845
+
846
+ domains = get_domains_for_node_class(
847
+ name,
848
+ environment,
849
+ hosting,
850
+ ssh_username,
851
+ )
852
+
853
+ if domains.length.zero?
854
+ error "error: couldn't find #{name} in #{hosting}/#{environment}"
855
+
856
+ node_types = govuk_node_list_classes(environment, hosting)
857
+
858
+ similar_node_types = strings_similar_to(name, node_types)
859
+
860
+ if similar_node_types.any?
861
+ info "\ndid you mean:"
862
+ similar_node_types.each { |s| info " - #{s}" }
863
+ else
864
+ info "\nall node types:"
865
+ node_types.each { |s| info " - #{s}" }
866
+ end
867
+
868
+ exit 1
869
+ elsif domains.length == 1
870
+ target = domains.first
871
+
872
+ info "There is #{bold('one machine')} to connect to"
873
+ else
874
+ n_machines = bold("#{domains.length} machines")
875
+ info "There are #{n_machines} of this class"
876
+
877
+ if number
878
+ unless number.positive?
879
+ print_empty_line
880
+ error "error: invalid machine number '#{number}', it must be > 0"
881
+ exit 1
882
+ end
883
+
884
+ unless number <= domains.length
885
+ print_empty_line
886
+ error "error: cannot connect to machine number: #{number}"
887
+ exit 1
888
+ end
889
+
890
+ target = domains[number - 1]
891
+ info "Connecting to number #{number}"
892
+ else
893
+ target = domains.sample
894
+ info "Connecting to a random machine (number #{domains.find_index(target) + 1})"
895
+ end
896
+ end
897
+ end
898
+
899
+ [target, hosting]
900
+ end
901
+
826
902
  def check_for_target(target)
827
903
  unless target
828
904
  error "error: you must specify the target\n"
@@ -842,20 +918,23 @@ class GovukConnect::CLI
842
918
 
843
919
  def types
844
920
  @types ||= {
845
- "app-console" => Proc.new do |target, environment, args, _options|
921
+ "app-console" => proc do |target, environment, args, extra_args, _options|
846
922
  check_for_target(target)
847
923
  check_for_additional_arguments("app-console", args)
924
+ check_for_additional_arguments("app-console", extra_args)
848
925
  govuk_app_command(target, environment, "console")
849
926
  end,
850
927
 
851
- "app-dbconsole" => Proc.new do |target, environment, args, _options|
928
+ "app-dbconsole" => proc do |target, environment, args, extra_args, _options|
852
929
  check_for_target(target)
853
930
  check_for_additional_arguments("app-dbconsole", args)
931
+ check_for_additional_arguments("app-dbconsole", extra_args)
854
932
  govuk_app_command(target, environment, "dbconsole")
855
933
  end,
856
934
 
857
- "rabbitmq" => Proc.new do |target, environment, args, _options|
935
+ "rabbitmq" => proc do |target, environment, args, extra_args, _options|
858
936
  check_for_additional_arguments("rabbitmq", args)
937
+ check_for_additional_arguments("rabbitmq", extra_args)
859
938
 
860
939
  target ||= "rabbitmq"
861
940
 
@@ -876,8 +955,9 @@ class GovukConnect::CLI
876
955
  )
877
956
  end,
878
957
 
879
- "sidekiq-monitoring" => Proc.new do |target, environment, args, _options|
958
+ "sidekiq-monitoring" => proc do |target, environment, args, extra_args, _options|
880
959
  check_for_additional_arguments("sidekiq-monitoring", args)
960
+ check_for_additional_arguments("sidekiq-monitoring", extra_args)
881
961
  ssh(
882
962
  target || "backend",
883
963
  environment,
@@ -885,28 +965,50 @@ class GovukConnect::CLI
885
965
  )
886
966
  end,
887
967
 
888
- "ssh" => Proc.new do |target, environment, args, options|
968
+ "ssh" => proc do |target, environment, args, extra_args, options|
889
969
  check_for_target(target)
970
+ target = target_from_options(target, options)
890
971
 
891
- if options.key? :hosting
892
- hosting, name, number = parse_hosting_name_and_number(target)
893
- if hosting
894
- error "error: hosting specified twice"
895
- exit 1
896
- end
972
+ ssh(
973
+ target,
974
+ environment,
975
+ port_forward: options[:port_forward],
976
+ additional_arguments: [args, extra_args].flatten,
977
+ )
978
+ end,
979
+
980
+ "scp-pull" => proc do |target, environment, args, extra_args, options|
981
+ check_for_target(target)
982
+ target = target_from_options(target, options)
897
983
 
898
- target = {
899
- hosting: options[:hosting],
900
- name: name,
901
- number: number,
902
- }
984
+ if args.length < 2
985
+ error "error: need at least two filenames"
986
+ exit 1
903
987
  end
904
988
 
905
- ssh(
989
+ scp(
906
990
  target,
907
991
  environment,
908
- port_forward: options[:port_forward],
909
- additional_arguments: args,
992
+ args,
993
+ additional_arguments: extra_args,
994
+ )
995
+ end,
996
+
997
+ "scp-push" => proc do |target, environment, args, extra_args, options|
998
+ check_for_target(target)
999
+ target = target_from_options(target, options)
1000
+
1001
+ if args.length < 2
1002
+ error "error: need at least two filenames"
1003
+ exit 1
1004
+ end
1005
+
1006
+ scp(
1007
+ target,
1008
+ environment,
1009
+ args,
1010
+ push: true,
1011
+ additional_arguments: extra_args,
910
1012
  )
911
1013
  end,
912
1014
  }
@@ -915,26 +1017,21 @@ class GovukConnect::CLI
915
1017
  def main(argv)
916
1018
  check_ruby_version_greater_than(required_major: 2, required_minor: 0)
917
1019
 
1020
+ extra_arguments_after_double_dash = []
1021
+
918
1022
  double_dash_index = argv.index "--"
919
1023
  if double_dash_index
920
- # This is used in the case of passing extra options to ssh, the --
921
- # acts as a separator, so to avoid optparse interpreting those
922
- # options, split argv around -- before parsing the options
923
- rest = argv[double_dash_index + 1, argv.length]
1024
+ # This is used in the case of passing extra options to ssh and
1025
+ # scp, the -- acts as a separator, so to avoid optparse
1026
+ # interpreting those as options, split argv around -- before
1027
+ # parsing the options
1028
+ extra_arguments_after_double_dash = argv[double_dash_index + 1, argv.length]
924
1029
  argv = argv[0, double_dash_index]
925
-
926
- argv.clear
927
- argv.concat argv
928
-
929
- options = parse_options(argv)
930
-
931
- type, target = argv
932
- else
933
- options = parse_options(argv)
934
-
935
- type, target, *rest = argv
936
1030
  end
937
1031
 
1032
+ govuk_connect_options = parse_options(argv)
1033
+ type, target, *extra_arguments_before_double_dash = argv
1034
+
938
1035
  unless type
939
1036
  error "error: you must specify the connection type\n"
940
1037
 
@@ -967,7 +1064,7 @@ class GovukConnect::CLI
967
1064
  exit 1
968
1065
  end
969
1066
 
970
- environment = options[:environment]&.to_sym
1067
+ environment = govuk_connect_options[:environment]&.to_sym
971
1068
 
972
1069
  unless environment
973
1070
  error "error: you must specify the environment\n"
@@ -983,7 +1080,13 @@ class GovukConnect::CLI
983
1080
  exit 1
984
1081
  end
985
1082
 
986
- handler.call(target, environment, rest, options)
1083
+ handler.call(
1084
+ target,
1085
+ environment,
1086
+ extra_arguments_before_double_dash,
1087
+ extra_arguments_after_double_dash,
1088
+ govuk_connect_options,
1089
+ )
987
1090
  rescue Interrupt
988
1091
  # Handle SIGTERM without printing a stacktrace
989
1092
  exit 1
@@ -1,3 +1,3 @@
1
1
  module GovukConnect
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.3.3".freeze
3
3
  end
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.1.0
4
+ version: 0.3.3
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: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2020-09-10 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.5.0
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.5.0
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.0.3
101
- signing_key:
100
+ rubygems_version: 3.1.2
101
+ signing_key:
102
102
  specification_version: 4
103
103
  summary: govuk-connect command line tool
104
104
  test_files: []