@govuk-pay/cli 0.0.55 → 0.0.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/package.json +1 -1
  2. package/resources/legacy-ruby-cli/README.md +5 -74
  3. package/resources/legacy-ruby-cli/lib/pay_cli/commands/doctor.rb +0 -85
  4. package/resources/legacy-ruby-cli/lib/pay_cli/config.rb +1 -23
  5. package/resources/legacy-ruby-cli/lib/pay_cli/entry_point.rb +4 -21
  6. package/resources/legacy-ruby-cli/.rspec +0 -1
  7. package/resources/legacy-ruby-cli/config/generate-secrets.yml +0 -9
  8. package/resources/legacy-ruby-cli/config/secrets.yml +0 -682
  9. package/resources/legacy-ruby-cli/config/service_secrets.yml +0 -203
  10. package/resources/legacy-ruby-cli/lib/pay_cli/aws/services.rb +0 -47
  11. package/resources/legacy-ruby-cli/lib/pay_cli/commands/aws.rb +0 -29
  12. package/resources/legacy-ruby-cli/lib/pay_cli/commands/browse.rb +0 -31
  13. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/app_client.rb +0 -216
  14. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/config.rb +0 -142
  15. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/config.yaml +0 -198
  16. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/docker.rb +0 -66
  17. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/all.yaml +0 -847
  18. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/card.yaml +0 -491
  19. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/custom.yaml +0 -71
  20. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/docker-compose.erb +0 -395
  21. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/end-to-end.erb +0 -30
  22. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/java.yaml +0 -456
  23. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/localstack/init-aws.sh +0 -70
  24. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/naxsi/readme.md +0 -1
  25. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/postgres/docker-entrypoint-initdb.d/make_payments_databases.sql +0 -26
  26. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/adminusers.env +0 -49
  27. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/cardid.env +0 -2
  28. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/connector.env +0 -70
  29. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/demo-service.env +0 -10
  30. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/egress/squid.conf +0 -47
  31. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/frontend.env +0 -12
  32. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/java_app.env +0 -1
  33. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ledger.env +0 -7
  34. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/products-ui.env +0 -14
  35. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/products.env +0 -25
  36. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/publicapi.env +0 -13
  37. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/publicauth.env +0 -13
  38. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/selfservice.env +0 -21
  39. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/frontend-proxy.crt +0 -18
  40. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/products-ui-proxy.crt +0 -20
  41. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/publicapi-proxy.crt +0 -18
  42. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/selfservice-proxy.crt +0 -20
  43. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/stubs-proxy.crt +0 -18
  44. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/frontend-proxy.key +0 -28
  45. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/products-ui-proxy.key +0 -28
  46. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/publicapi-proxy.key +0 -28
  47. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/selfservice-proxy.key +0 -28
  48. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/stubs-proxy.key +0 -28
  49. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/make-selfsigned.sh +0 -2
  50. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/stubs.env +0 -12
  51. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/toolbox.env +0 -5
  52. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/webhooks.env +0 -9
  53. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/toolbox.yaml +0 -473
  54. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/image_extractor.rb +0 -20
  55. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local.rb +0 -451
  56. package/resources/legacy-ruby-cli/lib/pay_cli/commands/secrets.rb +0 -114
  57. package/resources/legacy-ruby-cli/lib/pay_cli/commands/tunnel/services.yml +0 -49
  58. package/resources/legacy-ruby-cli/lib/pay_cli/naming.rb +0 -6
  59. package/resources/legacy-ruby-cli/lib/pay_cli/secrets.rb +0 -281
  60. package/resources/legacy-ruby-cli/package-lock.json +0 -6
  61. package/resources/legacy-ruby-cli/rds_access/connect.sh +0 -175
  62. package/resources/legacy-ruby-cli/spec/.rubocop.yml +0 -2
  63. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.complex +0 -34
  64. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.complex_differing_froms +0 -33
  65. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.no_from +0 -3
  66. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.simple +0 -5
  67. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.simple_no_tag +0 -5
  68. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.with_sha +0 -5
  69. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.with_sha_no_tag +0 -5
  70. package/resources/legacy-ruby-cli/spec/lib/pay_cli/commands/local/image_extractor_spec.rb +0 -55
  71. package/resources/legacy-ruby-cli/spec/naming_spec.rb +0 -19
  72. package/resources/legacy-ruby-cli/spec/spec_helper.rb +0 -106
@@ -1,281 +0,0 @@
1
- require 'open3'
2
- require 'pp'
3
- require 'yaml'
4
-
5
- require 'aws-sdk-ssm'
6
- require 'tty-table'
7
-
8
- module PayCLI::Secrets
9
- SECRETS_FILE_PATH = File.join(PayCLI::Config::CONFIG_PATH, 'secrets.yml')
10
- GENERATE_FILE_PATH = File.join(PayCLI::Config::CONFIG_PATH, 'generate-secrets.yml')
11
-
12
- SECRETS_PROVIDERS = Proc.new do
13
- # We should produce a mapping of env -> secret_name -> provider
14
- mapping = {}
15
-
16
- generate_secrets_info = YAML.load_file(GENERATE_FILE_PATH)
17
-
18
- YAML.load_file(SECRETS_FILE_PATH).each do |provider, environments|
19
- environments.map do |env, secrets|
20
- generate_secrets_info.each do |service, service_generate_names|
21
- mapping[env] ||= {}
22
- service_generate_names.each do | generate_info |
23
- mapping[env][service] ||= {}
24
- mapping[env][service][generate_info.first] = {
25
- provider: 'generate',
26
- detail: generate_info.last
27
- }
28
- end
29
- end
30
- secrets.each do |service, service_secrets|
31
- mapping[env] ||= {}
32
-
33
- service_secrets.each do |secret_info|
34
- mapping[env][service] ||= {}
35
-
36
- if secret_info.class == Array
37
- secret_name = secret_info.first
38
-
39
- mapping[env][service][secret_name] = {
40
- provider: provider,
41
- detail: secret_info.last
42
- }
43
- else
44
- mapping[env][service][secret_info] = {
45
- provider: provider,
46
- }
47
- end
48
- end
49
- end
50
- end
51
- end
52
-
53
- mapping
54
- end.call
55
-
56
- def self.fetch!(env, service, key, query_ssm=false)
57
- if query_ssm
58
- STDERR.puts "Using ssm to lookup secret"
59
- ssm_val = self.fetch_single_secret_from_env_for_service!(env,service, key)
60
- unless ssm_val
61
- STDERR.puts "Could not find #{key} for #{service} in #{env} ssm"
62
- exit 1
63
- end
64
- return ssm_val
65
- end
66
-
67
-
68
- unless PayCLI::Secrets::SECRETS_PROVIDERS.key? env
69
- STDERR.puts "Could not find #{env} in secrets mapping #{SECRETS_FILE_PATH}"
70
- exit 1
71
- end
72
-
73
- unless PayCLI::Secrets::SECRETS_PROVIDERS[env].key? service
74
- STDERR.puts "Could not find #{service} in secrets mapping #{SECRETS_FILE_PATH} for #{env}"
75
- exit 1
76
- end
77
-
78
- unless PayCLI::Secrets::SECRETS_PROVIDERS[env][service].key? key
79
- STDERR.puts "Could not find #{key} in #{env} secrets mapping for #{service}"
80
- exit 1
81
- end
82
-
83
- provider = PayCLI::Secrets::SECRETS_PROVIDERS[env][service][key][:provider]
84
- STDERR.puts "Found provider #{provider} for key #{key} in #{env} for #{service}"
85
-
86
- case provider
87
- when 'local'
88
- fetch_local! env, service, key
89
- when 'generate'
90
- generate! PayCLI::Secrets::SECRETS_PROVIDERS[env][service][key][:detail]
91
- when 'value'
92
- fetch_value! env, service, key
93
- when 'pass'
94
- fetch_pass! '', PayCLI::Secrets::SECRETS_PROVIDERS[env][service][key][:detail]
95
- when /^pay-.*pass$/
96
- pass_path = PayCLI::Secrets::SECRETS_PROVIDERS[env][service][key][:detail]
97
- fetch_pay_pass! env, service, key, provider, pass_path
98
- else
99
- STDERR.puts "Provider #{provider} not supported"
100
- exit 1
101
- end
102
- end
103
-
104
- def self.generate!(detail)
105
- puts "Generating #{detail}"
106
- detail_array = detail.split(":")
107
-
108
- abort "Incorrect format of generate detail #{detail}" unless detail_array.length == 2
109
- method, length = detail_array
110
- case method
111
- when 'random'
112
- SecureRandom.urlsafe_base64(length.to_i)
113
- end
114
- end
115
-
116
- def self.fetch_pass!(path, pass_path)
117
- env = {}
118
- env['PASSWORD_STORE_DIR'] = path if path
119
-
120
- stdin, stdout, wait_thr = Open3.popen2(env, "pass #{pass_path}")
121
- password = stdout.readlines.map(&:chomp).join("\n")
122
- stdin.close
123
- stdout.close
124
- pass_status = wait_thr.value
125
-
126
- abort "Pass failed, error above" unless pass_status.success?
127
-
128
- password
129
- end
130
-
131
- def self.fetch_pay_pass!(env, service, key, provider, pass_path)
132
- if ! ENV.has_key?('WORKSPACE')
133
- STDERR.puts 'Error: You must set your WORKSPACE env var to the directory where you checkout alphagov github projects'
134
- exit 1
135
- end
136
-
137
- path = File.expand_path(File.join(
138
- ENV['WORKSPACE'], provider
139
- ))
140
-
141
- abort "Path #{path} doesn't exist or isn't a directory" unless File.directory? path
142
-
143
- STDERR.puts "Pulling secret #{key} from #{path} for #{service}"
144
- fetch_pass! path, pass_path
145
- end
146
-
147
- def self.fetch_local!(env, service, key)
148
- environments = YAML.load_file(PayCLI::Config::LOCAL_SECRETS_PATH)
149
-
150
- value = environments.fetch(env, nil)&.fetch(service, nil)&.fetch(key, nil)
151
- if value.nil?
152
- STDERR.puts "Could not find #{key} in #{env} in local provider for #{service}"
153
- exit 1
154
- end
155
-
156
- value
157
- end
158
-
159
- def self.fetch_value!(env, service, key)
160
- PayCLI::Secrets::SECRETS_PROVIDERS
161
- .fetch(env)
162
- .fetch(service)
163
- .fetch(key)
164
- .fetch(:detail)
165
- end
166
-
167
- def self.secrets_for_service(service)
168
- secrets_definition_path = File.join(
169
- PayCLI::Config::CONFIG_PATH, 'service_secrets.yml'
170
- )
171
- secrets_definitions = YAML.load_file(secrets_definition_path)
172
-
173
- unless secrets_definitions.key? service
174
- abort "Could not find secrets definition for #{service}"
175
- end
176
-
177
- secrets_definitions.fetch service
178
- end
179
-
180
- def self.fetch_single_secret_from_env_for_service!(env, service, name)
181
- PayCLI::Environment.setup! env
182
- ssm = Aws::SSM::Client.new
183
-
184
- begin
185
- secret_value = ssm.get_parameter({
186
- name: secret_name(env, service, name),
187
- with_decryption: true
188
- }).parameter.value
189
- rescue Aws::SSM::Errors::ParameterNotFound
190
- secret_value = nil
191
- end
192
-
193
- secret_value
194
- end
195
-
196
- def self.secrets_in_envs_for_service(envs, service)
197
- accounts = envs.map { |e| e.split('-').first }.uniq
198
- all_parameters = []
199
-
200
- accounts.each do |acc|
201
- PayCLI::Environment.setup! acc
202
- ssm = Aws::SSM::Client.new
203
-
204
- next_token = nil
205
- loop do
206
- STDERR.puts "Making request to AWS SSM for #{acc}"
207
-
208
- opts = {}
209
- opts[:next_token] = next_token unless next_token.nil?
210
-
211
- response = ssm.describe_parameters(opts)
212
-
213
- next_token = response.next_token
214
- all_parameters += response.parameters
215
-
216
- break if next_token.nil?
217
- end
218
- end
219
-
220
- secrets_per_env = envs.map do |env|
221
- secrets = all_parameters
222
- .select { |p| p.name =~ /^#{env}_#{service}\./ }
223
- .map { |p| p.name }
224
- .map { |p| p.sub(/^#{env}_#{service}\./, '') }
225
- .map { |p| p.upcase }
226
- [env, secrets]
227
- end.to_h
228
-
229
- secrets_per_env
230
- end
231
-
232
- def self.secret_name(env, service, name)
233
- return _concourse_secret_name(service, name) if %w[cd-pay-dev cd-pay-deploy cd-main].include? service
234
-
235
- "#{env}_#{service}.#{name}".downcase
236
- end
237
-
238
- def self._concourse_secret_name(service, name)
239
- # Service name is `cd-pay-dev` but the ssm name is only `pay-dev` so remove the cd-
240
- service = service[3..]
241
-
242
- "/pay-cd/concourse/pipelines/#{service.downcase}/#{name}"
243
- end
244
-
245
- def self.write_secret_for_service_in_env!(env, service, name, value)
246
- PayCLI::Environment.setup! env
247
- ssm = Aws::SSM::Client.new
248
-
249
- STDERR.puts "Updating value of #{name} in #{env} with #{value}"
250
- ssm.put_parameter({
251
- name: secret_name(env, service, name),
252
- type: 'SecureString',
253
- value: value,
254
- overwrite: true,
255
- })
256
- end
257
-
258
- def self.fetch_secret_for_service_from_env(env, service, name)
259
- PayCLI::Environment.setup! env
260
- ssm = Aws::SSM::Client.new
261
-
262
- STDERR.puts "Fetching secret #{name} from #{env} / #{service}"
263
-
264
- ssm.get_parameter({
265
- name: secret_name(env, service, name),
266
- with_decryption: true
267
- }).parameter.value
268
- end
269
-
270
- def self.diff_table(old_value, new_value)
271
- TTY::Table.new([
272
- ['Old', '=>', 'New'],
273
- [old_value, '', new_value]
274
- ]).render(
275
- :unicode,
276
- alignment: :center,
277
- padding: 1,
278
- multiline: true,
279
- )
280
- end
281
- end
@@ -1,6 +0,0 @@
1
- {
2
- "name": "cli",
3
- "lockfileVersion": 2,
4
- "requires": true,
5
- "packages": {}
6
- }
@@ -1,175 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Temporary script for tunneling to RDS during development of the bastion solution
4
-
5
- set -euo pipefail
6
-
7
- function usage() {
8
- echo "Usage: $0 <environment> <app>"
9
- echo
10
- echo "Examples:"
11
- echo " $0 test-12 adminusers"
12
- echo " $0 test-perf-1 ledger"
13
- exit 1
14
- }
15
-
16
- function is_help_arg() {
17
- if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
18
- return 0
19
- fi
20
-
21
- return 1
22
- }
23
-
24
- if [ "$#" -ne 2 ]; then
25
- usage
26
- fi
27
-
28
- ENVIRONMENT="$1"
29
- APP="$2"
30
- if [[ -z $ENVIRONMENT ]] || [[ -z $APP ]] || is_help_arg "$ENVIRONMENT" || is_help_arg "$APP"; then
31
- usage
32
- fi
33
-
34
- for x in aws yq jq ssh-keygen aws-vault ssh
35
- do
36
- if ! command -v $x &> /dev/null
37
- then
38
- echo "$x is not installed, exiting."
39
- exit 1
40
- fi
41
- done
42
-
43
- ACCOUNT="${ENVIRONMENT%%-*}"
44
- PAY_ENV_NAME=$(sed -E 's/-[0-9]+$//' <<<"$ENVIRONMENT")
45
- KEY_LOCATION="${TMPDIR}rds_tunnel_temp_key"
46
-
47
- function cleanup() {
48
- echo "cleaning up..."
49
- if rm "${KEY_LOCATION}"*; then
50
- echo "Removed temp key pair";
51
- else
52
- echo "Failed to remove key pair from ${KEY_LOCATION}"
53
- fi
54
- }
55
-
56
- trap cleanup EXIT
57
-
58
- PROMPT_TEXT="Do you require read-only access, or write-access to the database? [R/w]: "
59
- read -r -p "$PROMPT_TEXT" READONLY_INPUT
60
- while [ "$READONLY_INPUT" != "R" ] && [ "$READONLY_INPUT" != "r" ] && [ "$READONLY_INPUT" != "W" ] && [ "$READONLY_INPUT" != "w" ] && [ "$READONLY_INPUT" != "" ]; do
61
- echo
62
- read -r -p "$PROMPT_TEXT" READONLY_INPUT
63
- done
64
- echo
65
-
66
- if [ "$READONLY_INPUT" == "w" ] || [ "$READONLY_INPUT" == "W" ]; then
67
- echo "Database write access requested"
68
- READONLY=0
69
- else
70
- echo "Database read-only access requested"
71
- READONLY=1
72
- fi
73
-
74
- echo "Finding bastion host"
75
- read -r bastion_instance_id availability_zone <<< "$(aws-vault exec "$ACCOUNT" -- \
76
- aws autoscaling describe-auto-scaling-groups | \
77
- jq --arg env "$ENVIRONMENT" '.AutoScalingGroups[] | select(.AutoScalingGroupName == $env + "-bastion").Instances[0] | "\(.InstanceId) \(.AvailabilityZone)"' -r)"
78
-
79
- if [[ -z $bastion_instance_id ]] || [[ -z $availability_zone ]]; then
80
- echo "Failed to find bastion instance"
81
- exit 1
82
- fi
83
-
84
- echo "Found bastion $bastion_instance_id"
85
-
86
- echo "Getting RDS endpoint"
87
- rds_endpoint="$(aws-vault exec "$ACCOUNT" -- \
88
- aws rds describe-db-instances |\
89
- jq --arg rds_instance "${ENVIRONMENT}-${APP}" '.DBInstances[] | select(.DBInstanceIdentifier | startswith($rds_instance)).Endpoint.Address' -r)"
90
-
91
- if [[ -z $rds_endpoint ]]; then
92
- echo "Failed to find RDS endpoint"
93
- exit 1
94
- fi
95
- echo "RDS endpoint is: ${rds_endpoint}"
96
-
97
- echo "Getting RDS instance engine version"
98
- engine_version=$(aws-vault exec "$ACCOUNT" -- \
99
- aws rds describe-db-instances | \
100
- jq -r --arg rds_instance "${ENVIRONMENT}-${APP}" '.DBInstances[] | select(.DBInstanceIdentifier | startswith($rds_instance)).EngineVersion')
101
- echo "RDS engine_version is ${engine_version}"
102
-
103
- echo "Generating ssh key pair, saving to ${KEY_LOCATION}"
104
- if ! ssh-keygen -q -t rsa -b 4096 -f "$KEY_LOCATION" -N ''; then
105
- echo "Failed to generate ssh key pair"
106
- exit 1
107
- fi
108
-
109
- echo "Uploading public key to bastion"
110
- if ! aws-vault exec "$ACCOUNT" -- \
111
- aws ec2-instance-connect send-ssh-public-key \
112
- --instance-id "$bastion_instance_id" \
113
- --availability-zone "$availability_zone" \
114
- --instance-os-user ec2-user \
115
- --ssh-public-key "file://${KEY_LOCATION}.pub"; then
116
-
117
- echo "Failed to upload public key to bastion"
118
- exit 1
119
- fi
120
-
121
- yellow="\033[0;33m"
122
- reset="\033[0m"
123
- ul="\033[4m"
124
- ulstop="\033[24m"
125
-
126
- echo -e "${yellow} ${reset}"
127
- echo -e "${yellow} ⚠️ WARNING: When using SSM, any and all activity you perform may be getting logged for security auditing purposes (think PCI).${reset}"
128
- echo -e "${yellow} Avoid sending or accessing ${ul}anything${ulstop} that could cause a security breach, such as:${reset}"
129
- echo -e "${yellow} ${reset}"
130
- echo -e "${yellow} • Secret API Keys or Tokens${reset}"
131
- echo -e "${yellow} • Credentials or Passwords${reset}"
132
- echo -e "${yellow} • Cardholder Data or Personally-Identifiable Information (PII)${reset}"
133
- echo -e "${yellow} • Anything else that may be protected by GDPR or PCI-DSS${reset}"
134
- echo -e "${yellow} • Anything classified as GSC 'Secret' or above${reset}"
135
- echo -e "${yellow} ${reset}"
136
- echo -e "${yellow} If you have a problem with this or aren\'t sure, use Ctrl-C ${ul}right now${ulstop} and discontinue your SSM session.${reset}"
137
- echo -e "${yellow} ${reset}"
138
-
139
- echo "Opening tunnel to rds"
140
- if ! aws-vault exec "$ACCOUNT" -- \
141
- ssh -i "$KEY_LOCATION" -N -f -M -S temp-ssh.sock \
142
- -L 65432:"$rds_endpoint":5432 ec2-user@"$bastion_instance_id" \
143
- -o "UserKnownHostsFile=/dev/null" \
144
- -o "StrictHostKeyChecking=no" \
145
- -o IdentitiesOnly=yes \
146
- -o ProxyCommand="aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p"; then
147
- echo "Failed to open tunnel to RDS"
148
- exit 1
149
- fi
150
-
151
- SOURCE_DIRECTORY=$(dirname "$BASH_SOURCE")
152
-
153
- if [ "$READONLY" -eq 1 ]; then
154
- DB_USER=$(yq eval ".value.$ENVIRONMENT.$APP.DB_SUPPORT_USER_READONLY" < "${SOURCE_DIRECTORY}/../config/secrets.yml")
155
- DB_USER_SECRET_NAME="aws/rds/support_readonly_users/${PAY_ENV_NAME}/${DB_USER}" # pragma: allowlist secret
156
- PAY_SECRETS_PASSWORD_NAME="DB_SUPPORT_PASSWORD_READONLY" # pragma: allowlist secret
157
- else
158
- DB_USER=$(yq eval ".value.$ENVIRONMENT.$APP.DB_USER" < "${SOURCE_DIRECTORY}/../config/secrets.yml")
159
- DB_USER_SECRET_NAME="aws/rds/application_users/${ACCOUNT}/${DB_USER}" # pragma: allowlist secret
160
- PAY_SECRETS_PASSWORD_NAME="DB_PASSWORD" # pragma: allowlist secret
161
- fi
162
-
163
- echo -e "Connected tunnel to $APP RDS database in $ENVIRONMENT on port 65432\n"
164
- echo "Copy DB credentials to clipboard (in another window) using pay-low-pass:"
165
- echo -e " pay-low-pass $DB_USER_SECRET_NAME | pbcopy\n" # pragma: allowlist secret
166
- echo "Alternatively, fetch credentials from pay secrets:"
167
- echo -e " pay secrets fetch $ENVIRONMENT $APP $PAY_SECRETS_PASSWORD_NAME | pbcopy\n" # pragma: allowlist secret
168
- echo "Open psql with:"
169
- echo -e " psql -h localhost -p 65432 -U $DB_USER -d $APP\n"
170
- echo "Alternatively connect using docker instead of needing psql installed locally and set the password automatically using pay-low-pass:"
171
- echo -e " docker run --rm -ti postgres:${engine_version}-alpine psql --host docker.for.mac.localhost --port 65432 --user $DB_USER --dbname $APP\n"
172
- echo "Or even more conveniently connect using a docker container and set the password automatically using pay-low-pass:"
173
- echo -e " docker run -e \"PGPASSWORD=\$(pay-low-pass ${DB_USER_SECRET_NAME})\" --rm -ti postgres:${engine_version}-alpine psql --host docker.for.mac.localhost --port 65432 --user $DB_USER --dbname $APP\n"
174
- read -rsn1 -p "Press any key to close session."; echo
175
- ssh -O exit -S temp-ssh.sock '*'
@@ -1,2 +0,0 @@
1
- Metrics/BlockLength:
2
- IgnoredMethods: ['describe', 'context']
@@ -1,34 +0,0 @@
1
- # Preceeding comment
2
-
3
-
4
- FROM node:18.18.0-alpine3.18@sha256:619ce27eb37c7c0476bd518085bf1ba892e2148fc1ab5dbaff2f20c56e50444d as builder
5
-
6
- WORKDIR /app
7
- COPY package.json .
8
- COPY package-lock.json .
9
- RUN npm ci --quiet
10
-
11
- COPY . .
12
- RUN npm run compile
13
-
14
- FROM node:18.18.0-alpine3.18@sha256:619ce27eb37c7c0476bd518085bf1ba892e2148fc1ab5dbaff2f20c56e50444d as final
15
-
16
- RUN ["apk", "--no-cache", "upgrade"]
17
-
18
- RUN ["apk", "add", "--no-cache", "tini"]
19
-
20
- WORKDIR /app
21
- COPY . .
22
- RUN rm -rf ./test
23
- # Copy in compile assets and deps from build container
24
- COPY --from=builder /app/node_modules ./node_modules
25
- COPY --from=builder /app/govuk_modules ./govuk_modules
26
- COPY --from=builder /app/public ./public
27
- RUN npm prune --omit=dev
28
-
29
- ENV PORT 9000
30
- EXPOSE 9000
31
-
32
- ENTRYPOINT ["tini", "--"]
33
-
34
- CMD ["npm", "start"]
@@ -1,33 +0,0 @@
1
- # Preceeding comment
2
-
3
- FROM node:18.18.0-alpine3.18@sha256:619ce27eb37c7c0476bd518085bf1ba892e2148fc1ab5dbaff2f20c56e50444d as builder
4
-
5
- WORKDIR /app
6
- COPY package.json .
7
- COPY package-lock.json .
8
- RUN npm ci --quiet
9
-
10
- COPY . .
11
- RUN npm run compile
12
-
13
- FROM node:18.18.0-alpine3.18@sha256:619ce27eb37c7c0476bd518085bf1ba892e2148fc1ab5dbaff2f20c56e50444d as final
14
-
15
- RUN ["apk", "--no-cache", "upgrade"]
16
-
17
- RUN ["apk", "add", "--no-cache", "tini"]
18
-
19
- WORKDIR /app
20
- COPY . .
21
- RUN rm -rf ./test
22
- # Copy in compile assets and deps from build container
23
- COPY --from=builder /app/node_modules ./node_modules
24
- COPY --from=builder /app/govuk_modules ./govuk_modules
25
- COPY --from=builder /app/public ./public
26
- RUN npm prune --omit=dev
27
-
28
- ENV PORT 9000
29
- EXPOSE 9000
30
-
31
- ENTRYPOINT ["tini", "--"]
32
-
33
- CMD ["npm", "start"]
@@ -1,5 +0,0 @@
1
- FROM node:alpine-3.18
2
-
3
- ENV foo=bar
4
-
5
- CMD ["sh"]
@@ -1,5 +0,0 @@
1
- FROM node:alpine-3.18@sha256:3482a20c97e401b56ac50ba8920cc7b5b2022bfc6aa7d4e4c231755770cf892f
2
-
3
- ENV foo=bar
4
-
5
- CMD ["sh"]
@@ -1,5 +0,0 @@
1
- FROM node@sha256:b1fdeade9cae98c30bbd8087f26f8da404e6fc48bdd53772017855c1a1d32605
2
-
3
- ENV foo=bar
4
-
5
- CMD ["sh"]
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe PayCLI::Commands::Local::ImageExtractor do
4
- describe '.parse_image_without_sha' do
5
- it 'gives the correct image name and tag on a simple dockerfile' do
6
- expect(
7
- described_class.parse_image_without_sha(fixture_path('simple'))
8
- ).to eq('node:alpine-3.18')
9
- end
10
-
11
- it 'gives the correct image name and tag on a simple dockerfile with no image tag' do
12
- expect(
13
- described_class.parse_image_without_sha(fixture_path('simple_no_tag'))
14
- ).to eq('node')
15
- end
16
-
17
- it 'gives the correct image name and tag on a dockerfile with an image sha and tag' do
18
- expect(
19
- described_class.parse_image_without_sha(fixture_path('with_sha'))
20
- ).to eq('node:alpine-3.18')
21
- end
22
-
23
- it 'gives the correct image name and tag on a dockerfile with an image sha but no tag' do
24
- expect(
25
- described_class.parse_image_without_sha(fixture_path('with_sha_no_tag'))
26
- ).to eq('node')
27
- end
28
-
29
- it 'gives the correct image name and tag on a complex dockerfile with multiple FROM lines' do
30
- expect(
31
- described_class.parse_image_without_sha(fixture_path('complex'))
32
- ).to eq('node:18.18.0-alpine3.18')
33
- end
34
-
35
- it 'gives the first image name and tag on a complex dockerfile with multiple differing FROM lines' do
36
- expect(
37
- described_class.parse_image_without_sha(fixture_path('complex_differing_froms'))
38
- ).to eq('node:18.18.0-alpine3.18')
39
- end
40
-
41
- it 'raises a DockerfileNotFound error if the dockerfile does not exist' do
42
- expect { described_class.parse_image_without_sha(fixture_path('DOES_NOT_EXIST')) }
43
- .to raise_error(PayCLI::Commands::Local::ImageExtractor::DockerfileNotFound)
44
- end
45
-
46
- it 'raises an ImageNotFoundInDockerfile error if the file does not contain a FROM line' do
47
- expect { described_class.parse_image_without_sha(fixture_path('no_from')) }
48
- .to raise_error(PayCLI::Commands::Local::ImageExtractor::ImageNotFoundInDockerfile)
49
- end
50
- end
51
-
52
- def fixture_path(dockerfile_name)
53
- File.join(__dir__, '..', '..', '..', '..', 'fixtures', 'dockerfile_examples', "Dockerfile.#{dockerfile_name}")
54
- end
55
- end
@@ -1,19 +0,0 @@
1
- # rubocop:disable Metrics/BlockLength
2
- RSpec.describe 'pay naming' do
3
- # rubocop:enable Metrics/BlockLength
4
- context 'asg names' do
5
- it 'frontend www weirdness' do
6
- expect(PayCLI::Naming.asg_name(
7
- 'env-name',
8
- 'frontend'
9
- )).to eq('env-name-www-ecs-appserver')
10
- end
11
-
12
- it 'cardid normalness' do
13
- expect(PayCLI::Naming.asg_name(
14
- 'env-name',
15
- 'cardid'
16
- )).to eq('env-name-cardid-ecs-appserver')
17
- end
18
- end
19
- end