Skip to content
Merged
Changes from all commits
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
11 changes: 10 additions & 1 deletion lib/tasks/attempts.rake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ namespace :attempts do
desc 'Confirm your dev setup is configured properly'
task check_enabled: :environment do
failed = false
auth_token = IdentityConfig.store.irs_attempt_api_auth_tokens.sample
puts 'There are no configured irs_attempt_api_auth_tokens' if auth_token.nil?
private_key_path = 'keys/attempts_api_private_key.key'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was set at the class level earlier but Zach (rightly) pulled some of it out since it was spamming rake output in prod: e82e728

We expected auth_token and private_key_path to be defined here. I'm duplicating them, and keeping the puts rather than adding a separate check. I don't think we need to worry about DRYing this up further.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

whoops great catch, thanks


if IdentityConfig.store.irs_attempt_api_enabled
puts 'βœ… Feature flag is enabled'
Expand All @@ -59,7 +62,7 @@ namespace :attempts do
puts 'βœ… Sinatra app SP has irs_attempts_api_enabled=true'
else
failed = true
puts "❌ FAILED: Set irs_attempts_api_enabled=true on ServiceProvider.find #{sp.id}"
puts '❌ FAILED: Run rake attempts:enable_for_sinatra'
end

if IdentityConfig.store.irs_attempt_api_auth_tokens.include?(auth_token)
Expand All @@ -78,6 +81,12 @@ namespace :attempts do
puts 'Remember to restart Rails after updating application.yml.default!' if failed
end

desc 'Enable irs_attempts_api_enabled for Sinatra SP'
task enable_for_sinatra: :environment do
sp = ServiceProvider.find_by(friendly_name: 'Example Sinatra App')
sp.update(irs_attempts_api_enabled: true)
end
Copy link
Copy Markdown
Contributor Author

@n1zyy n1zyy Oct 20, 2022

Choose a reason for hiding this comment

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

Since we're already checking this and telling you if it's wrong, let's just offer to fix it here, rather than making the user go off to the rails console.

I briefly debated adding a check so this would refuse to run in prod, but (1) you shouldn't run random rake tasks in prod, (2) there probably isn't an actual SP named "Example Sinatra App" in prod, and (3) if there is, someone running this probably actually intends to enable it? 🀷 Happy to add a check if people believe it's warranted.

Going in the other direction, we could make check_enabled just fix this for you immediately, but none of the others can be done that way so it seems best to stay consistent.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd consider maybe making the friendly name (or even issuer?) an argument so we ca call rake enable_attempts_api ISSUER=ABCDEF

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That'd be easy enough to implement, but the intent here was just for localhost use with the default Sinatra app. I think if people are going to go edit other providers they're probably better off using the Rails console.


desc 'Clear all events from Redis'
task purge_events: :environment do
IrsAttemptsApi::RedisClient.clear_attempts!
Expand Down