Skip to content

Adds attempts:enable_for_sinatra and fix minor breakage#7179

Merged
n1zyy merged 1 commit intomainfrom
mattw/fix-attempts-rake
Nov 4, 2022
Merged

Adds attempts:enable_for_sinatra and fix minor breakage#7179
n1zyy merged 1 commit intomainfrom
mattw/fix-attempts-rake

Conversation

@n1zyy
Copy link
Contributor

@n1zyy n1zyy commented Oct 20, 2022

🎫 Ticket

None. This is whim.

🛠 Summary of changes

  • Fixes a small bug breaking rake attempts:check_enabled
  • Adds rake attempts:enable_for_sinatra task, to make life easier

📜 Testing Plan

$ be rake attempts:check_enabled
✅ Feature flag is enabled
❌ FAILED: Run rake attempts:enable_for_sinatra
✅ abc123 set as auth token
✅ 'keys/attempts_api_private_key.key' exists for decrypting events
Remember to restart Rails after updating application.yml.default!

$ be rake attempts:enable_for_sinatra

$ be rake attempts:check_enabled
✅ Feature flag is enabled
✅ Sinatra app SP has irs_attempts_api_enabled=true
✅ abc123 set as auth token
✅ 'keys/attempts_api_private_key.key' exists for decrypting events

🚀 Notes for Deployment

N/A - This should not be used in prod.

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
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
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

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
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
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
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.

@n1zyy n1zyy requested a review from a team October 20, 2022 02:56
Copy link
Contributor

@Rwolfe-Nava Rwolfe-Nava left a comment

Choose a reason for hiding this comment

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

Thank you for doing this!

@n1zyy n1zyy merged commit 78e1cf3 into main Nov 4, 2022
@n1zyy n1zyy deleted the mattw/fix-attempts-rake branch November 4, 2022 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants