-
-
Notifications
You must be signed in to change notification settings - Fork 211
Feat: replaced hardcoded test server admin key with env variable #1568
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: rohansen856 <rohansen856@gmail.com>
Signed-off-by: rohansen856 <rohansen856@gmail.com>
Signed-off-by: rohansen856 <rohansen856@gmail.com>
fkiraly
left a comment
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 successfully removes the secret from the code base.
My only question, is there a documentation location (e.g., developer documentation) that also needs to get updated about this? Since developers wishing to use the test server now have to:
- obtain credentials (from whom or where?)
- set the environment variable in python
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1568 +/- ##
==========================================
+ Coverage 52.75% 52.76% +0.01%
==========================================
Files 36 36
Lines 4333 4334 +1
==========================================
+ Hits 2286 2287 +1
Misses 2047 2047 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I think if any documentation update has to be done it should be in Advanced user guide ( also this is the admin API key for the OpenML test server (https://test.openml.org`) (even though we used very weak credentials for testing purposes: Please do let me know if you have other suggestions on this @fkiraly |
|
@jgyasu, does this need to be added to the developer guide you are writing? |
geetu040
left a comment
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 fine, just need to add code for loading .env if that is required. And we should also mention this in the internal developer setup.
| - name: Run tests on Ubuntu Test | ||
| if: matrix.os == 'ubuntu-latest' | ||
| env: | ||
| OPENML_TEST_SERVER_ADMIN_KEY: ${{ secrets.OPENML_TEST_SERVER_ADMIN_KEY }} |
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.
we should make sure these are added in the github secrets before merging this
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.
secret set
|
|
||
| OPENML_CACHE_DIR_ENV_VAR = "OPENML_CACHE_DIR" | ||
| OPENML_SKIP_PARQUET_ENV_VAR = "OPENML_SKIP_PARQUET" | ||
| OPENML_TEST_SERVER_ADMIN_KEY_ENV_VAR = "OPENML_TEST_SERVER_ADMIN_KEY" |
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.
in case of using a .env file, some code is required to load it and may add the extra dependency python-dotenv
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.
yes definitely! Will go ahead with the new dep if approved.
| ) | ||
| @pytest.mark.production() | ||
| def test_switch_to_example_configuration(self): | ||
| """Verifies the test configuration is loaded properly.""" |
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.
btw this test passes anyways even if you use any random admin_key, right?
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.
Yes, test_switch_to_example_configuration doesn't make any API calls, it only tests that start_using_configuration_for_example() correctly swaps the apikey and server values. So it passes with any value (even None is ok)
But test_data_status (tests\test_datasets\test_dataset_functions.py) does require a valid admin key because it makes actual API calls to openml.datasets.status_update() which the server validates, so if a user passes invalid value it would return authentication error:
FAILED tests/test_datasets/test_dataset_functions.py::TestOpenMLDataset::test_data_status - openml.exceptions.OpenMLServerException: https://test.openml.org/api/v1/xml/data/status/update ...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.
Yes, I think the more reasonable approach here is to update this test to use some other sentinel value.
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.
Mostly LGTM, but I am not yet sold on introducing the .env file.
Regular user settings are currently configured through a dedicated configuration file already. I'm not yet convinced that adding a .env file for (developer) configuration is more logical than extending the existing configuration file. A decision should probably be made in the larger context on how to handle configurations?
Something that seems reasonable is to support openml config files in ./.openml/config for directory level configurations.
In my opinion we can merge this as is (except for the note on test_switch_to_example_configuration), and then discuss ideas on how we should have user and developer configurations after.
| - name: Run tests on Ubuntu Test | ||
| if: matrix.os == 'ubuntu-latest' | ||
| env: | ||
| OPENML_TEST_SERVER_ADMIN_KEY: ${{ secrets.OPENML_TEST_SERVER_ADMIN_KEY }} |
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.
secret set
| ) | ||
| @pytest.mark.production() | ||
| def test_switch_to_example_configuration(self): | ||
| """Verifies the test configuration is loaded properly.""" |
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.
Yes, I think the more reasonable approach here is to update this test to use some other sentinel value.
Metadata
Details
this PR is made to remove the hardcoded test server admin key from the codebase and replace it with environment variable-based authentication.
Summary
openml/config.pyAdded a new environment variable constant for the test server admin key:openml/testing.py. Modified theTestBaseclass to read the admin key from an environment variable instead of using a hardcoded value:Before:
After:
Note:
Noneby default when the environment variable is not setAlso in the tests, Added
pytest.skipifdecorators to tests that require admin privileges in the following test files:tests/test_openml/test_config.pyTest:
test_switch_to_example_configurationAdded decorator:
tests/test_datasets/test_dataset_functions.pyTest:
test_data_statusAdded decorator:
Note:
4. CI Configuration Update (
.github/workflows/test.yml)Added the environment variable to all test execution steps in the GitHub Actions workflow:
Steps updated:
Added to each step:
Impact:
@PGijsbers this requires someone to put the admin key in the github secrets which would be a critical step.