Skip to content

Commit

Permalink
Update Data Request script to compute requesting issuer and have conf…
Browse files Browse the repository at this point in the history
…igurable depth

changelog: Internal, Scripts, Update DataRequest script to compute requesting issuer and have configurable depth
  • Loading branch information
mitchellhenke committed Nov 21, 2024
1 parent 74f0ff0 commit 0a125b4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/data_pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,22 @@ def run(args:, config:)
ActiveRecord::Base.connection.execute('SET statement_timeout = 0')
uuids = args

requesting_issuers =
config.requesting_issuers.presence || compute_requesting_issuers(uuids)

users, missing_uuids = uuids.map do |uuid|
DataRequests::Deployed::LookupUserByUuid.new(uuid).call || uuid
end.partition { |u| u.is_a?(User) }

shared_device_users = DataRequests::Deployed::LookupSharedDeviceUsers.new(users).call
shared_device_users =
if config.depth && config.depth > 0
DataRequests::Deployed::LookupSharedDeviceUsers.new(users, config.depth).call
else
users
end

output = shared_device_users.map do |user|
DataRequests::Deployed::CreateUserReport.new(user, config.requesting_issuers).call
DataRequests::Deployed::CreateUserReport.new(user, requesting_issuers).call
end

if config.include_missing?
Expand Down Expand Up @@ -198,6 +206,20 @@ def run(args:, config:)
json: output,
)
end

private

def compute_requesting_issuers(uuids)
service_providers = ServiceProviderIdentity.where(uuid: uuids).pluck(:service_provider)
return nil if service_providers.empty?
service_provider = service_providers.tally.max_by { |_sp, count| count }[0]

warn "Computed service provider #{service_provider}"

[
service_provider,
]
end
end

class ProfileSummary
Expand Down
7 changes: 7 additions & 0 deletions lib/script_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def reason_arg?
:show_help,
:requesting_issuers,
:deflate,
:depth,
:reason,
keyword_init: true,
) do
Expand Down Expand Up @@ -111,6 +112,12 @@ def option_parser
config.requesting_issuers << issuer
end

opts.on('--depth=DEPTH', <<-MSG) do |depth|
depth of connected devices (used for ig-request task)
MSG
config.depth = depth.to_i
end

opts.on('--help') do
config.show_help = true
end
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/data_pull_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,25 @@
expect(result.subtask).to eq('ig-request')
expect(result.uuids).to eq([user.uuid])
end

context 'with SP UUID argument and no requesting issuer' do
let(:args) { [identity.uuid] }
let(:config) { ScriptBase::Config.new }
it 'runs the create users report with computed requesting issuer', aggregate_failures: true do
expect(result.table).to be_nil
expect(result.json.first.keys).to contain_exactly(
:user_id,
:login_uuid,
:requesting_issuer_uuid,
:email_addresses,
:mfa_configurations,
:user_events,
)

expect(result.subtask).to eq('ig-request')
expect(result.uuids).to eq([user.uuid])
end
end
end
end

Expand Down

0 comments on commit 0a125b4

Please sign in to comment.