From b32792a068970c082ab82e5864d27bb264dd797e Mon Sep 17 00:00:00 2001 From: Mitchell Henke Date: Fri, 26 Mar 2021 12:13:13 -0500 Subject: [PATCH 1/2] remove some lambda --- app/services/idv/agent.rb | 135 +++++------------- app/services/lambda_jobs/runner.rb | 45 ------ .../doc_auth/document_capture_step_spec.rb | 12 +- spec/services/idv/agent_spec.rb | 18 --- spec/services/lambda_jobs/git_ref_spec.rb | 5 - spec/services/lambda_jobs/runner_spec.rb | 101 ------------- 6 files changed, 39 insertions(+), 277 deletions(-) delete mode 100644 app/services/lambda_jobs/runner.rb delete mode 100644 spec/services/lambda_jobs/git_ref_spec.rb delete mode 100644 spec/services/lambda_jobs/runner_spec.rb diff --git a/app/services/idv/agent.rb b/app/services/idv/agent.rb index 837e7afe183..03e55eaffb7 100644 --- a/app/services/idv/agent.rb +++ b/app/services/idv/agent.rb @@ -10,11 +10,11 @@ def proof_resolution(document_capture_session, should_proof_state_id:, trace_id: document_capture_session.result_id, ) - if FeatureManagement.ruby_workers_enabled? - encrypted_arguments = Encryption::Encryptors::SessionEncryptor.new.encrypt( - { applicant_pii: @applicant }.to_json, - ) + encrypted_arguments = Encryption::Encryptors::SessionEncryptor.new.encrypt( + { applicant_pii: @applicant }.to_json, + ) + if FeatureManagement.ruby_workers_enabled? ResolutionProofingJob.perform_later( encrypted_arguments: encrypted_arguments, callback_url: callback_url, @@ -24,40 +24,14 @@ def proof_resolution(document_capture_session, should_proof_state_id:, trace_id: result_id: document_capture_session.result_id, ) else - LambdaJobs::Runner.new( - job_class: Idv::Proofer.resolution_job_class, - in_process_config: { - aamva_config: { - auth_request_timeout: AppConfig.env.aamva_auth_request_timeout, - auth_url: AppConfig.env.aamva_auth_url, - cert_enabled: AppConfig.env.aamva_cert_enabled, - private_key: AppConfig.env.aamva_private_key, - public_key: AppConfig.env.aamva_public_key, - verification_request_timeout: AppConfig.env.aamva_verification_request_timeout, - verification_url: AppConfig.env.aamva_verification_url, - }, - lexisnexis_config: { - instant_verify_workflow: AppConfig.env.lexisnexis_instant_verify_workflow, - account_id: AppConfig.env.lexisnexis_account_id, - base_url: AppConfig.env.lexisnexis_base_url, - username: AppConfig.env.lexisnexis_username, - password: AppConfig.env.lexisnexis_password, - request_mode: AppConfig.env.lexisnexis_request_mode, - request_timeout: AppConfig.env.lexisnexis_timeout, - }, - }, - args: { - applicant_pii: @applicant, - callback_url: callback_url, - should_proof_state_id: should_proof_state_id, - dob_year_only: AppConfig.env.proofing_send_partial_dob == 'true', - trace_id: trace_id, - }, - ).run do |idv_result| - document_capture_session.store_proofing_result(idv_result[:resolution_result]) - - nil - end + ResolutionProofingJob.perform_now( + encrypted_arguments: encrypted_arguments, + callback_url: callback_url, + should_proof_state_id: should_proof_state_id, + dob_year_only: AppConfig.env.proofing_send_partial_dob == 'true', + trace_id: trace_id, + result_id: document_capture_session.result_id, + ) end end @@ -66,11 +40,11 @@ def proof_address(document_capture_session, trace_id:) callback_url = Rails.application.routes.url_helpers.address_proof_result_url( document_capture_session.result_id, ) + encrypted_arguments = Encryption::Encryptors::SessionEncryptor.new.encrypt( + { applicant_pii: @applicant }.to_json, + ) if FeatureManagement.ruby_workers_enabled? - encrypted_arguments = Encryption::Encryptors::SessionEncryptor.new.encrypt( - { applicant_pii: @applicant }.to_json, - ) AddressProofingJob.perform_later( encrypted_arguments: encrypted_arguments, callback_url: callback_url, @@ -78,25 +52,12 @@ def proof_address(document_capture_session, trace_id:) trace_id: trace_id, ) else - LambdaJobs::Runner.new( - job_class: Idv::Proofer.address_job_class, - args: { applicant_pii: @applicant, callback_url: callback_url, trace_id: trace_id }, - in_process_config: { - lexisnexis_config: { - phone_finder_workflow: AppConfig.env.lexisnexis_phone_finder_workflow, - account_id: AppConfig.env.lexisnexis_account_id, - base_url: AppConfig.env.lexisnexis_base_url, - username: AppConfig.env.lexisnexis_username, - password: AppConfig.env.lexisnexis_password, - request_mode: AppConfig.env.lexisnexis_request_mode, - request_timeout: AppConfig.env.lexisnexis_timeout, - }, - }, - ).run do |idv_result| - document_capture_session.store_proofing_result(idv_result[:address_result]) - - nil - end + AddressProofingJob.perform_now( + encrypted_arguments: encrypted_arguments, + callback_url: callback_url, + result_id: document_capture_session.result_id, + trace_id: trace_id, + ) end end @@ -105,11 +66,11 @@ def proof_document(document_capture_session, liveness_checking_enabled:, trace_i result_id: document_capture_session.result_id, ) - if FeatureManagement.ruby_workers_enabled? - encrypted_arguments = Encryption::Encryptors::SessionEncryptor.new.encrypt( - { document_arguments: @applicant }.to_json, - ) + encrypted_arguments = Encryption::Encryptors::SessionEncryptor.new.encrypt( + { document_arguments: @applicant }.to_json, + ) + if FeatureManagement.ruby_workers_enabled? DocumentProofingJob.perform_later( encrypted_arguments: encrypted_arguments, liveness_checking_enabled: liveness_checking_enabled, @@ -118,46 +79,14 @@ def proof_document(document_capture_session, liveness_checking_enabled:, trace_i trace_id: trace_id, ) else - LambdaJobs::Runner.new( - job_class: Idv::Proofer.document_job_class, - args: { - encryption_key: @applicant[:encryption_key], - front_image_iv: @applicant[:front_image_iv], - back_image_iv: @applicant[:back_image_iv], - selfie_image_iv: @applicant[:selfie_image_iv], - front_image_url: @applicant[:front_image_url], - back_image_url: @applicant[:back_image_url], - selfie_image_url: @applicant[:selfie_image_url], - liveness_checking_enabled: liveness_checking_enabled, - callback_url: callback_url, - trace_id: trace_id, - }, - ).run do |doc_auth_result| - document_result = doc_auth_result.to_h.fetch(:document_result, {}) - dcs = DocumentCaptureSession.new(result_id: document_capture_session.result_id) - dcs.store_doc_auth_result( - result: document_result.except(:pii_from_doc), - pii: document_result[:pii_from_doc], - ) - - nil - end + DocumentProofingJob.perform_now( + encrypted_arguments: encrypted_arguments, + liveness_checking_enabled: liveness_checking_enabled, + result_id: document_capture_session.result_id, + callback_url: callback_url, + trace_id: trace_id, + ) end end - - private - - def init_results - { - errors: {}, - messages: [], - context: { - stages: [], - }, - exception: nil, - success: false, - timed_out: false, - } - end end end diff --git a/app/services/lambda_jobs/runner.rb b/app/services/lambda_jobs/runner.rb deleted file mode 100644 index 8316d61ee63..00000000000 --- a/app/services/lambda_jobs/runner.rb +++ /dev/null @@ -1,45 +0,0 @@ -module LambdaJobs - class Runner - attr_reader :job_class, :args, :in_process_config - - def initialize(job_class:, args:, in_process_config: {}) - @job_class = job_class - @args = args - @in_process_config = in_process_config - end - - def run(&local_callback) - if Identity::Hostdata.in_datacenter? && AppConfig.env.aws_lambda_proofing_enabled == 'true' - aws_lambda_client.invoke( - function_name: function_name, - invocation_type: 'Event', - log_type: 'None', - payload: args.to_json, - ) - else - job_class.handle( - event: args.merge(in_process_config), - context: nil, - &local_callback - ) - end - end - - def aws_lambda_client - Aws::Lambda::Client.new(region: AppConfig.env.aws_region) - end - - # Due to length limits, we can only use the first 10 characters of a git SHA - def function_name - "#{Identity::Hostdata.env}-idp-functions-#{job_name}Function:#{LambdaJobs::GIT_REF[0...10]}" - end - - # @example - # new(job_class: IdentityIdpFunctions::ProofResolutionMock).job_name - # => "ProofResolutionMock" - # @return [String] - def job_name - job_class.name.split('::').last - end - end -end diff --git a/spec/features/idv/doc_auth/document_capture_step_spec.rb b/spec/features/idv/doc_auth/document_capture_step_spec.rb index ff97df963f2..5a0ff719d1a 100644 --- a/spec/features/idv/doc_auth/document_capture_step_spec.rb +++ b/spec/features/idv/doc_auth/document_capture_step_spec.rb @@ -271,11 +271,8 @@ context 'when using async uploads', :js do before do - allow(LambdaJobs::Runner).to receive(:new). - with(hash_including(job_class: Idv::Proofer.document_job_class)). + allow(DocumentProofingJob).to receive(:perform_later). and_call_original - allow(AppConfig.env).to receive(:ruby_workers_enabled). - and_return('false') end it 'proceeds to the next page with valid info' do @@ -309,7 +306,12 @@ click_on 'Submit' expect(page).to have_current_path(next_step, wait: 20) - expect(LambdaJobs::Runner).to have_received(:new) do |args:, **| + expect(DocumentProofingJob).to have_received(:perform_later) do |encrypted_arguments:, **| + args = JSON.parse( + Encryption::Encryptors::SessionEncryptor.new.decrypt(encrypted_arguments), + symbolize_names: true, + )[:document_arguments] + original = File.read('app/assets/images/logo.png') encryption_helper = IdentityIdpFunctions::EncryptionHelper.new diff --git a/spec/services/idv/agent_spec.rb b/spec/services/idv/agent_spec.rb index 39f30242f63..d5ae0d18501 100644 --- a/spec/services/idv/agent_spec.rb +++ b/spec/services/idv/agent_spec.rb @@ -51,24 +51,6 @@ transaction_id: IdentityIdpFunctions::StateIdMockClient::TRANSACTION_ID, ) end - - context 'proofing partial date of birth' do - before do - allow(AppConfig.env).to receive(:proofing_send_partial_dob).and_return('true') - allow(AppConfig.env).to receive(:ruby_workers_enabled). - and_return('false') - end - - it 'passes dob_year_only to the proofing function' do - expect(LambdaJobs::Runner).to receive(:new). - with(hash_including(args: hash_including(dob_year_only: true))). - and_call_original - - agent.proof_resolution( - document_capture_session, should_proof_state_id: true, trace_id: trace_id - ) - end - end end context 'proofing state_id disabled' do diff --git a/spec/services/lambda_jobs/git_ref_spec.rb b/spec/services/lambda_jobs/git_ref_spec.rb deleted file mode 100644 index 52dcfe9a0b7..00000000000 --- a/spec/services/lambda_jobs/git_ref_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -RSpec.describe LambdaJobs::GIT_REF do - it 'exists' do - expect(LambdaJobs::GIT_REF).to be - end -end diff --git a/spec/services/lambda_jobs/runner_spec.rb b/spec/services/lambda_jobs/runner_spec.rb deleted file mode 100644 index 1080130f5b6..00000000000 --- a/spec/services/lambda_jobs/runner_spec.rb +++ /dev/null @@ -1,101 +0,0 @@ -require 'rails_helper' - -RSpec.describe LambdaJobs::Runner do - subject(:runner) do - LambdaJobs::Runner.new(args: args, job_class: job_class, in_process_config: in_process_config) - end - - let(:args) { { foo: 'bar' } } - let(:job_class) { double('JobClass', name: 'SomeModule::OtherModule::JobClass') } - let(:in_process_config) { { key: 'secret' } } - let(:aws_lambda_proofing_enabled) { 'true' } - - let(:env) { 'dev' } - let(:git_ref) { '1234567890abcdefghijklmnop' } - before do - stub_const('LambdaJobs::GIT_REF', git_ref) - allow(Identity::Hostdata).to receive(:env).and_return(env) - end - - describe '#function_name' do - it 'has the env, job class and first 10 characters of the GIT_REF' do - expect(runner.function_name).to eq('dev-idp-functions-JobClassFunction:1234567890') - end - end - - describe '#run' do - before do - allow(Identity::Hostdata).to receive(:in_datacenter?).and_return(in_datacenter) - allow(AppConfig.env).to receive(:aws_lambda_proofing_enabled). - and_return(aws_lambda_proofing_enabled) - end - - context 'when run in a deployed environment' do - let(:in_datacenter) { true } - - context 'when aws_lambda_proofing_enabled is true' do - let(:aws_lambda_proofing_enabled) { 'true' } - - let(:aws_lambda_client) { instance_double(Aws::Lambda::Client) } - before do - expect(runner).to receive(:aws_lambda_client).and_return(aws_lambda_client) - end - - it 'involves a lambda in AWS, without sending in_process_config' do - expect(aws_lambda_client).to receive(:invoke).with( - function_name: 'dev-idp-functions-JobClassFunction:1234567890', - invocation_type: 'Event', - log_type: 'None', - payload: args.to_json, - ) - - runner.run - end - end - - context 'when aws_lambda_proofing_enabled is false' do - let(:aws_lambda_proofing_enabled) { 'false' } - - it 'calls JobClass.handle' do - expect(job_class).to receive(:handle).with( - event: args.merge(in_process_config), - context: nil, - ) - - runner.run - end - end - end - - context 'when run locally' do - let(:in_datacenter) { false } - - it 'calls JobClass.handle, merging in including in_process_config' do - expect(job_class).to receive(:handle).with( - event: args.merge(in_process_config), - context: nil, - ) - - runner.run - end - - context 'when run locally with a block' do - it 'passes the block to the handler' do - result = Object.new - - expect(job_class).to receive(:handle).with( - event: args.merge(in_process_config), - context: nil, - ).and_yield(result) - - yielded_result = nil - runner.run do |callback_result| - yielded_result = callback_result - end - - expect(yielded_result).to eq(result) - end - end - end - end -end From 48312effc7027b6a2b5388a63050b6c7eb3d2b54 Mon Sep 17 00:00:00 2001 From: Mitchell Henke Date: Fri, 26 Mar 2021 13:20:38 -0500 Subject: [PATCH 2/2] remove lambda jobs git ref --- Gemfile | 3 +-- Gemfile.lock | 2 +- lib/lambda_jobs/git_ref.rb | 5 ----- 3 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 lib/lambda_jobs/git_ref.rb diff --git a/Gemfile b/Gemfile index d0bafec9934..5f4ed478149 100644 --- a/Gemfile +++ b/Gemfile @@ -26,8 +26,7 @@ gem 'http_accept_language' gem 'identity-doc-auth', github: '18F/identity-doc-auth', branch: 'v0.5.0' gem 'identity-hostdata', github: '18F/identity-hostdata', tag: 'v2.0.0' gem 'identity-logging', github: '18F/identity-logging', tag: 'v0.1.0' -require File.join(__dir__, 'lib', 'lambda_jobs', 'git_ref.rb') -gem 'identity-idp-functions', github: '18F/identity-idp-functions', ref: LambdaJobs::GIT_REF +gem 'identity-idp-functions', github: '18F/identity-idp-functions', ref:'d9241bdfea85a76c170e456a89' gem 'identity-telephony', github: '18f/identity-telephony', tag: 'v0.1.12' gem 'identity_validations', github: '18F/identity-validations', branch: 'main' gem 'json-jwt', '>= 1.11.0' diff --git a/Gemfile.lock b/Gemfile.lock index 906fdaa5b77..6667f8ea3f6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -32,7 +32,7 @@ GIT GIT remote: https://github.com/18F/identity-idp-functions.git revision: d9241bdfea85a76c170e456a89ec6601549f4c4a - ref: d9241bdfea85a76c170e456a89ec6601549f4c4a + ref: d9241bdfea85a76c170e456a89 specs: identity-idp-functions (0.15.2) aamva (>= 4.0.0) diff --git a/lib/lambda_jobs/git_ref.rb b/lib/lambda_jobs/git_ref.rb deleted file mode 100644 index 160d76af46d..00000000000 --- a/lib/lambda_jobs/git_ref.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -module LambdaJobs - GIT_REF = 'd9241bdfea85a76c170e456a89ec6601549f4c4a' -end