Closed coreone closed 4 years ago
@schercav
I am using Secure_Config_Parser
from pytos/common/functions/config.py
.
Example code lifted almost entirely (with corrections) from the README
:
#!/usr/bin/env python
import logging
from pytos.common.logging.definitions import COMMON_LOGGER_NAME
from pytos.common.logging.logger import setup_loggers
from pytos.common.functions.config import Secure_Config_Parser
from pytos.securetrack.helpers import Secure_Track_Helper
conf = Secure_Config_Parser(config_file_path="/tmp/ini.conf")
logger = logging.getLogger(COMMON_LOGGER_NAME)
setup_loggers(conf.dict("log_levels"), log_to_stdout=True)
logger.info("Hello world")
print(conf)
sth = Secure_Track_Helper.from_secure_config_parser(conf)
print(sth)
Results in:
# python sth.py
Logging to STDOUT is enabled.
<pytos.common.functions.config.Secure_Config_Parser object at 0x7f449c656310>
Traceback (most recent call last):
File "sth.py", line 14, in <module>
sth = Secure_Track_Helper.from_secure_config_parser(conf)
File "/usr/local/lib/python3.7/site-packages/pytos/common/helpers.py", line 206, in from_secure_config_parser
username = secure_config_parser_obj.get_username(cls.CONFIG_PARSER_SECTION_NAME)
AttributeError: 'Secure_Config_Parser' object has no attribute 'get_username'
The configuration example file I'm using is:
[common]
log_file_path = /var/log/pytos/
[log_levels]
common = WARNING
helpers = WARNING
reports = WARNING
requests = WARNING
mail = WARNING
sql = WARNING
xml = WARNING
web = WARNING
third_party = WARNING
[securetrack]
username = theuser
password = pass
hostname = thehost
Okay, please change the commit to the development repo and I will approve the commit.
Closing to rebase on Development branch
The
get_username
andget_password
functions didn't exist, so this method wouldn't work short of subclassing and overriding the method.