-
Notifications
You must be signed in to change notification settings - Fork 4
Created script just for calling the login/logout endpoint #213
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _this_dir = os.path.dirname(os.path.abspath(__file__)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_to_dspace_lib = os.path.join(_this_dir, "../../libs/dspace-rest-python") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sys.path.insert(0, path_to_dspace_lib) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sys.path.insert(0, os.path.join(_this_dir, "../../src")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import dspace # noqa | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import settings # noqa | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import project_settings # noqa | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from utils import init_logging, update_settings # noqa | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger = logging.getLogger() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| env = update_settings(settings.env, project_settings.settings) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| init_logging(_logger, env["log_file"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger.info("Started...") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dspace_be = dspace.rest(env["backend"]["endpoint"], env["backend"]["user"], env["backend"]["password"], True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in range(1, 10): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _logger.info(f"Authenticating {i}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dspace_be.client.authenticate() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and make the loop count configurable. The authentication loop lacks error handling and uses a hard-coded count. This could cause the script to fail silently or make it difficult to customize for different testing scenarios. - dspace_be = dspace.rest(env["backend"]["endpoint"], env["backend"]["user"], env["backend"]["password"], True)
- for i in range(1, 10):
- _logger.info(f"Authenticating {i}")
- dspace_be.client.authenticate()
+ try:
+ dspace_be = dspace.rest(env["backend"]["endpoint"], env["backend"]["user"], env["backend"]["password"], True)
+
+ # Make loop count configurable via environment variable
+ loop_count = int(os.environ.get("AUTH_LOOP_COUNT", "9"))
+
+ for i in range(1, loop_count + 1):
+ _logger.info(f"Authenticating attempt {i}/{loop_count}")
+ try:
+ dspace_be.client.authenticate()
+ _logger.info(f"Authentication attempt {i} successful")
+ except Exception as e:
+ _logger.error(f"Authentication attempt {i} failed: {e}")
+
+ except Exception as e:
+ _logger.error(f"Failed to initialize DSpace backend: {e}")
+ sys.exit(1)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Call logout every 5th request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # if i % 5 == 0: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # dspace_be.client.logout() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # print("Logged out") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
🛠️ Refactor suggestion
Add validation for required environment variables.
The script assumes required credentials exist in the environment but doesn't validate them. This could lead to unclear error messages if configuration is missing.
Also applies to: 21-21
🤖 Prompt for AI Agents