Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Data Request script to compute requesting issuer and have configurable depth #11541

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"
Copy link
Contributor

@matthinz matthinz Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe warn if there were UUIDs from multiple SPs detected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


[
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
20 changes: 20 additions & 0 deletions spec/lib/data_pull_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,26 @@
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 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