dvla-application_helper 5.1.5
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.
- checksums.yaml +7 -0
- data/.drone.yml +481 -0
- data/.env.template +4 -0
- data/.rspec +3 -0
- data/.rubocop.yml +21 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +674 -0
- data/Rakefile +31 -0
- data/config/settings/drone-dev.yml +41 -0
- data/config/settings/drone-ext.yml +35 -0
- data/config/settings/drone-link.yml +35 -0
- data/config/settings/drone-perf.yml +35 -0
- data/config/settings/local-dev.yml +40 -0
- data/config/settings/local-ext.yml +35 -0
- data/config/settings/local-link.yml +35 -0
- data/config/settings/local-perf.yml +35 -0
- data/config/settings.yml +29 -0
- data/config/yarp.yml +6 -0
- data/functional-tests/Rakefile +74 -0
- data/functional-tests/chutney.yml +110 -0
- data/functional-tests/features/codl.feature +170 -0
- data/functional-tests/features/codl_image_review_states.feature +140 -0
- data/functional-tests/features/csudl.feature +54 -0
- data/functional-tests/features/csudl_image_review_states.feature +20 -0
- data/functional-tests/features/step_definitions/app_domain_steps.rb +213 -0
- data/functional-tests/features/step_definitions/application_creation_steps.rb +115 -0
- data/functional-tests/features/step_definitions/image_steps.rb +144 -0
- data/functional-tests/features/step_definitions/state_machine_steps.rb +43 -0
- data/functional-tests/features/support/data/artefacts.rb +27 -0
- data/functional-tests/features/support/data/image_helpers.rb +20 -0
- data/functional-tests/features/support/data/schema_helpers.rb +3 -0
- data/functional-tests/features/support/data/string_manipulation.rb +9 -0
- data/functional-tests/features/support/env.rb +25 -0
- data/functional-tests/features/support/hooks.rb +56 -0
- data/functional-tests/features/support/yarp_integration/yarp_helpers.rb +23 -0
- data/functional-tests/features/uodl_image_review_states.feature +244 -0
- data/functional-tests/features/uodl_non_processable.feature +441 -0
- data/functional-tests/features/uodl_processable.feature +416 -0
- data/lib/dvla/application_helper/builders/V1/application_builder.rb +298 -0
- data/lib/dvla/application_helper/builders/V1/codl_application_builder.rb +205 -0
- data/lib/dvla/application_helper/builders/V1/csudl_application_builder.rb +329 -0
- data/lib/dvla/application_helper/builders/V2/base_uodl_v2_application_builder.rb +357 -0
- data/lib/dvla/application_helper/builders/V2/cop_v2_application_builder.rb +59 -0
- data/lib/dvla/application_helper/builders/V2/dup_v2_application_builder.rb +84 -0
- data/lib/dvla/application_helper/builders/V2/exc_v2_application_builder.rb +55 -0
- data/lib/dvla/application_helper/builders/V2/rep_v2_application_builder.rb +84 -0
- data/lib/dvla/application_helper/builders/V2/tyr_v2_application_builder.rb +62 -0
- data/lib/dvla/application_helper/builders/V2/uodl_v2_application_builder.rb +278 -0
- data/lib/dvla/application_helper/builders/V3/base_uodl_v3_application_builder.rb +342 -0
- data/lib/dvla/application_helper/builders/V3/cop_v3_application_builder.rb +56 -0
- data/lib/dvla/application_helper/builders/V3/dup_v3_application_builder.rb +78 -0
- data/lib/dvla/application_helper/builders/V3/exc_v3_application_builder.rb +56 -0
- data/lib/dvla/application_helper/builders/V3/rep_v3_application_builder.rb +81 -0
- data/lib/dvla/application_helper/builders/V3/tyr_v3_application_builder.rb +59 -0
- data/lib/dvla/application_helper/builders/dup_rep_builder_mixin.rb +71 -0
- data/lib/dvla/application_helper/builders/photo_builder_mixin.rb +49 -0
- data/lib/dvla/application_helper/builders/photo_signature_builder_mixin.rb +68 -0
- data/lib/dvla/application_helper/configuration.rb +37 -0
- data/lib/dvla/application_helper/constants.rb +21 -0
- data/lib/dvla/application_helper/enums/review_state.rb +30 -0
- data/lib/dvla/application_helper/enums/unable_to_prove_licence_possession_reasons.rb +8 -0
- data/lib/dvla/application_helper/factories/address.rb +21 -0
- data/lib/dvla/application_helper/factories/application_details.rb +353 -0
- data/lib/dvla/application_helper/factories/casework.rb +7 -0
- data/lib/dvla/application_helper/factories/csudl_photo_signature_image.rb +156 -0
- data/lib/dvla/application_helper/factories/csudl_photo_signature_images.rb +85 -0
- data/lib/dvla/application_helper/factories/organ_donor.rb +32 -0
- data/lib/dvla/application_helper/factories/person.rb +73 -0
- data/lib/dvla/application_helper/factories/photo_image.rb +147 -0
- data/lib/dvla/application_helper/factories/photo_images.rb +183 -0
- data/lib/dvla/application_helper/factories/photo_signature_image.rb +158 -0
- data/lib/dvla/application_helper/factories/photo_signature_images.rb +64 -0
- data/lib/dvla/application_helper/fixtures/photo/comparison_image.jpeg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/passport_image.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/photocard_back.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/photocard_front.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/rejected_user_uploaded_image.jpeg +0 -0
- data/lib/dvla/application_helper/fixtures/photo/user_uploaded_image.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/signature/csudl_signature_image.tiff +0 -0
- data/lib/dvla/application_helper/fixtures/signature/passport_image.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/signature/rejected_user_uploaded_image.jpg +0 -0
- data/lib/dvla/application_helper/fixtures/signature/user_uploaded_image.jpg +0 -0
- data/lib/dvla/application_helper/processors/application_status.rb +45 -0
- data/lib/dvla/application_helper/processors/application_task.rb +301 -0
- data/lib/dvla/application_helper/services/application_diary.rb +123 -0
- data/lib/dvla/application_helper/services/application_domain.rb +239 -0
- data/lib/dvla/application_helper/services/application_process_engine.rb +120 -0
- data/lib/dvla/application_helper/services/check_aws_credentials.rb +24 -0
- data/lib/dvla/application_helper/services/driving_licence_channel_api.rb +67 -0
- data/lib/dvla/application_helper/services/image_service.rb +116 -0
- data/lib/dvla/application_helper/services/image_utility.rb +82 -0
- data/lib/dvla/application_helper/services/state_machine_helpers.rb +146 -0
- data/lib/dvla/application_helper/version.rb +5 -0
- data/lib/dvla/application_helper.rb +92 -0
- data/renovate.json +4 -0
- data/scripts/application-login.sh +56 -0
- data/scripts/drone-aws-login.sh +18 -0
- data/scripts/seed_application.rb +268 -0
- data/sonar-project.properties +4 -0
- metadata +343 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
module DVLA
|
2
|
+
module Application
|
3
|
+
module ImageService
|
4
|
+
def self.image_service_headers
|
5
|
+
{
|
6
|
+
'x-correlation-id': RequestHeaders::X_CORRELATION_ID,
|
7
|
+
'dvla-resource': RequestHeaders::DVLA_RESOURCE,
|
8
|
+
'dvla-origin-resource': RequestHeaders::DVLA_ORIGIN_RESOURCE,
|
9
|
+
'dvla-user': RequestHeaders::DVLA_USER,
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get_image_url_body(image_id:, image_origin:, image_type:)
|
14
|
+
{
|
15
|
+
imageId: image_id,
|
16
|
+
imageOriginType: image_origin,
|
17
|
+
imageType: image_type,
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.image_base64_body(image_id:, image_type:, image_transformation_type:, image_origin: 'User')
|
22
|
+
{
|
23
|
+
imageId: image_id,
|
24
|
+
imageOriginType: image_origin,
|
25
|
+
imageType: image_type,
|
26
|
+
imageTransformationType: image_transformation_type,
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.image_retention_body(retention, image_id, origin_type = 'User')
|
31
|
+
{
|
32
|
+
imageId: image_id,
|
33
|
+
imageOriginType: origin_type,
|
34
|
+
imageType: 'Photo',
|
35
|
+
retainForApplication: retention,
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.put_user_uploaded_image_in_service(image_id:, image_type: 'Photo')
|
40
|
+
image_folder_name = image_type.downcase
|
41
|
+
put_local_image_in_service(image_id:, image_origin: 'User', image_path: "../fixtures/#{image_folder_name}/user_uploaded_image.jpg", log_description: "User #{image_type}", image_type:)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.put_comparison_image_in_service(image_id:, image_type: 'Photo')
|
45
|
+
image_folder_name = image_type.downcase
|
46
|
+
put_local_image_in_service(image_id:, image_origin: 'User', image_path: "../fixtures/#{image_folder_name}/comparison_image.jpeg", log_description: "Comparison #{image_type}", image_type:)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.put_passport_image_in_service(image_id:, image_type: 'Photo')
|
50
|
+
image_folder_name = image_type.downcase
|
51
|
+
put_local_image_in_service(image_id:, image_origin: 'Passport', image_path: "../fixtures/#{image_folder_name}/passport_image.jpg", log_description: "Passport #{image_type}", image_type:)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.put_passport_comparison_image_in_service(image_id:, image_type: 'Photo')
|
55
|
+
image_folder_name = image_type.downcase
|
56
|
+
put_local_image_in_service(image_id:, image_origin: 'Passport', image_path: "../fixtures/#{image_folder_name}/comparison_image.jpeg", log_description: "Passport Comparison #{image_type}", image_type:)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.put_home_office_comparison_image_in_service(image_id:, image_type: 'Photo')
|
60
|
+
image_folder_name = image_type.downcase
|
61
|
+
put_local_image_in_service(image_id:, image_origin: 'HomeOffice', image_path: "../fixtures/#{image_folder_name}/comparison_image.jpeg", log_description: "Home Office Comparison #{image_type}", image_type:)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.put_local_image_in_service(image_id:, image_origin:, image_path:, log_description:, image_type: 'Photo')
|
65
|
+
if image_exists?(image_id:, image_origin:, image_type:)
|
66
|
+
DVLA::Application.logger.info("#{log_description} image already exists in image service, no need to create. imageID = #{image_id.green}")
|
67
|
+
else
|
68
|
+
image_upload_url = JSON.parse(image_service_http_post(endpoint: 'get-image-upload-url', body: get_image_url_body(image_id:, image_origin:, image_type:)))['url']
|
69
|
+
image_file = File.open(File.expand_path(image_path, File.dirname(__FILE__)))
|
70
|
+
|
71
|
+
DVLA::Application.logger.info("Uploading #{log_description} photo to image service. imageID = #{image_id.green}")
|
72
|
+
HTTPX.put(image_upload_url, body: File.open(image_file))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.image_service_http_post(endpoint:, body:)
|
77
|
+
image_service_url = "#{Settings.application_helper.services.image_service.base_url}v1/#{endpoint}"
|
78
|
+
headers = image_service_headers.merge(AWS.sign_the_request(image_service_url, body))
|
79
|
+
HTTPX.post(image_service_url, json: body, headers:)
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.image_exists?(image_id:, image_origin:, image_type:)
|
83
|
+
images_service_does_image_exist_url = "#{Settings.application_helper.services.image_service.base_url}v1/get-image-exists"
|
84
|
+
headers = image_service_headers.merge(AWS.sign_the_request(images_service_does_image_exist_url, get_image_exists_body(image_id:, image_origin:, image_type:)))
|
85
|
+
response = HTTPX.post(images_service_does_image_exist_url, json: get_image_exists_body(image_id:, image_origin:, image_type:), headers:)
|
86
|
+
JSON.parse(response.body).to_h['imageExists']
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.image_service_get_base64(image_id:, image_type:, image_transformation_type:, image_origin: 'User')
|
90
|
+
image_service_base64_url = "#{Settings.application_helper.services.image_service.base_url}v1/get-image-as-base64"
|
91
|
+
request_body = image_base64_body(image_id:, image_origin:, image_type:, image_transformation_type:)
|
92
|
+
headers = image_service_headers.merge(AWS.sign_the_request(image_service_base64_url, request_body))
|
93
|
+
HTTPX.post(image_service_base64_url, json: request_body, headers:)
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.get_base64_image_data(image_id:, image_origin:, image_type: 'Photo', image_transformation_type: 'D90')
|
97
|
+
BlockRepeater::Repeater.new do
|
98
|
+
DVLA::Application.logger.info("Checking that imageID = #{image_id.green} has seeded successfully")
|
99
|
+
@response = JSON.parse(image_service_get_base64(image_id:, image_origin:, image_type:, image_transformation_type:))['base64String']
|
100
|
+
end.until do
|
101
|
+
@response != nil
|
102
|
+
end.repeat(times: 10, delay: 3)
|
103
|
+
|
104
|
+
if @response == false
|
105
|
+
raise StandardError "ImageId: #{image_id.green} not found in image service S3 bucket"
|
106
|
+
end
|
107
|
+
|
108
|
+
@response
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.get_image_exists_body(image_id:, image_origin:, image_type:)
|
112
|
+
get_image_url_body(image_id:, image_origin:, image_type:)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module DVLA
|
2
|
+
module Application
|
3
|
+
module ImageUtility
|
4
|
+
def self.image_utility_headers(x_image_use: RequestHeaders::X_IMAGE_USE)
|
5
|
+
{
|
6
|
+
'content-type': RequestHeaders::CONTENT_TYPE,
|
7
|
+
'dvla-resource': RequestHeaders::DVLA_RESOURCE,
|
8
|
+
'dvla-origin-resource': RequestHeaders::DVLA_ORIGIN_RESOURCE,
|
9
|
+
'x-image-use': x_image_use,
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.generate_x_image_use(image_purpose: 'Comparison', image_type: 'Photo')
|
14
|
+
if image_type == 'Signature'
|
15
|
+
RequestHeaders::X_IMAGE_USE_APP_SIGNATURE
|
16
|
+
elsif image_purpose == 'Application'
|
17
|
+
RequestHeaders::X_IMAGE_USE_APP_PHOTO
|
18
|
+
elsif image_purpose == 'Comparison'
|
19
|
+
RequestHeaders::X_IMAGE_USE_DRIVER_PHOTO
|
20
|
+
elsif image_purpose == 'Photocard front'
|
21
|
+
RequestHeaders::X_IMAGE_USE_PHOTOCARD_FRONT
|
22
|
+
elsif image_purpose == 'Photocard back'
|
23
|
+
RequestHeaders::X_IMAGE_USE_PHOTOCARD_BACK
|
24
|
+
else
|
25
|
+
raise StandardError, 'The image_purpose and image_type are not valid'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.store_image_in_image_utility(image_id:, image_purpose: 'Comparison', image_origin: 'User', image_type: 'Photo', image_transformation_type: 'D90')
|
30
|
+
x_image_use = generate_x_image_use(image_purpose:, image_type:)
|
31
|
+
|
32
|
+
if image_exists_in_utility?(image_id:, x_image_use:)
|
33
|
+
DVLA::Application.logger.info("Image already exists in image utility, no need to create. imageID = #{image_id.green}")
|
34
|
+
else
|
35
|
+
base64_image_data = DVLA::Application::ImageService.get_base64_image_data(image_id:, image_origin:, image_type:, image_transformation_type:)
|
36
|
+
body = {
|
37
|
+
type: 'image/jpeg',
|
38
|
+
data: base64_image_data,
|
39
|
+
imageId: image_id,
|
40
|
+
}
|
41
|
+
|
42
|
+
DVLA::Application.logger.info("Uploading #{image_origin} #{image_purpose} image to image utility")
|
43
|
+
image_utility_http_post(endpoint: 'image/store', body:, x_image_use:)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.store_local_image_in_image_utility(image_id:, image_path:, image_purpose: 'Comparison', image_origin: 'User', image_type: 'Photo', image_file_type: 'image/jpeg')
|
48
|
+
x_image_use = generate_x_image_use(image_purpose:, image_type:)
|
49
|
+
|
50
|
+
if image_exists_in_utility?(image_id:, x_image_use:)
|
51
|
+
DVLA::Application.logger.info("#{image_origin.blue} #{image_type.blue} | #{image_purpose.blue} Image already exists in image utility, no need to create. imageID = #{image_id.green}")
|
52
|
+
else
|
53
|
+
image_file = File.open(File.expand_path(image_path, File.dirname(__FILE__)))
|
54
|
+
base64_image_data = Base64.strict_encode64(image_file.read)
|
55
|
+
image_file.close
|
56
|
+
body = {
|
57
|
+
type: image_file_type,
|
58
|
+
data: base64_image_data,
|
59
|
+
imageId: image_id,
|
60
|
+
}
|
61
|
+
|
62
|
+
DVLA::Application.logger.info("Uploading #{image_origin.blue} #{image_type.blue} | #{image_purpose.blue} local image to image utility")
|
63
|
+
response = image_utility_http_post(endpoint: 'image/store', body:, x_image_use:)
|
64
|
+
|
65
|
+
raise StandardError, "Failed to store image in image utility, status: #{response.status}" unless response.status == 201
|
66
|
+
|
67
|
+
DVLA::Application.logger.info("Image stored in image utility, imageID = #{image_id.green}") if response.status == 201
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.image_exists_in_utility?(image_id:, x_image_use:)
|
72
|
+
image_utility_http_post(endpoint: 'image/exist', body: { imageId: image_id }, x_image_use:).status == 204
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.image_utility_http_post(endpoint:, body:, x_image_use: RequestHeaders::X_IMAGE_USE_DRIVER_PHOTO)
|
76
|
+
image_utility_url = "#{Settings.application_helper.services.image_utility.base_url}v1/#{endpoint}"
|
77
|
+
headers = image_utility_headers(x_image_use:).merge(AWS.sign_the_request(image_utility_url, body))
|
78
|
+
HTTPX.post(image_utility_url, json: body.as_json, headers:)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module DVLA
|
2
|
+
module Application
|
3
|
+
require 'aws-sdk-states'
|
4
|
+
require 'block_repeater/repeater'
|
5
|
+
|
6
|
+
class StateMachine
|
7
|
+
attr_accessor :stage, :account_id, :state_machine_arn, :state_machine_name
|
8
|
+
|
9
|
+
# @param *account_id [String] AWS AccountId, optional, will default to dev if not set in env
|
10
|
+
# @param *state_machine_name [String] eg 'application-process-engine-fulfilment', required
|
11
|
+
# @param *stage [String] deployed stage name eg 'dev', optional, will default to dev if not set in env
|
12
|
+
def initialize(state_machine_name:, stage: nil, account_id: nil)
|
13
|
+
@stage = stage || ENV.fetch('DRIVERS_APPLICATION_PROCESS_ENGINE_STAGE_NAME', Settings.application_helper.services.state_machine.stage)
|
14
|
+
@account_id = account_id || ENV.fetch('STATE_MACHINE_ACCOUNT_ID', Settings.application_helper.services.state_machine.account_id)
|
15
|
+
@state_machine_name = state_machine_name
|
16
|
+
@state_machine_arn = %(arn:aws:states:eu-west-2:#{@account_id}:stateMachine:#{@stage}-#{@state_machine_name})
|
17
|
+
@client = Aws::States::Client.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def list_activities
|
21
|
+
@client.list_activities(state_machine_arn: @state_machine_arn)
|
22
|
+
end
|
23
|
+
|
24
|
+
def list_executions
|
25
|
+
@client.list_executions(state_machine_arn: @state_machine_arn).to_hash[:executions]
|
26
|
+
end
|
27
|
+
|
28
|
+
def assert_execution_exists(execution_arn:)
|
29
|
+
begin
|
30
|
+
@client.describe_execution(execution_arn: execution_arn)
|
31
|
+
true
|
32
|
+
rescue Aws::States::Errors::ExecutionDoesNotExist
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def start_execution(execution_name:, input:)
|
38
|
+
@client.start_execution(state_machine_arn: @state_machine_arn, name: execution_name, input: input.to_json)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param *application_id [String](UUID), required
|
42
|
+
# @param *correlation_id [String](UUID), optional
|
43
|
+
# @param *session_id [String](UUID), optional
|
44
|
+
# @return *input data [Hash], will include additional_input if passed in
|
45
|
+
def generate_start_execution_input_data(application_id:, additional_input: nil, correlation_id: SecureRandom.uuid, session_id: SecureRandom.uuid)
|
46
|
+
base_input = { applicationId: application_id,
|
47
|
+
correlationId: correlation_id,
|
48
|
+
sessionId: session_id }
|
49
|
+
|
50
|
+
additional_input.nil? ? base_input : base_input.merge(additional_input)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class StateMachineExecution
|
55
|
+
attr_accessor :account_id, :calling_service, :execution_arn, :execution_uuid, :iteration, :stage, :state_machine_name
|
56
|
+
|
57
|
+
# @param *execution_arn [String], optional, can be calculated and set using method calculate_execution_arn
|
58
|
+
def initialize(execution_arn: nil)
|
59
|
+
@account_id = ENV.fetch('STATE_MACHINE_ACCOUNT_ID', Settings.application_helper.services.state_machine.account_id)
|
60
|
+
@calling_service = nil
|
61
|
+
@client = Aws::States::Client.new
|
62
|
+
@execution_arn = execution_arn
|
63
|
+
@execution_uuid = nil
|
64
|
+
@iteration = nil
|
65
|
+
@stage = ENV.fetch('STATE_MACHINE_STAGE_NAME', Settings.application_helper.services.state_machine.stage)
|
66
|
+
@state_machine_name = nil
|
67
|
+
end
|
68
|
+
|
69
|
+
def describe_execution
|
70
|
+
DVLA::Application.logger.info("Calling Describe Execution for execution: #{@execution_arn}".blue)
|
71
|
+
make_state_machine_call(client_method: 'describe_execution')
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_history
|
75
|
+
DVLA::Application.logger.info("Calling Get History for execution: #{@execution_arn}".blue)
|
76
|
+
make_state_machine_call(client_method: 'get_execution_history')
|
77
|
+
end
|
78
|
+
|
79
|
+
def stop_execution
|
80
|
+
DVLA::Application.logger.info("Calling Stop Execution on execution: #{@execution_arn}".blue)
|
81
|
+
make_state_machine_call(client_method: 'stop_execution')
|
82
|
+
end
|
83
|
+
|
84
|
+
# @param *step_name [String], relates to AWS step function step name
|
85
|
+
# @param *event_type_name [String], relates to AWS step event type
|
86
|
+
# returns found object or nil
|
87
|
+
def find_event_details(step_name:, event_type_name:)
|
88
|
+
DVLA::Application.logger.info("Attempting to find: #{event_type_name}, for step: #{step_name}".blue)
|
89
|
+
# iterate through each event first
|
90
|
+
get_history.data.events.each do |event|
|
91
|
+
target_event = event.as_json[event_type_name]
|
92
|
+
unless target_event.nil?
|
93
|
+
if target_event['name'] == step_name
|
94
|
+
DVLA::Application.logger.info('Event Found'.green)
|
95
|
+
return target_event
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
DVLA::Application.logger.info("No event found for: #{event_type_name}, for step: #{step_name}".blue)
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
|
103
|
+
def wait_for_execution_completion(repeat_times: 30, repeat_delay: 2, status: 'RUNNING')
|
104
|
+
BlockRepeater::Repeater.new do
|
105
|
+
begin
|
106
|
+
@client.describe_execution(execution_arn: @execution_arn).to_hash
|
107
|
+
rescue Aws::States::Errors::ServiceError => e
|
108
|
+
DVLA::Application.logger.info "AWS Service error #{e.message}"
|
109
|
+
end
|
110
|
+
end.until do |result|
|
111
|
+
result[:status] != status
|
112
|
+
end.repeat(times: repeat_times, delay: repeat_delay)
|
113
|
+
end
|
114
|
+
|
115
|
+
# @param *execution_arn [String], will be set once this method is called
|
116
|
+
# @param *execution_uuid [String](UUID), required, typically the application_id or a generated uuid
|
117
|
+
# @param *state_machine_name [String], required, eg 'application-process-engine-fulfilment'
|
118
|
+
# @param *calling_service [String], optional, eg 'application-process-engine'
|
119
|
+
# @param *iteration [Integer], optional, defaults to 1
|
120
|
+
def generate_execution_arn(execution_uuid:, state_machine_name:, calling_service: nil, iteration: 1)
|
121
|
+
@calling_service = calling_service
|
122
|
+
@execution_uuid = execution_uuid
|
123
|
+
@state_machine_name = state_machine_name
|
124
|
+
@iteration = iteration
|
125
|
+
@execution_arn = if @calling_service.nil?
|
126
|
+
%(arn:aws:states:eu-west-2:#{@account_id}:execution:#{@stage}-#{@state_machine_name}:#{@execution_uuid})
|
127
|
+
else
|
128
|
+
%(arn:aws:states:eu-west-2:#{@account_id}:execution:#{@stage}-#{@state_machine_name}:#{@calling_service}-#{@execution_uuid}-#{@iteration})
|
129
|
+
end
|
130
|
+
self
|
131
|
+
end
|
132
|
+
|
133
|
+
def make_state_machine_call(client_method:)
|
134
|
+
DVLA::Application.logger.info("Invoking state machine method: #{client_method}")
|
135
|
+
DVLA::Application.logger.info("AWS execution_arn: #{@execution_arn}")
|
136
|
+
begin
|
137
|
+
@client.method(client_method).call(execution_arn: @execution_arn)
|
138
|
+
rescue Aws::States::Errors::ServiceError => e
|
139
|
+
e
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'block_repeater'
|
2
|
+
require 'config'
|
3
|
+
require 'dvla-application-diary-openapi-client'
|
4
|
+
require 'dvla-application-domain-openapi-client'
|
5
|
+
require 'dvla-application-process-engine-openapi-client'
|
6
|
+
require 'dvla/application_helper/configuration'
|
7
|
+
require 'rspec/expectations'
|
8
|
+
require 'dvla/herodotus'
|
9
|
+
require 'dvla/aws'
|
10
|
+
require 'dvla-driving-licence-channel-api-openapi-client'
|
11
|
+
require 'dvla/poirot'
|
12
|
+
require 'faker'
|
13
|
+
require 'faker_maker'
|
14
|
+
require 'httpx'
|
15
|
+
|
16
|
+
Faker::Config.locale = 'en-GB'
|
17
|
+
|
18
|
+
module DVLA
|
19
|
+
module Application
|
20
|
+
path = File.expand_path(__dir__)
|
21
|
+
Dir.glob("#{path}/application_helper/**/*.rb").each { |f| require_relative f }
|
22
|
+
|
23
|
+
CONFIG = "#{Gem::Specification.find_by_name('dvla-application_helper').gem_dir.freeze}/config".freeze
|
24
|
+
|
25
|
+
# Returns the configuration object, initializing it if necessary.
|
26
|
+
#
|
27
|
+
# @return [Configuration] the configuration object.
|
28
|
+
def self.configuration
|
29
|
+
@configuration ||= Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
# Configures the gem environment.
|
33
|
+
#
|
34
|
+
# @yieldparam [Configuration] config the configuration object yielded to the block.
|
35
|
+
def self.config
|
36
|
+
yield configuration
|
37
|
+
end
|
38
|
+
|
39
|
+
# Retrieve the logger object.
|
40
|
+
#
|
41
|
+
# @return [Logger] logger instance.
|
42
|
+
def self.logger
|
43
|
+
configuration.logger
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module Dvla
|
49
|
+
def self.build_mirror(source, destination)
|
50
|
+
inners = source
|
51
|
+
.constants(false)
|
52
|
+
.filter { |constant| source.const_get(constant, false).is_a?(Module) }
|
53
|
+
.map { |constant| source.const_get(constant) }
|
54
|
+
|
55
|
+
|
56
|
+
inners.each do |inner|
|
57
|
+
inner_name = inner.name.split('::').last
|
58
|
+
mirror = if destination.constants(false).include?(inner_name)
|
59
|
+
mirror.const_get(inner_name, false)
|
60
|
+
else
|
61
|
+
inner.is_a?(Class) ? Class.new : Module.new
|
62
|
+
end
|
63
|
+
|
64
|
+
destination.const_set(inner_name, mirror)
|
65
|
+
|
66
|
+
mirror.define_singleton_method(:method_missing) do |method_name, *vargs, **kwargs, &block|
|
67
|
+
warn("Access via deprecated module name of Dvla; use DVLA instead. Method #{method_name} called")
|
68
|
+
inner.send(method_name, *vargs, **kwargs, &block)
|
69
|
+
end
|
70
|
+
|
71
|
+
mirror.define_singleton_method(:const_missing) do |const_name|
|
72
|
+
warn("Access via deprecated module name of Dvla; use DVLA instead. Constant #{const_name} called")
|
73
|
+
inner.const_get(const_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
if inner.is_a?(Class)
|
77
|
+
mirror.define_method(:initialize) do |*vargs, **kwargs, &block|
|
78
|
+
warn("Access via deprecated module name of Dvla; use DVLA instead. Class #{inner.name} instantiated")
|
79
|
+
mirror.instance_variable_set(:@mirror, inner.new(*vargs, **kwargs, &block))
|
80
|
+
end
|
81
|
+
|
82
|
+
mirror.define_method(:method_missing) do |method_name, *vargs, **kwargs, &block|
|
83
|
+
mirror.instance_variable_get(:@mirror).send(method_name, *vargs, **kwargs, &block)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
build_mirror(inner, mirror)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
build_mirror(DVLA, self)
|
92
|
+
end
|
data/renovate.json
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/bin/zsh
|
2
|
+
|
3
|
+
profile="dev"
|
4
|
+
account_id=129805137803
|
5
|
+
|
6
|
+
if [ $# -gt 0 ] && [ $1 != ${profile} ]
|
7
|
+
then
|
8
|
+
if [ $1 = "nonprod" ]
|
9
|
+
then
|
10
|
+
profile="nonprod"
|
11
|
+
account_id=736948357641
|
12
|
+
else
|
13
|
+
printf "Unrecognised account, provide 'dev' or 'nonprod'\n"
|
14
|
+
return
|
15
|
+
fi
|
16
|
+
fi
|
17
|
+
|
18
|
+
export AWS_PROFILE=application-${profile}
|
19
|
+
export ACCOUNT_ID=${account_id}
|
20
|
+
export AWS_SDK_LOAD_CONFIG=true
|
21
|
+
export AWS_REGION=eu-west-2
|
22
|
+
|
23
|
+
aws sso login
|
24
|
+
|
25
|
+
setopt no_nomatch
|
26
|
+
rm -f ~/.aws/sso/cache/botocore*.json
|
27
|
+
setopt nomatch
|
28
|
+
|
29
|
+
SSO_CREDS="$(jq -s add ~/.aws/sso/cache/*.json)"
|
30
|
+
|
31
|
+
ACCESS_TOKEN=$(echo $SSO_CREDS | jq -r .accessToken)
|
32
|
+
|
33
|
+
TEMP_ROLE="$(aws sso get-role-credentials --account-id $ACCOUNT_ID --role-name Developer --access-token $ACCESS_TOKEN --region $AWS_REGION)"
|
34
|
+
|
35
|
+
secret_key=$(echo $TEMP_ROLE | jq -r .roleCredentials.secretAccessKey)
|
36
|
+
access_key=$(echo $TEMP_ROLE | jq -r .roleCredentials.accessKeyId)
|
37
|
+
token=$(echo $TEMP_ROLE | jq -r .roleCredentials.sessionToken)
|
38
|
+
expiration=$(echo $TEMP_ROLE | jq -r .roleCredentials.expiration)
|
39
|
+
|
40
|
+
aws configure set aws_secret_access_key $secret_key
|
41
|
+
aws configure set aws_access_key_id $access_key
|
42
|
+
aws configure set aws_session_token $token
|
43
|
+
printf "Account #%s | cloudplatform+Application%s\n" ${account_id} ${(C)profile}
|
44
|
+
|
45
|
+
export AWS_SECRET_ACCESS_KEY=$secret_key
|
46
|
+
export AWS_ACCESS_KEY_ID=$access_key
|
47
|
+
export AWS_SESSION_TOKEN=$token
|
48
|
+
export AWS_TOKEN_EXPIRY=$expiration
|
49
|
+
|
50
|
+
# Update .env file values
|
51
|
+
sed -i "" "s|\(AWS_SECRET_ACCESS_KEY=\).*|\1$secret_key|" .env
|
52
|
+
sed -i "" "s|\(AWS_ACCESS_KEY_ID=\).*|\1$access_key|" .env
|
53
|
+
sed -i "" "s|\(AWS_SESSION_TOKEN=\).*|\1$token|" .env
|
54
|
+
printf ".env file AWS values updated\n"
|
55
|
+
|
56
|
+
source ./.env
|
@@ -0,0 +1,18 @@
|
|
1
|
+
ACCOUNT_ID="129805137803"
|
2
|
+
if [ "$ENVIRONMENT" = "drone-link" ]; then
|
3
|
+
ACCOUNT_ID="736948357641"
|
4
|
+
fi
|
5
|
+
|
6
|
+
echo "Attempting to get AWS credentials..."
|
7
|
+
TEMP_ROLE="$(aws sts assume-role --role-arn arn:aws:iam::${ACCOUNT_ID}:role/platform/drone-serverless-test-role --role-session-name drone-serverless-sts)"
|
8
|
+
secret_key=$(echo $TEMP_ROLE | jq -r .Credentials.SecretAccessKey)
|
9
|
+
access_key=$(echo $TEMP_ROLE | jq -r .Credentials.AccessKeyId)
|
10
|
+
token=$(echo $TEMP_ROLE | jq -r .Credentials.SessionToken)
|
11
|
+
aws configure set aws_secret_access_key $secret_key --profile drone-serverless-sts
|
12
|
+
aws configure set aws_access_key_id $access_key --profile drone-serverless-sts
|
13
|
+
aws configure set aws_session_token $token --profile drone-serverless-sts
|
14
|
+
export AWS_SECRET_ACCESS_KEY=$secret_key
|
15
|
+
export AWS_ACCESS_KEY_ID=$access_key
|
16
|
+
export AWS_SESSION_TOKEN=$token
|
17
|
+
export AWS_TOKEN_EXPIRY=$expiration
|
18
|
+
export AWS_REGION=eu-west-2
|