govuk-connect 0.7.0 → 0.8.0

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: 0cec686de41c55db9dbb4d680aa596cdb8ac039845011bb4aa435b94eb3f4e9f
4
- data.tar.gz: bb8eb071164ade05f8dbbe1e2e3bc780ea883dc848b384de14f2ea795d5920f3
3
+ metadata.gz: 3809f92432d9568040b786cea22448406da43403917459d8bf96210457be9cd6
4
+ data.tar.gz: a606f53b33df1e4baa5c95f265c4fd078c886ec2f9d853c3950f087eb19b0201
5
5
  SHA512:
6
- metadata.gz: 35f339438073571faee19d7da1a8d191d15a8cd389b3786f686c1ab59e3c3e0a23bddd5948135578b5cc87572d971c896c4c4feb0287e0c2b2acfa3e79c16da2
7
- data.tar.gz: 7b50c8d20288f0206dc8d312f8f4c05b0f0763c1437726865af18c2cf7f0ceaebeb1a99135044a3cd1f49d4be548c7327a6d784b0b16031114cef6ad446f4102
6
+ metadata.gz: d47dce35c946feb4c5869eb3cbc3b7a6ac1796cdb668ecd79d79e4d19e19cd39800e9e593336239120d6681a6016e2f0c9a3561e7e6c6484f18eb1275ed002ed
7
+ data.tar.gz: 343c1544abe716c63783591c3a6d33a2cc83c03ad2bab7cb3ed273526c523dd8d46a362bd9d6333b513ea250b4c2655f2009f77d80c84cb4b6362aafbe27eb54
@@ -24,11 +24,9 @@ class GovukConnect::CLI
24
24
 
25
25
  gds govuk connect scp-pull --environment integration backend /tmp/filename.txt ~/Downloads/
26
26
 
27
- gds govuk connect app-console --environment staging publishing-api
28
-
29
- gds govuk connect app-dbconsole -e integration whitehall_backend/whitehall
30
-
31
27
  gds govuk connect rabbitmq -e staging aws/rabbitmq
28
+
29
+ gds govuk connect amazonmq -e integration
32
30
  EXAMPLES
33
31
 
34
32
  MACHINE_TARGET_DESCRIPTION = <<-DOCS.freeze
@@ -70,12 +68,14 @@ class GovukConnect::CLI
70
68
 
71
69
  CONNECTION_TYPE_DESCRIPTIONS = {
72
70
  "ssh" => "Connect to a machine through SSH.",
73
- "app-console" => "Launch a console for an application. For example, a rails console when connecting to a Rails application.",
74
- "app-dbconsole" => "Launch a console for the database for an application.",
71
+ "app-console" => "(DEPRECATED; use kubectl instead) Launch a Rails console for an application.",
72
+ "app-dbconsole" => "(DEPRECATED; use kubectl instead) Launch a Rails database console for an application.",
75
73
  "rabbitmq" => "Setup port forwarding to the RabbitMQ admin interface.",
74
+ "amazonmq" => "Setup port forwarding to the AmazonMQ admin interface.",
76
75
  }.freeze
77
76
 
78
77
  RABBITMQ_PORT = 15_672
78
+ AMAZONMQ_PORT = 443
79
79
 
80
80
  JUMPBOXES = {
81
81
  test: {
@@ -113,6 +113,15 @@ class GovukConnect::CLI
113
113
  info "Check this is correct, and if it isn't, set the `USER` environment variable to the correct username."
114
114
  end
115
115
 
116
+ def print_vpn_help_info
117
+ info "You may also wish to check that you are connected to the VPN, as attempting to SSH into an instance when NOT on the VPN can result in an operation timed out error"
118
+ end
119
+
120
+ def print_k8s_setup_info
121
+ info "If that doesn't work for you, follow the setup instructions at"
122
+ info "https://govuk-k8s-user-docs.publishing.service.gov.uk/get-started/access-eks-cluster\n"
123
+ end
124
+
116
125
  # From Rosetta Code: https://rosettacode.org/wiki/Levenshtein_distance#Ruby
117
126
  def levenshtein_distance(string1, string2)
118
127
  string1 = string1.downcase
@@ -289,6 +298,8 @@ class GovukConnect::CLI
289
298
  error "\nerror: command failed: #{command}"
290
299
  print_empty_line
291
300
  print_ssh_username_configuration_help
301
+ print_empty_line
302
+ print_vpn_help_info
292
303
  exit 1
293
304
  end
294
305
 
@@ -572,6 +583,40 @@ class GovukConnect::CLI
572
583
  exec(*ssh_command)
573
584
  end
574
585
 
586
+ def remote_port_forward(
587
+ target,
588
+ environment,
589
+ port_forward,
590
+ additional_arguments: []
591
+ )
592
+ log "debug: remote port-forward to #{target} in #{environment}"
593
+
594
+ target, hosting = ssh_target(target, environment)
595
+
596
+ localhost_port = random_free_port
597
+
598
+ ssh_command = [
599
+ "ssh",
600
+ *ssh_identity_arguments,
601
+ "-N",
602
+ "-L",
603
+ "#{localhost_port}:#{target}:#{port_forward}",
604
+ user_at_host(
605
+ ssh_username,
606
+ jumpbox_for_environment_and_hosting(environment, hosting),
607
+ ),
608
+ ]
609
+
610
+ info "Port forwarding setup, access:\n\n https://127.0.0.1:#{localhost_port}/\n\n"
611
+ info "(ignore any warnings about certificate mis-match - this is expected and OK)"
612
+
613
+ ssh_command += additional_arguments
614
+
615
+ info "\n#{bold('Running command:')} #{ssh_command.join(' ')}\n\n"
616
+
617
+ exec(*ssh_command)
618
+ end
619
+
575
620
  def scp(
576
621
  target,
577
622
  environment,
@@ -624,6 +669,10 @@ class GovukConnect::CLI
624
669
  "cd #{directory} && rake eyaml:decrypt_value[#{environment},govuk_rabbitmq::root_password]"
625
670
  end
626
671
 
672
+ def amazonmq_root_password_command(environment)
673
+ "sops data/app-amazonmq/#{environment}/common.secret.tfvars"
674
+ end
675
+
627
676
  def hosting_and_environment_from_url(url)
628
677
  uri = URI(url)
629
678
 
@@ -788,7 +837,7 @@ class GovukConnect::CLI
788
837
  # Split something like aws/backend:2 in to :aws, 'backend', 2
789
838
  hosting, name, number = parse_hosting_name_and_number(target)
790
839
 
791
- if name.end_with? ".internal"
840
+ if name.end_with?(".internal") || name.end_with?(".govuk-internal.digital")
792
841
  target = name
793
842
  hosting = :aws
794
843
  else
@@ -801,7 +850,7 @@ class GovukConnect::CLI
801
850
  hosting,
802
851
  )
803
852
 
804
- if domains.length.zero?
853
+ if domains.empty?
805
854
  error "error: couldn't find #{name} in #{hosting}/#{environment}"
806
855
 
807
856
  node_types = govuk_node_list_classes(environment, hosting)
@@ -867,20 +916,33 @@ class GovukConnect::CLI
867
916
  end
868
917
  end
869
918
 
919
+ def target_name_to_k8s_deployment(target_name)
920
+ {
921
+ /draft_[a-z_]+\/([a-z_-]+)/ => "draft-\\1",
922
+ /.*\// => "", # If not draft, drop the Puppet class prefix.
923
+ "whitehall_backend/whitehall" => "whitehall-admin",
924
+ "whitehall_frontend/whitehall" => "whitehall-frontend",
925
+ }.reduce(target_name) do |result, (pattern, replacement)|
926
+ result.sub(pattern, replacement)
927
+ end
928
+ end
929
+
870
930
  def types
871
931
  @types ||= {
872
- "app-console" => proc do |target, environment, args, extra_args, _options|
873
- check_for_target(target)
874
- check_for_additional_arguments("app-console", args)
875
- check_for_additional_arguments("app-console", extra_args)
876
- govuk_app_command(target, environment, "console")
932
+ "app-console" => proc do |target, _environment, _args, _extra_args, _options|
933
+ target ||= "<app-name>"
934
+ deployment = target_name_to_k8s_deployment(target)
935
+ info "#{bold('The command for opening a Rails console has changed. Run this instead:')}\n\n"
936
+ info " k exec -it deploy/#{deployment} -- rails c\n\n"
937
+ print_k8s_setup_info
877
938
  end,
878
939
 
879
- "app-dbconsole" => proc do |target, environment, args, extra_args, _options|
880
- check_for_target(target)
881
- check_for_additional_arguments("app-dbconsole", args)
882
- check_for_additional_arguments("app-dbconsole", extra_args)
883
- govuk_app_command(target, environment, "dbconsole")
940
+ "app-dbconsole" => proc do |target, _environment, _args, _extra_args, _options|
941
+ target ||= "<app-name>"
942
+ deployment = target_name_to_k8s_deployment(target)
943
+ info "#{bold('The command for opening a Rails dbconsole has changed. Run this instead:')}\n\n"
944
+ info " k exec -it deploy/#{deployment} -- rails db\n\n"
945
+ print_k8s_setup_info
884
946
  end,
885
947
 
886
948
  "rabbitmq" => proc do |target, environment, args, extra_args, _options|
@@ -906,6 +968,25 @@ class GovukConnect::CLI
906
968
  )
907
969
  end,
908
970
 
971
+ "amazonmq" => proc do |target, environment, args, extra_args, _options|
972
+ check_for_additional_arguments("amazonmq", args)
973
+ check_for_additional_arguments("amazonmq", extra_args)
974
+
975
+ target ||= "publishingmq.#{environment}.govuk-internal.digital"
976
+
977
+ info "You'll need to login as the RabbitMQ #{bold('root')} user."
978
+ info "Get the password from govuk-aws-data, for example:\n\n"
979
+ info " # from the root directory of govuk-aws-data repository\n\n"
980
+ info " #{bold(amazonmq_root_password_command(environment))}"
981
+ print_empty_line
982
+
983
+ remote_port_forward(
984
+ target,
985
+ environment,
986
+ AMAZONMQ_PORT,
987
+ )
988
+ end,
989
+
909
990
  "ssh" => proc do |target, environment, args, extra_args, options|
910
991
  check_for_target(target)
911
992
  target = target_from_options(target, options)
@@ -1,3 +1,3 @@
1
1
  module GovukConnect
2
- VERSION = "0.7.0".freeze
2
+ VERSION = "0.8.0".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.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-08 00:00:00.000000000 Z
11
+ date: 2023-05-26 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: 4.3.0
61
+ version: 4.10.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: 4.3.0
68
+ version: 4.10.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
@@ -90,14 +90,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - ">="
92
92
  - !ruby/object:Gem::Version
93
- version: '2.7'
93
+ version: '3.0'
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []
100
- rubygems_version: 3.3.19
100
+ rubygems_version: 3.4.13
101
101
  signing_key:
102
102
  specification_version: 4
103
103
  summary: govuk-connect command line tool