Skip to content

Commit

Permalink
introduce mvi rake task to fetch mvi attributes given csv (#3607)
Browse files Browse the repository at this point in the history
  • Loading branch information
saneshark authored Dec 6, 2019
1 parent 90bad1c commit fd494a3
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions rakelib/mvi.rake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,54 @@ middle_name="W" last_name="Smith" birth_date="1945-01-25" gender="M" ssn="555443
end
end

desc 'Given a CSV with ICNs, append attributes needed to stage the user as ID.me LOA3' do
task :idme_saml_stage_attributes, [:csvfile] => [:environment] do |_, args|
raise 'No input CSV provided' unless args[:csvfile]

CSV.open(args[:csvfile] + '.out', 'w', write_headers: true) do |dest|
existing_headers = CSV.open(args[:csvfile], &:readline)
appended_headers = %w[first_name middle_name last_name gender birth_date ssn address]
CSV.open(args[:csvfile], headers: true) do |source|
dest << (existing_headers + appended_headers)
source.each do |row|
user_identity = UserIdentity.new(
uuid: SecureRandom.uuid,
email: 'fakeemail@needed_for_object_validation.gov',
mhv_icn: row['icn'], # HACK: because the presence of this attribute results in ICN based MVI lookup
loa: {
current: LOA::THREE,
highest: LOA::THREE
}
)

# Not persisting any users, user_identities, or caching MVI by doing it this way.
user = User.new(uuid: user_identity.uuid)
user.instance_variable_set(:@identity, user_identity)
mvi = Mvi.for_user(user)
response = mvi.send(:mvi_service).find_profile(user_identity)

appended_headers.each do |column_name|
case column_name
when 'address'
row['address'] = response.profile.address.to_json
when 'first_name'
row['first_name'] = response.profile.given_names.first
when 'middle_name'
row['middle_name'] = response.profile.given_names.to_a[1..-1]&.join(' ')
when 'last_name'
row['last_name'] = response.profile.family_name
else
row[column_name] = response.profile.send(column_name.to_sym)
end
end

dest << row
end
end
end
end
end

desc 'Build mock MVI yaml database for users in given CSV'
task :mock_database, [:csvfile] => [:environment] do |_, args|
raise 'No input CSV provided' unless args[:csvfile]
Expand Down

0 comments on commit fd494a3

Please sign in to comment.