-
Notifications
You must be signed in to change notification settings - Fork 27
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
Added a session token auth method to rf_diagnostic_data #182
Open
brandonbiggs
wants to merge
4
commits into
DMTF:main
Choose a base branch
from
brandonbiggs:session-token
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3fb1792
Added a session token auth method to rf_diagnostic_data
25e54a1
Added a clean section to the makefile
78cc94f
Moving commonly used arguments to their own file. Also created a new …
73aecd4
Updated the make lint section to include ruff and fixed my ruff errors
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import argparse | ||
|
||
|
||
def validate_auth(args): | ||
if (args.user and args.password and not args.session_token) or ( | ||
args.session_token and not (args.user or args.password) | ||
): | ||
return | ||
else: | ||
print("You must specify both --user and --password or --session-token") | ||
quit(1) | ||
|
||
|
||
def create_parent_parser(description: str = "", auth: bool = False, rhost: bool = False): | ||
parent_parser = argparse.ArgumentParser(description=description, add_help=False) | ||
|
||
parent_parser.add_argument( | ||
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. Could we maintain parity with the existing |
||
"--log-level", | ||
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], | ||
default="INFO", | ||
help="Creates debug file showing HTTP traces and exceptions", | ||
) | ||
parent_parser.add_argument("--log-to-console", action="store_true", help="Enable logging to console") | ||
parent_parser.add_argument("--log-to-file", action="store_true", help="Enable logging to a file") | ||
parent_parser.add_argument( | ||
"--debug", action="store_true", help="Creates debug file showing HTTP traces and exceptions" | ||
) | ||
|
||
if auth: | ||
parent_parser.add_argument("--user", "-u", type=str, help="The user name for authentication") | ||
parent_parser.add_argument("--password", "-p", type=str, help="The password for authentication") | ||
parent_parser.add_argument("--session-token", "-t", type=str, help="The session token for authentication") | ||
|
||
if rhost: | ||
parent_parser.add_argument( | ||
"--rhost", "-r", type=str, required=True, help="The address of the Redfish service (with scheme)" | ||
) | ||
|
||
return parent_parser | ||
|
||
|
||
def validate_args(args): | ||
validate_auth(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import logging | ||
import datetime | ||
import redfish | ||
import os | ||
|
||
|
||
def get_debug_level(level): | ||
if level == "DEBUG": | ||
return logging.DEBUG | ||
elif level == "INFO": | ||
return logging.INFO | ||
elif level == "WARNING": | ||
return logging.WARNING | ||
elif level == "ERROR": | ||
return logging.ERROR | ||
elif level == "CRITICAL": | ||
return logging.CRITICAL | ||
else: | ||
raise ValueError(f"Invalid debug level: {level}") | ||
|
||
|
||
def setup_logger( | ||
file_log: bool = False, stream_log: bool = True, log_level: str = "INFO", file_name: str = "redfish_utils" | ||
): | ||
log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" | ||
log_level = get_debug_level(log_level) | ||
logger = logging.getLogger(__name__) | ||
|
||
if file_log: | ||
file_name = os.path.basename(file_name) | ||
timestamp = datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S") | ||
log_file = f"{file_name}-{timestamp}.log".format() | ||
logger = redfish.redfish_logger(log_file, log_format, log_level) | ||
|
||
if stream_log: | ||
formatter = logging.Formatter(log_format) | ||
sh = logging.StreamHandler() | ||
sh.setFormatter(formatter) | ||
logger.addHandler(sh) | ||
logger.setLevel(log_level) | ||
|
||
return logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'll need the DMTF copyright above this line (just need to copy/paste from another file in here).