I have some information stored in a file the buildout directory / package root. When I try to access this file e.g. via configparser this works only in debug mode (local development with ./bin/instance fg):
from configparser import ConfigParser
config = ConfigParser()
I've also tried to open the file via open:
I'm pretty sure this worked in the past. Setup is Plone 6 coredev. Both works with instance in foreground but not on production. What's the trick to archive this? Or as an option: Is there a better approach to store and access sensible information which I don't want to have in my code repository?
You implicitly tell us that the file access does not work in production mode but without telling how this "does not work" looks like in detail. Do you get an exception? Then the exception should give valuable insights.
Sorry for not being specific. I expected somehow a new security feature known by everybody except me. Anyway...
configparser fails silently. There is no exception or error message if it can not read the given file. What ever you do later with the expected string fails in this case.
open says a little bit more:
Traceback (innermost last):
Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
Module ZPublisher.WSGIPublisher, line 376, in publish_module
Module ZPublisher.WSGIPublisher, line 279, in publish
Module ZPublisher.mapply, line 85, in mapply
Module ZPublisher.WSGIPublisher, line 68, in call_object
Module my.package.browser.project, line 28, in __call__
FileNotFoundError: [Errno 2] No such file or directory: 'file.ini'
I also played around with os.listdir today to check if I am in the correct place. When I start the instance in fg with ./bin/instance fg my working directory is the package root. When I start the instance regular with ./bin/instance start my directory is in parts/instance where those files are clearly not located.
I wasn't aware of that so my initial questions is wrong. Here is a possible solution for my problem: