@govuk-pay/cli 0.0.55 → 0.0.57

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 (73) 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/src/commands/local/subcommands/user.js +15 -2
  7. package/resources/legacy-ruby-cli/.rspec +0 -1
  8. package/resources/legacy-ruby-cli/config/generate-secrets.yml +0 -9
  9. package/resources/legacy-ruby-cli/config/secrets.yml +0 -682
  10. package/resources/legacy-ruby-cli/config/service_secrets.yml +0 -203
  11. package/resources/legacy-ruby-cli/lib/pay_cli/aws/services.rb +0 -47
  12. package/resources/legacy-ruby-cli/lib/pay_cli/commands/aws.rb +0 -29
  13. package/resources/legacy-ruby-cli/lib/pay_cli/commands/browse.rb +0 -31
  14. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/app_client.rb +0 -216
  15. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/config.rb +0 -142
  16. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/config.yaml +0 -198
  17. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/docker.rb +0 -66
  18. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/all.yaml +0 -847
  19. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/card.yaml +0 -491
  20. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/custom.yaml +0 -71
  21. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/docker-compose.erb +0 -395
  22. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/end-to-end.erb +0 -30
  23. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/java.yaml +0 -456
  24. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/localstack/init-aws.sh +0 -70
  25. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/naxsi/readme.md +0 -1
  26. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/postgres/docker-entrypoint-initdb.d/make_payments_databases.sql +0 -26
  27. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/adminusers.env +0 -49
  28. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/cardid.env +0 -2
  29. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/connector.env +0 -70
  30. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/demo-service.env +0 -10
  31. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/egress/squid.conf +0 -47
  32. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/frontend.env +0 -12
  33. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/java_app.env +0 -1
  34. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ledger.env +0 -7
  35. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/products-ui.env +0 -14
  36. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/products.env +0 -25
  37. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/publicapi.env +0 -13
  38. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/publicauth.env +0 -13
  39. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/selfservice.env +0 -21
  40. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/frontend-proxy.crt +0 -18
  41. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/products-ui-proxy.crt +0 -20
  42. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/publicapi-proxy.crt +0 -18
  43. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/selfservice-proxy.crt +0 -20
  44. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/certs/stubs-proxy.crt +0 -18
  45. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/frontend-proxy.key +0 -28
  46. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/products-ui-proxy.key +0 -28
  47. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/publicapi-proxy.key +0 -28
  48. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/selfservice-proxy.key +0 -28
  49. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/keys/stubs-proxy.key +0 -28
  50. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/ssl/make-selfsigned.sh +0 -2
  51. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/stubs.env +0 -12
  52. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/toolbox.env +0 -5
  53. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/services/webhooks.env +0 -9
  54. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/files/toolbox.yaml +0 -473
  55. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local/image_extractor.rb +0 -20
  56. package/resources/legacy-ruby-cli/lib/pay_cli/commands/local.rb +0 -451
  57. package/resources/legacy-ruby-cli/lib/pay_cli/commands/secrets.rb +0 -114
  58. package/resources/legacy-ruby-cli/lib/pay_cli/commands/tunnel/services.yml +0 -49
  59. package/resources/legacy-ruby-cli/lib/pay_cli/naming.rb +0 -6
  60. package/resources/legacy-ruby-cli/lib/pay_cli/secrets.rb +0 -281
  61. package/resources/legacy-ruby-cli/package-lock.json +0 -6
  62. package/resources/legacy-ruby-cli/rds_access/connect.sh +0 -175
  63. package/resources/legacy-ruby-cli/spec/.rubocop.yml +0 -2
  64. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.complex +0 -34
  65. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.complex_differing_froms +0 -33
  66. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.no_from +0 -3
  67. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.simple +0 -5
  68. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.simple_no_tag +0 -5
  69. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.with_sha +0 -5
  70. package/resources/legacy-ruby-cli/spec/fixtures/dockerfile_examples/Dockerfile.with_sha_no_tag +0 -5
  71. package/resources/legacy-ruby-cli/spec/lib/pay_cli/commands/local/image_extractor_spec.rb +0 -55
  72. package/resources/legacy-ruby-cli/spec/naming_spec.rb +0 -19
  73. package/resources/legacy-ruby-cli/spec/spec_helper.rb +0 -106
@@ -1,203 +0,0 @@
1
- ---
2
- adminusers:
3
- - DB_USER
4
- - DB_PASSWORD
5
- - DB_SUPPORT_USER_READONLY
6
- - DB_SUPPORT_PASSWORD_READONLY
7
- - DB_SUPPORT_USER_READWRITE
8
- - DB_SUPPORT_PASSWORD_READWRITE
9
- - NOTIFY_API_KEY
10
- - NOTIFY_SECRET
11
- - SENTRY_DSN
12
- alb_and_s3_logging_pipeline:
13
- - firehose_hec_token
14
- amazon-managed-prometheus:
15
- - pager_duty_cloudwatch_integration_url_in_hours_only
16
- - pager_duty_cloudwatch_integration_url_24_7_p1
17
- cardid:
18
- - SENTRY_DSN
19
- connector:
20
- - DB_USER
21
- - DB_PASSWORD
22
- - DB_SUPPORT_USER_READONLY
23
- - DB_SUPPORT_PASSWORD_READONLY
24
- - DB_SUPPORT_USER_READWRITE
25
- - DB_SUPPORT_PASSWORD_READWRITE
26
- - NOTIFY_SECRET
27
- - NOTIFY_API_KEY
28
- - GDS_CONNECTOR_STRIPE_AUTH_TOKEN
29
- - GDS_CONNECTOR_STRIPE_AUTH_LIVE_TOKEN
30
- - GDS_CONNECTOR_STRIPE_WEBHOOK_SIGN_SECRET
31
- - GDS_CONNECTOR_STRIPE_WEBHOOK_LIVE_SIGN_SECRET
32
- - GDS_CONNECTOR_STRIPE_CONNECT_APPLICATION_WEBHOOK_LIVE_SIGN_SECRET
33
- - GDS_CONNECTOR_STRIPE_CONNECT_APPLICATION_WEBHOOK_TEST_SIGN_SECRET
34
- - WORLDPAY_APPLE_PAY_PAYMENT_PROCESSING_CERTIFICATE
35
- - WORLDPAY_APPLE_PAY_PAYMENT_PROCESSING_PRIVATE_KEY
36
- - WORLDPAY_APPLE_PAY_PAYMENT_PROCESSING_CERTIFICATE_SECONDARY
37
- - WORLDPAY_APPLE_PAY_PAYMENT_PROCESSING_PRIVATE_KEY_SECONDARY
38
- - SENTRY_DSN
39
- - SANDBOX_AUTH_TOKEN
40
- deploy:
41
- - PAGER_DUTY_CLOUDWATCH_INTEGRATION_URL
42
- - PAGER_DUTY_CLOUDWATCH_INTEGRATION_URL_STAGING
43
- pact-broker:
44
- - master_db_user
45
- - master_db_password
46
- - DB_USER
47
- - DB_PASSWORD
48
- - DB_SUPPORT_USER_READONLY
49
- - DB_SUPPORT_PASSWORD_READONLY
50
- - DB_SUPPORT_USER_READWRITE
51
- - DB_SUPPORT_PASSWORD_READWRITE
52
- pact-broker-auth:
53
- - pact-broker-basic-auth-password
54
- - pact-broker-basic-auth-username
55
- frontend:
56
- - GOOGLE_PAY_MERCHANT_ID
57
- - GOOGLE_PAY_MERCHANT_ID_2
58
- - SESSION_ENCRYPTION_KEY
59
- - SESSION_ENCRYPTION_KEY_2
60
- - AB_TEST_THRESHOLD
61
- - WORLDPAY_APPLE_PAY_MERCHANT_ID
62
- - WORLDPAY_APPLE_PAY_MERCHANT_ID_CERTIFICATE
63
- - WORLDPAY_APPLE_PAY_MERCHANT_ID_CERTIFICATE_KEY
64
- - STRIPE_APPLE_PAY_MERCHANT_ID
65
- - STRIPE_APPLE_PAY_MERCHANT_ID_CERTIFICATE
66
- - STRIPE_APPLE_PAY_MERCHANT_ID_CERTIFICATE_KEY
67
- - STRIPE_TEST_PUBLISHABLE_API_KEY
68
- - STRIPE_LIVE_PUBLISHABLE_API_KEY
69
- - SENTRY_DSN
70
- - SENTRY_CSP_REPORT_URI
71
- network:
72
- - PAGER_DUTY_CLOUDWATCH_ALB_INTEGRATION_URL
73
- publicapi:
74
- # These secrets are used by the app, but having them set to an empty string tries to overwrite working secrets with
75
- # the words 'Password Store'. They are not in pay-low-pass, so for now to stop them being overwritten I'm commenting them out
76
- # - TOKEN_API_HMAC_SECRET
77
- - SENTRY_DSN
78
- publicauth:
79
- - DB_USER
80
- - DB_PASSWORD
81
- - DB_SUPPORT_USER_READONLY
82
- - DB_SUPPORT_PASSWORD_READONLY
83
- - DB_SUPPORT_USER_READWRITE
84
- - DB_SUPPORT_PASSWORD_READWRITE
85
- # These secrets are used by the app, but having them set to an empty string tries to overwrite working secrets with
86
- # the words 'Password Store'. They are not in pay-low-pass, so for now to stop them being overwritten I'm commenting them out
87
- # - TOKEN_DB_BCRYPT_SALT
88
- # - TOKEN_API_HMAC_SECRET
89
- - SENTRY_DSN
90
- product-page:
91
- - pager_duty_cloudwatch_integration_url
92
- products:
93
- - DB_USER
94
- - DB_PASSWORD
95
- - DB_SUPPORT_USER_READONLY
96
- - DB_SUPPORT_PASSWORD_READONLY
97
- - DB_SUPPORT_USER_READWRITE
98
- - DB_SUPPORT_PASSWORD_READWRITE
99
- - SENTRY_DSN
100
- products-ui:
101
- - SESSION_ENCRYPTION_KEY
102
- - SENTRY_DSN
103
- - GOOGLE_RECAPTCHA_SECRET_KEY
104
- - GOOGLE_RECAPTCHA_SITE_KEY
105
- - GOOGLE_RECAPTCHA_ENTERPRISE_PROJECT_ID
106
- selfservice:
107
- - SESSION_ENCRYPTION_KEY
108
- - ZENDESK_API_KEY
109
- - ZENDESK_USER
110
- - STRIPE_ACCOUNT_API_KEY
111
- - SENTRY_DSN
112
- ledger:
113
- - DB_PASSWORD
114
- - DB_USER
115
- - DB_SUPPORT_USER_READONLY
116
- - DB_SUPPORT_PASSWORD_READONLY
117
- - DB_SUPPORT_USER_READWRITE
118
- - DB_SUPPORT_PASSWORD_READWRITE
119
- - SENTRY_DSN
120
- webhooks:
121
- - DB_PASSWORD
122
- - DB_USER
123
- - DB_SUPPORT_USER_READONLY
124
- - DB_SUPPORT_PASSWORD_READONLY
125
- - DB_SUPPORT_USER_READWRITE
126
- - DB_SUPPORT_PASSWORD_READWRITE
127
- - SENTRY_DSN
128
- toolbox:
129
- - AUTH_GITHUB_CLIENT_ID
130
- - AUTH_GITHUB_CLIENT_SECRET
131
- - AUTH_GITHUB_VIEW_ONLY_TEAM_ID
132
- - AUTH_GITHUB_USER_SUPPORT_TEAM_ID
133
- - AUTH_GITHUB_ADMIN_TEAM_ID
134
- - STRIPE_ACCOUNT_API_KEY
135
- - STRIPE_ACCOUNT_TEST_API_KEY
136
- - SENTRY_DSN
137
- - ZENDESK_API_KEY
138
- - ZENDESK_USER
139
- cd-pay-deploy:
140
- - docker-password
141
- - docker-username
142
- - docker-email
143
- - docker-access-token
144
- - end-to-end/docker-password
145
- - end-to-end/docker-username
146
- - end-to-end/docker-email
147
- - end-to-end/docker-access-token
148
- - github-access-token
149
- - grafana-annotations-password
150
- - internal-vulnerability-scan/jira-api-username
151
- - internal-vulnerability-scan/jira-api-token
152
- - internal-vulnerability-scan/jira-base-url
153
- - pact-broker-username
154
- - pact-broker-password
155
- - pact-broker/pact-broker-password
156
- - pact-broker/pact-broker-username
157
- - pay_aws_deploy_account_id
158
- - pay_aws_prod_account_id
159
- - pay_aws_production_account_id
160
- - pay_aws_staging_account_id
161
- - pay_aws_test_account_id
162
- - slack-notification-secret
163
- cd-pay-dev:
164
- - docker-email
165
- - docker-username
166
- - docker-password
167
- - docker-access-token
168
- - github-access-token
169
- - grafana-annotations-password
170
- - pact-broker-username
171
- - pact-broker-password
172
- - pay_aws_deploy_account_id
173
- - pay_aws_staging_account_id
174
- - pay_aws_test_account_id
175
- - pay_aws_dev_account_id
176
- - pay-js-commons/github-access-token
177
- - pr-ci/github-access-token
178
- - slack-notification-secret
179
- - smartpay-expected-password
180
- - smartpay-expected-user
181
- - worldpay-expected-password
182
- - worldpay-expected-user
183
- cd-main:
184
- - docker-email
185
- - docker-username
186
- - docker-password
187
- - docker-access-token
188
- - slack-notification-secret
189
- webhooks_intrusion_monitoring:
190
- - pager_duty_cloudwatch_integration_url
191
- stubs:
192
- - smartpay-expected-password
193
- - smartpay-expected-user
194
- - worldpay-expected-password
195
- - worldpay-expected-user
196
- codebuild:
197
- - docker-username
198
- - docker-access-token
199
- - github-access-token
200
- worldpay_secure_file_gateway:
201
- - private-key
202
- - public-key
203
- - passphrase
@@ -1,47 +0,0 @@
1
- module PayCLI::Aws::Services
2
- def self.wait_for(env, service_name, desired_count)
3
- STDERR.puts "🔵 Waiting until >= #{desired_count} of #{service_name}"
4
-
5
- service = ::Aws::ECS::Client.new
6
- .describe_services(services: ["#{service_name}"], cluster: env)
7
- .services.first
8
- lb = service.load_balancers.first
9
- tg_arn = lb.target_group_arn
10
-
11
- lb_client = ::Aws::ElasticLoadBalancingV2::Client.new
12
-
13
- (1..).each do |attempt|
14
- STDERR.print "\r💤 Waiting (attempt #{attempt})"
15
-
16
- healths = lb_client
17
- .describe_target_health(target_group_arn: tg_arn)
18
- .target_health_descriptions
19
-
20
- healthy_services = healths.select { |h| h.target_health.state == 'healthy' }
21
-
22
- STDERR.print " | Found #{healthy_services.count} healthy #{service_name}"
23
-
24
- break if healthy_services.count >= desired_count
25
- sleep 5
26
- end
27
- end
28
-
29
- def self.scale(env, service_name, desired_count, wait=false)
30
- ecs_client = Aws::ECS::Client.new
31
-
32
- STDERR.puts "Scaling desired tasks of #{service_name} in #{env} to #{desired_count}"
33
- begin
34
- ecs_client
35
- .update_service(
36
- cluster: env,
37
- service: service_name,
38
- desired_count: desired_count
39
- )
40
- STDERR.puts "✅ Scaled #{service_name} in #{env} to #{desired_count}"
41
- rescue ::Aws::ECS::Errors::ClientException
42
- STDERR.puts "❌ Scaled failed for #{service_name} in #{env} to #{desired_count}"
43
- end
44
-
45
- wait_for(env, service_name, desired_count) if wait
46
- end
47
- end
@@ -1,29 +0,0 @@
1
- require 'English'
2
- require 'aws-sdk-route53'
3
-
4
- class PayCLI::Commands::Aws < Thor
5
- desc 'token <account>', 'fetches a token for <account>'
6
- def token(account)
7
- PayCLI::Aws::Tokens.setup!(account)
8
- STDERR.puts "Found token for #{account}, printing to STDOUT"
9
- STDERR.puts "If you aren't already, run this inside $() to set env vars"
10
- %w{AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN}.each do |varname|
11
- puts "export #{varname}=#{ENV[varname]}"
12
- end
13
- STDERR.puts "Outputted token for #{account} successfully"
14
- exit 0
15
- end
16
-
17
- desc 'cmd <account> <*args>',
18
- 'runs args in aws with credentials for <account>'
19
- def cmd(account, *args)
20
- PayCLI::Environment.setup! account
21
-
22
- pid = spawn(
23
- "aws #{args.join(' ')}",
24
- in: STDIN, out: STDOUT, err: STDERR
25
- )
26
- Process.wait pid
27
- exit $CHILD_STATUS.exitstatus
28
- end
29
- end
@@ -1,31 +0,0 @@
1
- require 'English'
2
-
3
- class PayCLI::Commands::Browse < Thor
4
- desc 'manual', 'browses the pay team manual'
5
- def manual
6
- STDERR.puts 'Opening the team manual'
7
- `open https://manual.payments.service.gov.uk`
8
- exit $CHILD_STATUS.exitstatus
9
- end
10
-
11
- desc 'repo', 'browses the pay-infra github repo'
12
- def repo
13
- STDERR.puts 'Opening the pay-infra github repository'
14
- `open https://github.com/alphagov/pay-infra`
15
- exit $CHILD_STATUS.exitstatus
16
- end
17
-
18
- desc 'status', 'browses the pay status page'
19
- def status
20
- STDERR.puts 'Opening the status page'
21
- `open http://payments.statuspage.io`
22
- exit $CHILD_STATUS.exitstatus
23
- end
24
-
25
- desc 'concourse', 'browses the concourse page'
26
- def concourse
27
- STDERR.puts 'Opening the concourse page'
28
- `open https://pay-cd.deploy.payments.service.gov.uk/`
29
- exit $CHILD_STATUS.exitstatus
30
- end
31
- end
@@ -1,216 +0,0 @@
1
- module PayCLI::Commands::Local::AppClient
2
- Config = PayCLI::Commands::Local::Config
3
-
4
- def self.create_account(service_id = nil, email_settings = { email_collection_mode: 'MANDATORY' })
5
- gateway_account_data = {
6
- payment_provider: 'sandbox',
7
- service_name: 'My service',
8
- type: 'test',
9
- service_id: service_id
10
- }
11
-
12
-
13
- patch_email_collection_mode_data = {
14
- op: 'replace',
15
- path: 'email_collection_mode',
16
- value: email_settings[:email_collection_mode]
17
- }
18
-
19
- account = post("#{base_url 'connector'}/v1/api/accounts", gateway_account_data)
20
-
21
- patch("#{base_url 'connector'}/v1/api/accounts/#{account["gateway_account_id"]}", patch_email_collection_mode_data)
22
- patch("#{base_url 'adminusers'}/v1/api/services/#{service_id}", {
23
- op: 'add',
24
- path: 'gateway_account_ids',
25
- value: [ account.fetch('gateway_account_id') ]
26
- })
27
-
28
- return account
29
-
30
- end
31
-
32
- def self.create_token(gateway_account_id)
33
- token_data = {
34
- account_id: gateway_account_id,
35
- description: 'my token',
36
- created_by: 'system generated',
37
- token_type: 'CARD'
38
- }
39
-
40
- post("#{base_url 'publicauth'}/v1/frontend/auth", token_data)
41
- .fetch('token')
42
- end
43
-
44
- def self.create_payment(api_token)
45
- payment_data = {
46
- amount: 1000,
47
- description: 'my payment',
48
- reference: 'my payment reference',
49
- return_url: 'https://www.payments.service.gov.uk'
50
- }
51
-
52
- post_with_token("#{base_url('publicapi')}/v1/payments", payment_data, api_token)
53
- end
54
-
55
- def self.create_user(gateway_account_ids: [], role_name: 'admin')
56
- username = SecureRandom.hex
57
- user_data = {
58
- gateway_account_ids: gateway_account_ids,
59
- email: "#{username}@example.com",
60
- password: 'aaaaaaaaaa',
61
- telephone_number: '01134960000',
62
- role_name: role_name
63
- }
64
-
65
- post("#{base_url 'adminusers'}/v1/api/users", user_data)
66
- .merge(user_data)
67
- end
68
-
69
- def self.create_payment_link(api_token)
70
- product_data = {
71
- pay_api_token: api_token,
72
- name: 'exampleName',
73
- price: 100,
74
- gateway_account_id: 1,
75
- return_url: 'https://test.test/some_reference',
76
- service_name: 'aServiceName',
77
- type: 'ADHOC',
78
- service_name_path: 'aServiceNamePath',
79
- product_name_path: SecureRandom.hex,
80
- reference_enabled: false
81
- }
82
-
83
- post("#{base_url 'products'}/v1/api/products/", product_data)
84
- end
85
-
86
- def self.create_service()
87
- service_data = {
88
- service_name: {en: 'My service', cy: 'Welsh name for My service'}
89
- }
90
-
91
- post("#{base_url 'adminusers'}/v1/api/services", service_data)
92
- end
93
-
94
- def self.post(url, data, custom_headers={}, exit_on_error = true)
95
- headers = {content_type: :json, accept: :json}.merge(custom_headers)
96
- begin
97
- [url]
98
- .map {|url| RestClient.post(url, data.to_json, headers).body}
99
- .map {|response| JSON.parse(response)}
100
- .first
101
- rescue => e
102
- begin
103
- STDERR.puts "😬 Calling #{url} got error #{e.response}... sssorry about that"
104
- rescue
105
- STDERR.puts "🤔 Hmm, seems we cannot connect to #{url}. Here is what's up at the moment:"
106
- report_state Config::all, false
107
- end
108
- exit 1 if exit_on_error
109
- end
110
- end
111
-
112
- def self.patch(url, data, custom_headers={}, exit_on_error = true)
113
- headers = {content_type: :json, accept: :json}.merge(custom_headers)
114
- begin
115
- RestClient.patch(url, data.to_json, headers)
116
- rescue => e
117
- begin
118
- STDERR.puts "😬 Calling #{url} got error #{e.response}... sssorry about that"
119
- rescue
120
- STDERR.puts "🤔 Hmm, seems we cannot connect to #{url}. Here is what's up at the moment:"
121
- report_state Config::all, false
122
- end
123
- exit 1 if exit_on_error
124
- end
125
- end
126
-
127
- def self.wait_for_apps(apps)
128
- timeout = 0
129
- app_states = list_app_states apps
130
-
131
- until all_up_states?(app_states) || timeout > 60 do
132
- STDERR.print [
133
- '🙄 Waiting for',
134
- app_states
135
- .reject {|app_state| app_state[:healthy]}
136
- .map {|app_state| ' ' + app_state[:app_name]}.join(','),
137
- + " \r"
138
- ].join('')
139
-
140
- $stdout.flush
141
- timeout += 1
142
- app_states = list_app_states apps
143
- sleep 1
144
- end
145
- STDERR.puts "\n\n"
146
- end
147
-
148
- def self.report_state(apps, summarise = true)
149
- app_states = list_app_states apps
150
- STDERR.puts app_states.map {|app_state| "#{app_state[:healthy] ? '✅' : '🔴'} #{app_state[:app_name]}"}
151
- if all_up_states?(app_states)
152
- STDERR.puts "\n🎉 Ready to roll\n\n"
153
- else
154
- STDERR.puts "\n💥 Hmmm, something not quite right"
155
- STDERR.puts "ℹ️ It may have just timed out waiting so you could just try again"
156
- STDERR.puts "ℹ️ Make sure you have the latest pay-infra"
157
- STDERR.puts "ℹ️ docker logs <app> should tell you if an app failed to launch"
158
- STDERR.puts "ℹ️ docker inspect <app> may give some clues under State"
159
- STDERR.puts "ℹ️ pay local nuke is drastic but may help"
160
- STDERR.puts "ℹ️ docker system prune --all is also drastic but may get things working"
161
- STDERR.puts "ℹ️ You may need to increase the memory in Docker Desktop settings\n\n"
162
-
163
-
164
- end if summarise
165
- end
166
-
167
- def self.get(url)
168
- RestClient::Request.execute(
169
- :url => url,
170
- :method => :get,
171
- :headers => {accept: :json},
172
- :verify_ssl => false
173
- )
174
- end
175
-
176
- def self.post_with_token(url, data, token, exit_on_error = true)
177
- post(url, data, {authorization: "Bearer #{token}"}, exit_on_error)
178
- end
179
-
180
- def self.is_app_up?(app_name)
181
- return true unless Config::has_healthcheck(app_name)
182
- begin
183
- get("#{base_url app_name}/healthcheck").code.equal? 200
184
- rescue
185
- false
186
- end
187
- end
188
-
189
- def self.is_proxy_up?(app_name)
190
- begin
191
- get("#{base_proxy_url app_name}/healthcheck").code.equal? 200
192
- rescue
193
- false
194
- end
195
- end
196
-
197
- def self.all_up?(apps)
198
- all_up_states? list_app_states apps
199
- end
200
-
201
- def self.all_up_states?(app_states)
202
- app_states.reject {|app| app[:healthy]}.length.equal? 0
203
- end
204
-
205
- def self.list_app_states(apps)
206
- apps.map {|app| {app_name: app[:name], healthy: is_app_up?(app[:name])}}
207
- end
208
-
209
- def self.base_url(app_name)
210
- "http://localhost:#{Config::port app_name}"
211
- end
212
-
213
- def self.base_proxy_url(app_name)
214
- "https://localhost:#{Config::proxy_port app_name}"
215
- end
216
- end
@@ -1,142 +0,0 @@
1
- module PayCLI::Commands::Local::Config
2
- @apps = ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file("#{File.dirname(__FILE__)}/config.yaml")).values
3
-
4
- def self.all
5
- @apps
6
- end
7
-
8
- def self.boring
9
- @apps.select {|app| app[:experimental] != true }
10
- end
11
-
12
- def self.port(app_name)
13
- self.get_config app_name, :port
14
- end
15
-
16
- def self.admin_port(app_name)
17
- self.get_config app_name, :admin_port
18
- end
19
-
20
- def self.get_config(app_name, field)
21
- @apps.select {|app| app[:name] == app_name}.map {|app| app[field]}.first
22
- end
23
-
24
- def self.has_healthcheck(app_name)
25
- @apps.select {|app| app[:name] == app_name}.map {|app| app[:healthcheck]}.first
26
- end
27
-
28
- def self.uses_redis(app_name)
29
- @apps.select {|app| app[:name] == app_name}.any? {|app| app.fetch(:uses_redis, false)}
30
- end
31
-
32
- def self.proxy_port(app_name)
33
- @apps.select {|app| app[:name] == app_name}.map {|app| app[:proxy_port]}.first
34
- end
35
-
36
- def self.can_use_egress_proxy(app_name)
37
- @apps.select {|app| app[:name] == app_name}.first.fetch(:can_use_egress_proxy, false)
38
- end
39
-
40
- def self.cluster( cluster, apps)
41
- apps.select {|app| app[:clusters].include?(cluster)}
42
- end
43
-
44
- def self.local(local_app_names, apps)
45
- apps.select {|app| local_app_names.include? app[:name]}
46
- end
47
-
48
- def self.remote(local_app_names, apps)
49
- apps.select {|app| !local_app_names.include? app[:name]}
50
- end
51
-
52
- def self.filter(app_names, apps)
53
- apps.select {|app| app_names.include? app[:name]}
54
- end
55
-
56
- def self.node(apps)
57
- apps.select { |app| app[:type] == 'node'}
58
- end
59
-
60
- def self.java(apps)
61
- apps.select { |app| app[:type] == 'java'}
62
- end
63
-
64
- def self.has_db(apps)
65
- apps.select {|app| app[:db]}
66
- end
67
-
68
- def self.has_proxy(apps)
69
- apps.select {|app| app[:proxy]}
70
- end
71
-
72
- def self.has_queue(apps)
73
- apps.select {|app| app[:queues]}
74
- end
75
-
76
- def self.has_sns_topics(apps)
77
- apps.select { |app| app[:sns_topics] }
78
- end
79
-
80
- def self.uses_localstack(apps)
81
- has_queue(apps).any? || has_sns_topics(apps).any?
82
- end
83
-
84
- def self.db_configs(apps)
85
- apps.map {|app| {
86
- name: app[:name] + '_db',
87
- port: app[:db_port]
88
- }}
89
- end
90
-
91
- def self.app_by_name(name)
92
- @apps.select do |app|
93
- app[:name] == name
94
- end
95
- end
96
-
97
- def self.proxy_configs(apps)
98
- apps.map {|app|
99
- if app[:naxsi]
100
- md5 = copy_naxsi_rules(app).hexdigest
101
- end
102
- {
103
- name: app[:name] + '-proxy',
104
- port: app[:proxy_port],
105
- proxy_port: app[:port],
106
- proxy_host: app[:name],
107
- naxsi_md5: md5
108
- }
109
- }
110
- end
111
-
112
- def self.copy_naxsi_rules(app)
113
- naxsi_rule_dest = File.join(
114
- File.dirname(__FILE__),
115
- "files/naxsi/#{app[:name]}.rules")
116
-
117
- naxsi_rule_source = File.join(
118
- File.dirname(__FILE__),
119
- '..', '..', '..', '..', '..',
120
- 'provisioning',
121
- 'terraform',
122
- 'modules',
123
- 'pay_microservices_v2',
124
- app[:name],
125
- 'files',
126
- "#{app[:name]}.naxsi")
127
-
128
- FileUtils.copy(naxsi_rule_source, naxsi_rule_dest)
129
-
130
- Digest::MD5.file naxsi_rule_dest
131
- end
132
-
133
- def self.write_end_to_end_config(binding)
134
- erb = ERB.new(File.read(File.join(
135
- File.dirname(__FILE__),
136
- 'files',
137
- 'end-to-end.erb')), trim_mode: '-')
138
-
139
- erb.result(binding)
140
- end
141
-
142
- end