govuk-connect 0.3.0 → 0.5.1

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: 716cf50c2125d2a12c992fec40538575fd7a6c40390e4e09739a2de1bd47e984
4
- data.tar.gz: 687de70081e82f05e8d5e0bc0f7f6152942dfb6b53bdf740b21952bdd533e1b1
3
+ metadata.gz: 3b14cf8cbdd487cc57a5f1aad1cbb1a5164a6e7a5f5bc4ab986f0560dd092ab7
4
+ data.tar.gz: '01769936fa3621d0dcc7e61ff9f1dc9c7a7f0852b2f587029c8ca73bcba78a15'
5
5
  SHA512:
6
- metadata.gz: 729380dae3704692181f5cac981d9fd9b40501f5ffc5a32432f8081d34c82cc1f65fc93071491a10a9b0830551ce23d6e0efb62048c51e9a2ac487f32a81a549
7
- data.tar.gz: efc411138a7ed5bfca695f6d5a5232643c2f3afea1d5c4b37ae7618c0276b4cfd7f7f1599d4708ae4ebb689c8d04453a7ffd153d0894028703b1715f1847207f
6
+ metadata.gz: 1f2705de184fc9b9f39dcc1705ff7c5508a456e9db23f217a2918f50a07032fce9bb3269cbdbd8ca7f15e56b8957aed2d6023015615db2d32fd2d7acfb69f378
7
+ data.tar.gz: 2264b408122a922c12a90c9ca9843215e8e6fa52a5041dd1995fcee1b32183190f13dc12c41aee1e07988147abac97d5d197e7e491f0cfadeb8f8e503feb6e44
@@ -15,41 +15,38 @@ 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 scp-push --environment integration backend filename.txt /tmp/
23
+ gds govuk connect scp-push --environment integration backend filename.txt /tmp/
24
24
 
25
- govuk-connect scp-pull --environment integration backend /tmp/filename.txt ~/Downloads/
25
+ gds govuk connect scp-pull --environment integration backend /tmp/filename.txt ~/Downloads/
26
26
 
27
- govuk-connect app-console --environment staging publishing-api
27
+ gds govuk connect app-console --environment staging publishing-api
28
28
 
29
- govuk-connect app-dbconsole -e integration whitehall_backend/whitehall
29
+ gds govuk connect app-dbconsole -e integration whitehall_backend/whitehall
30
30
 
31
- govuk-connect rabbitmq -e staging aws/rabbitmq
32
-
33
- govuk-connect sidekiq-monitoring -e integration
31
+ gds govuk connect rabbitmq -e staging aws/rabbitmq
34
32
  EXAMPLES
35
33
 
36
34
  MACHINE_TARGET_DESCRIPTION = <<-DOCS.freeze
37
- The ssh, scp-*, rabbitmq and sidekiq-monitoring connection types target
38
- machines.
35
+ The ssh, scp-*, rabbitmq connection types target machines.
39
36
 
40
37
  The machine can be specified by name, for example:
41
38
 
42
- govuk-connect ssh -e integration #{bold('backend')}
39
+ gds govuk connect ssh -e integration #{bold('backend')}
43
40
 
44
41
  If the hosting provider is ambiguous, you'll need to specify it prior
45
42
  to the name, for example:
46
43
 
47
- govuk-connect ssh -e staging #{bold('aws/')}backend
44
+ gds govuk connect ssh -e staging #{bold('aws/')}backend
48
45
 
49
46
  If you want to connect to a specific machine, you can specify a number
50
47
  after the name, for example:
51
48
 
52
- govuk-connect ssh -e integration backend#{bold(':2')}
49
+ gds govuk connect ssh -e integration backend#{bold(':2')}
53
50
  DOCS
54
51
 
55
52
  APP_TARGET_DESCRIPTION = <<-DOCS.freeze
@@ -58,17 +55,17 @@ class GovukConnect::CLI
58
55
 
59
56
  The application is specified by name, for example:
60
57
 
61
- govuk-connect app-console -e integration #{bold('publishing-api')}
58
+ gds govuk connect app-console -e integration #{bold('publishing-api')}
62
59
 
63
60
  If the node class is ambiguous, you'll need to specify it prior to
64
61
  the name, for example:
65
62
 
66
- govuk-connect app-console -e integration #{bold('whitehall_backend/')}whitehall
63
+ gds govuk connect app-console -e integration #{bold('whitehall_backend/')}whitehall
67
64
 
68
65
  If you want to connect to a specific machine, you can specify a
69
66
  number after the name, for example:
70
67
 
71
- govuk-connect app-console -e integration publishing-api#{bold(':2')}
68
+ gds govuk connect app-console -e integration publishing-api#{bold(':2')}
72
69
  DOCS
73
70
 
74
71
  CONNECTION_TYPE_DESCRIPTIONS = {
@@ -76,28 +73,21 @@ class GovukConnect::CLI
76
73
  "app-console" => "Launch a console for an application. For example, a rails console when connecting to a Rails application.",
77
74
  "app-dbconsole" => "Launch a console for the database for an application.",
78
75
  "rabbitmq" => "Setup port forwarding to the RabbitMQ admin interface.",
79
- "sidekiq-monitoring" => "Setup port forwarding to the Sidekiq Monitoring application.",
80
76
  }.freeze
81
77
 
82
78
  RABBITMQ_PORT = 15_672
83
- SIDEKIQ_MONITORING_PORT = 3211
84
79
 
85
80
  JUMPBOXES = {
86
81
  test: {
87
82
  aws: "jumpbox.pink.test.govuk.digital",
88
83
  },
89
- ci: {
90
- carrenza: "ci-jumpbox.integration.publishing.service.gov.uk",
91
- },
92
84
  integration: {
93
85
  aws: "jumpbox.integration.publishing.service.gov.uk",
94
86
  },
95
87
  staging: {
96
- carrenza: "jumpbox.staging.publishing.service.gov.uk",
97
88
  aws: "jumpbox.staging.govuk.digital",
98
89
  },
99
90
  production: {
100
- carrenza: "jumpbox.publishing.service.gov.uk",
101
91
  aws: "jumpbox.production.govuk.digital",
102
92
  },
103
93
  }.freeze
@@ -264,29 +254,7 @@ class GovukConnect::CLI
264
254
 
265
255
  def govuk_node_list_classes(environment, hosting)
266
256
  log "debug: looking up classes in #{hosting}/#{environment}"
267
- command = [
268
- "ssh",
269
- "-o",
270
- "ConnectTimeout=2", # Show a failure quickly
271
- *ssh_identity_arguments,
272
- user_at_host(
273
- ssh_username,
274
- jumpbox_for_environment_and_hosting(environment, hosting),
275
- ),
276
- "govuk_node_list --classes",
277
- ].join(" ")
278
-
279
- log "debug: running command: #{command}"
280
- output, status = Open3.capture2(command)
281
-
282
- unless status.success?
283
- error "\nerror: command failed: #{command}"
284
- print_empty_line
285
- print_ssh_username_configuration_help
286
- exit 1
287
- end
288
-
289
- classes = output.split("\n").sort
257
+ classes = ssh_capture("govuk_node_list --classes").sort
290
258
 
291
259
  log "debug: classes:"
292
260
  classes.each { |c| log " - #{c}" }
@@ -294,7 +262,16 @@ class GovukConnect::CLI
294
262
  classes
295
263
  end
296
264
 
297
- def get_domains_for_node_class(target, environment, hosting, ssh_username)
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)
298
275
  command = [
299
276
  "ssh",
300
277
  "-o",
@@ -304,19 +281,20 @@ class GovukConnect::CLI
304
281
  ssh_username,
305
282
  jumpbox_for_environment_and_hosting(environment, hosting),
306
283
  ),
307
- "govuk_node_list -c #{target}",
284
+ remote_command,
308
285
  ].join(" ")
309
286
 
287
+ log "debug: running command: #{command}"
310
288
  output, status = Open3.capture2(command)
311
289
 
312
290
  unless status.success?
313
- error "error: command failed: #{command}"
291
+ error "\nerror: command failed: #{command}"
314
292
  print_empty_line
315
293
  print_ssh_username_configuration_help
316
294
  exit 1
317
295
  end
318
296
 
319
- output.split("\n").sort
297
+ output.split("\n")
320
298
  end
321
299
 
322
300
  def govuk_directory
@@ -330,7 +308,6 @@ class GovukConnect::CLI
330
308
  govuk_directory,
331
309
  "govuk-puppet",
332
310
  {
333
- carrenza: "hieradata",
334
311
  aws: "hieradata_aws",
335
312
  }[hosting],
336
313
  )
@@ -401,7 +378,7 @@ class GovukConnect::CLI
401
378
  print_empty_line
402
379
  info "specify the node class and application mame, for example: "
403
380
  node_classes.each do |node_class|
404
- info "\n govuk-connect app-console -e #{environment} #{node_class}/#{app_name}"
381
+ info "\n gds govuk connect app-console -e #{environment} #{node_class}/#{app_name}"
405
382
  end
406
383
  print_empty_line
407
384
 
@@ -436,29 +413,13 @@ class GovukConnect::CLI
436
413
  return hosting if hosting
437
414
 
438
415
  aws_node_types = govuk_node_list_classes(environment, :aws)
439
- carrenza_node_types = govuk_node_list_classes(environment, :carrenza)
440
416
 
441
- if aws_node_types.include?(node_type) &&
442
- carrenza_node_types.include?(node_type)
443
-
444
- error "error: ambiguous hosting for #{node_type} in #{environment}"
445
- print_empty_line
446
- info "specify the hosting provider and node type, for example: "
447
- hosting_providers.each do |hosting_provider|
448
- info "\n govuk-connect ssh #{bold(hosting_provider)}/#{node_type}"
449
- end
450
- info "\n"
451
-
452
- exit 1
453
- elsif aws_node_types.include?(node_type)
417
+ if aws_node_types.include?(node_type)
454
418
  :aws
455
- elsif carrenza_node_types.include?(node_type)
456
- :carrenza
457
419
  else
458
420
  error "error: couldn't find #{node_type} in #{environment}"
459
421
 
460
- all_node_types = (aws_node_types + carrenza_node_types).uniq.sort
461
- similar_node_types = strings_similar_to(node_type, all_node_types)
422
+ similar_node_types = strings_similar_to(node_type, aws_node_types)
462
423
 
463
424
  if similar_node_types.any?
464
425
  info "\ndid you mean:"
@@ -493,17 +454,6 @@ class GovukConnect::CLI
493
454
  return :aws
494
455
  end
495
456
 
496
- carrenza_app_names = application_names_from_node_class_data(
497
- environment,
498
- :carrenza,
499
- )
500
-
501
- if carrenza_app_names.include? app_name
502
- log "debug: #{app_name} is hosted in Carrenza"
503
-
504
- return :carrenza
505
- end
506
-
507
457
  error "error: unknown hosting value '#{hosting}' for #{app_name}"
508
458
  exit 1
509
459
  end
@@ -650,7 +600,6 @@ class GovukConnect::CLI
650
600
  def rabbitmq_root_password_command(hosting, environment)
651
601
  hieradata_directory = {
652
602
  aws: "puppet_aws",
653
- carrenza: "puppet",
654
603
  }[hosting]
655
604
 
656
605
  directory = File.join(
@@ -666,14 +615,11 @@ class GovukConnect::CLI
666
615
  uri = URI(url)
667
616
 
668
617
  host_to_hosting_and_environment = {
669
- "ci-alert.integration.publishing.service.gov.uk" => %i[carrenza ci],
670
618
  "alert.integration.publishing.service.gov.uk" => %i[aws integration],
671
619
  "alert.staging.govuk.digital" => %i[aws staging],
672
620
  "alert.blue.staging.govuk.digital" => %i[aws staging],
673
- "alert.staging.publishing.service.gov.uk" => %i[carrenza staging],
674
621
  "alert.production.govuk.digital" => %i[aws production],
675
622
  "alert.blue.production.govuk.digital" => %i[aws production],
676
- "alert.publishing.service.gov.uk" => %i[carrenza production],
677
623
  }
678
624
 
679
625
  unless host_to_hosting_and_environment.key? uri.host
@@ -711,9 +657,12 @@ class GovukConnect::CLI
711
657
  @verbose = true
712
658
  end
713
659
 
714
- opts.on("-h", "--help", "Prints usage information and examples") do
660
+ opts.on("-h", "--help", "Prints usage examples and information") do
715
661
  info opts
716
662
  print_empty_line
663
+ info bold("EXAMPLES")
664
+ info EXAMPLES
665
+ print_empty_line
717
666
  info bold("CONNECTION TYPES")
718
667
  types.keys.each do |x|
719
668
  info " #{x}"
@@ -726,9 +675,6 @@ class GovukConnect::CLI
726
675
  print_empty_line
727
676
  info bold("APPLICATION TARGET")
728
677
  info APP_TARGET_DESCRIPTION
729
- print_empty_line
730
- info bold("EXAMPLES")
731
- info EXAMPLES
732
678
  exit
733
679
  end
734
680
  opts.on("-V", "--version", "Prints version information") do
@@ -755,7 +701,7 @@ class GovukConnect::CLI
755
701
 
756
702
  hosting = hosting.to_sym
757
703
 
758
- unless %i[carrenza aws].include? hosting
704
+ unless %i[aws].include? hosting
759
705
  error "error: unknown hosting provider: #{hosting}"
760
706
  print_empty_line
761
707
  info "available hosting providers are:"
@@ -795,7 +741,7 @@ class GovukConnect::CLI
795
741
  end
796
742
 
797
743
  if app_name_and_number.include? ":"
798
- app_name, number = name_and_number.split ":"
744
+ app_name, number = app_name_and_number.split ":"
799
745
 
800
746
  number = number.to_i
801
747
  else
@@ -832,9 +778,6 @@ class GovukConnect::CLI
832
778
  if name.end_with? ".internal"
833
779
  target = name
834
780
  hosting = :aws
835
- elsif name.end_with? ".gov.uk"
836
- target = name
837
- hosting = :carrenza
838
781
  else
839
782
  # The hosting might not have been provided, so check if necessary
840
783
  hosting ||= hosting_for_target_and_environment(target, environment)
@@ -843,7 +786,6 @@ class GovukConnect::CLI
843
786
  name,
844
787
  environment,
845
788
  hosting,
846
- ssh_username,
847
789
  )
848
790
 
849
791
  if domains.length.zero?
@@ -951,16 +893,6 @@ class GovukConnect::CLI
951
893
  )
952
894
  end,
953
895
 
954
- "sidekiq-monitoring" => proc do |target, environment, args, extra_args, _options|
955
- check_for_additional_arguments("sidekiq-monitoring", args)
956
- check_for_additional_arguments("sidekiq-monitoring", extra_args)
957
- ssh(
958
- target || "backend",
959
- environment,
960
- port_forward: SIDEKIQ_MONITORING_PORT,
961
- )
962
- end,
963
-
964
896
  "ssh" => proc do |target, environment, args, extra_args, options|
965
897
  check_for_target(target)
966
898
  target = target_from_options(target, options)
@@ -1,3 +1,3 @@
1
1
  module GovukConnect
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.5.1".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.3.0
4
+ version: 0.5.1
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-07-17 00:00:00.000000000 Z
11
+ date: 2021-05-28 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.16.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.16.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.1.2
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: []