-
Notifications
You must be signed in to change notification settings - Fork 29
Added a session token auth method to rf_diagnostic_data #182
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
3fb1792
25e54a1
78cc94f
73aecd4
b1dd447
1f56b37
b8c1c2f
52c0eea
6f36a46
0c8aca7
20e13fc
5b83932
a7ba74b
158351e
f9da079
54df429
33010c5
7d1c19d
a8c6563
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,57 @@ | ||
#! /usr/bin/python | ||
# Copyright Notice: | ||
# Copyright 2019-2025 DMTF. All rights reserved. | ||
# License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/Redfish-Tacklebox/blob/main/LICENSE.md | ||
|
||
""" | ||
Argument parser | ||
|
||
File : arguments.py | ||
|
||
Brief : A single location for arguments to pull from rather than having them defined in a bunch of places | ||
""" | ||
|
||
|
||
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 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. Okay, I'm back to this. Sorry it took me so long. I believe I added back the existing --debug functionality in diagnostic_data. I may have misunderstood you though. |
||
"--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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#! /usr/bin/python | ||
# Copyright Notice: | ||
# Copyright 2019-2025 DMTF. All rights reserved. | ||
# License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/Redfish-Tacklebox/blob/main/LICENSE.md | ||
|
||
""" | ||
Logger | ||
File : logger.py | ||
Brief : Contains a unified logger that can be referenced from other files | ||
""" | ||
|
||
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( | ||
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. It looks like the |
||
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 |
Uh oh!
There was an error while loading. Please reload this page.