-
Notifications
You must be signed in to change notification settings - Fork 7
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
Move sitewide settings to environment variables (PP-494) #1648
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1648 +/- ##
==========================================
+ Coverage 89.53% 89.97% +0.44%
==========================================
Files 245 244 -1
Lines 28817 28447 -370
Branches 6595 6493 -102
==========================================
- Hits 25802 25596 -206
+ Misses 2040 1895 -145
+ Partials 975 956 -19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
14d438d
to
5fad772
Compare
api/app.py
Outdated
os.environ["PALACE_SECRET_KEY"] = "".join( | ||
secrets.choice(string.ascii_lowercase) for i in range(24) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in the debug run function. Just allows us to run a debug environment with app.py without having to specify a SECRET_KEY every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Might be useful to clarify in the comment that this is only safe because this is a debug environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one will go away when #1664 goes in
This one is ready for review now, but I'm leaving it in draft until the additional PR in the description are ready to go, so it doesn't get merged early. |
f70e6a0
to
7b6a693
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. A few questions/comments, but no show stoppers.
README.md
Outdated
#### General | ||
|
||
- `PALACE_BASE_URL`: The base URL of the application. Used to create absolute links. (optional) | ||
- `PALACE_SECRET_KEY`: A secret key used for used to provide cryptographic signing, and should be set to a unique, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicated words: key [used for] [used to] provide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this part of the README, in favor of the work in #1664
sitewide_tos_href=Configuration.DEFAULT_TOS_HREF, | ||
sitewide_tos_text=Configuration.DEFAULT_TOS_TEXT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be configurable, in case a non-Palace entity wants to run this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we were running the Library Simplified code, we never actually set these did we? It wasn't until Palace when we customized them. I was thinking that we can make this configurable if/when someone needs it.
Happy to make them env vars though, if you disagree.
api/app.py
Outdated
@@ -61,12 +59,12 @@ def get_locale(): | |||
PalaceXrayProfiler.configure(app) | |||
|
|||
|
|||
def initialize_admin(_db=None): | |||
def initialize_admin(_db: Session | None = None, secret_key: str | None = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The secret key is required. Should we allow a None
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This went away with the work in #1664
api/app.py
Outdated
os.environ["PALACE_SECRET_KEY"] = "".join( | ||
secrets.choice(string.ascii_lowercase) for i in range(24) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Might be useful to clarify in the comment that this is only safe because this is a debug environment.
{ | ||
"key": CUSTOM_TOS_HREF, | ||
"label": _("Custom Terms of Service link"), | ||
"required": False, | ||
"default": DEFAULT_TOS_HREF, | ||
"description": _( | ||
"If your inclusion in the SimplyE mobile app is governed by terms other than the default, put the URL to those terms in this link so that librarians will have access to them. This URL will be used for all libraries on this circulation manager." | ||
), | ||
}, | ||
{ | ||
"key": CUSTOM_TOS_TEXT, | ||
"label": _("Custom Terms of Service link text"), | ||
"required": False, | ||
"default": DEFAULT_TOS_TEXT, | ||
"description": _( | ||
"Custom text for the Terms of Service link in the footer of these administrative interface pages. This is primarily useful if you're not connecting this circulation manager to the SimplyE mobile app. This text will be used for all libraries on this circulation manager." | ||
), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these get mapped to PALACE_
env vars, in case a non-palace entity wants to run the code? We could still use the default href and/or text, if they were not specified.
) | ||
) | ||
return | ||
return super(ReaperMonitor, self).run() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some lingering Python 2 goodness.
def test_script_run(self, holds_fixture: HoldsNotificationFixture): | ||
db = holds_fixture.db | ||
patron1 = db.patron() | ||
work1 = db.work(with_license_pool=True) | ||
work2 = db.work(with_license_pool=True) | ||
hold1, _ = work1.active_license_pool().on_hold_to(patron1, position=0) | ||
hold2, _ = work2.active_license_pool().on_hold_to(patron1, position=0) | ||
|
||
with patch("core.jobs.holds_notification.PushNotifications") as mock_notf: | ||
holds_fixture.monitor.run() | ||
assert mock_notf.send_holds_notifications.call_count == 1 | ||
assert mock_notf.send_holds_notifications.call_args_list == [ | ||
call([hold1, hold2]) | ||
] | ||
|
||
# Sitewide notifications are turned off | ||
mock_notf.send_holds_notifications.reset_mock() | ||
ConfigurationSetting.sitewide( | ||
db.session, Configuration.PUSH_NOTIFICATIONS_STATUS | ||
).value = ConfigurationConstants.FALSE | ||
holds_fixture.monitor.run() | ||
assert mock_notf.send_holds_notifications.call_count == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to get rid of this whole test or just the part related to the defunct Configuration.PUSH_NOTIFICATIONS_STATUS
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Added back in the non-config part of this test.
49c4897
to
7b6a693
Compare
7b6a693
to
dd46877
Compare
4f2bc3e
to
29a4be4
Compare
5212a4f
to
8feade0
Compare
0a60402
to
d4fb355
Compare
Description
Move our sitewide settings to environment variables, and remove the sitewide settings controller. Since this is the last bit of the configuration settings to get switched over, remove the old settings controller as well.
🚨 Before this one can be merged we need:
Updates to add new env vars to playbookUpdated admin UI that removes the sitewide settings screensChanges to sitewide config:
LOG_LEVEL
,LOG_APP_NAME
andDATABASE_LOG_LEVEL
removed because they were no longer used.EXCLUDED_AUDIO_DATA_SOURCES
removed, as its not used on any of our sites, and it was added long ago when testing overdrive content.MEASUREMENT_REAPER
removed, since we don't have any need to disable this reaper.PUSH_NOTIFICATIONS_STATUS
removed, since its enabled everywhere now anyway.BEARER_TOKEN_SIGNING_SECRET
is merged withSECRET_KEY
, since they have a similar function and it doesn't seem like we need both of them.STATIC_FILE_CACHE_TIME
removed, since we don't serve static files with the CM anymore.CUSTOM_TOS_HREF
andCUSTOM_TOS_TEXT
removed because we don't use them anywhere.Motivation and Context
Close to the end of the work for PP-4.
How Has This Been Tested?
Checklist