The only way to change it is to convert apiserver_conf
to a dictionary object ( as_plain_ordered_dict()
) and edit it
SuccessfulKoala55 this actually doesn't work
` apiserver_conf = ConfigFactory.parse_file(API_SERVER_CONF_PATH)
POINT 1
conf_content = HOCONConverter.to_hocon(config=ConfigFactory.from_dict(apiserver_conf.as_plain_ordered_dict()),
compact=False,
level=0, indent=2)
apiserver_conf['auth']['fixed_users']['users'].append(
ConfigFactory.from_dict({'username': username, 'password': password, 'name': name}))
POINT 2
new_conf_content = HOCONConverter.to_hocon(config=ConfigFactory.from_dict(apiserver_conf.as_plain_ordered_dict()),
compact=False,
level=0, indent=2) Strangely enough running this code results in
new_conf_content == conf_content to be
True . Seems like through this
ConfigTree ` object I can't really apply changes on the configuration file
Sorry my bad:config_obj['sdk']['stuff']['here'] = value
WackyRabbit7 in that case:from trains.utilities.pyhocon import ConfigFactory, HOCONConverter from trains.config import config_obj new_conf_text = HOCONConverter.to_hocon(config=ConfigFactory.from_dict(config_obj.as_plain_ordered_dict()), compact=False, level=0, indent=2) print(new_conf_text)
AgitatedDove14 permanent. I want to start with a CLI interface that allows me add users to the trains server
it will return a
Config
object right?
Will return a ConfigTree
object which behaves the same way
but using that code - how would I edit fileds?
If you need to change the values:config_obj.set(...)
You might want to edit the object on a copy, not the original 🙂
essentially editing apiserver.conf
section auth.fixed_users.users
whatttt? I looked at config_obj
didn't find any set
method
Another Q on that - does pyhocon
allows me to edit the file while keeping the comments in place?
What about:apiserver_conf.put( "auth.fixed_users.users", list(apiserver_conf.get("auth.fixed_users.users", [])) + [{'username': username, 'password': password, 'name': name}] )
it seems apiserver_conf
doesn't even change
WackyRabbit7 please note that if your aim is to edit the Server's configuration, you'll need to do that without the config_obj
loaded by Trains
Since your aim is to end up with content you can paste into apiserver.conf
(which is not loaded by Trains)
However, that can easily be done using ConfigFactory.parse_file("apiserver.conf")