Read access to (some) spin.toml's value from components(applications)
To read a file from my (sub)component in a Rust project, I need to specify its path starting from the very beginning of the project. (not component but from spin root project)
let reader = maxminddb::Reader::open_readfile(
"geoip/geodb/GeoLite2-City.mmdb"
).unwrap();
If I can read its working directory from spin.toml (component.build.workdir), I can make its file path more neutral with respect to the component's name (i.e., "{component.build.workdir}/geodb/GeoLite2-City.mmdb").
Additionally, allowing the application to read 'id,' 'workdir,' 'files,' 'allowed_http_hosts,' and 'route' from spin's component section would provide more flexibility and creativity for spin users.
I have also run into cases where having some metadata from the spin.toml available to the component would be nice. The case I ran into while I was building KV/SQLite explorer apps was that it would be nice to have access to the list of DBs/stores available to the component so that they can be exposed on the UI. It can also used to provide advance warning messages on UI without having to attempt to open the store if no stores are available.
Exploring this a little further - Do we think that components must have access to all the configurations in the spin.toml for that component or do we think that a restricted subset of it would be sufficient?
I kept sending a request object to other functions to retrieve various pieces of environment information (such as project details, URLs, etc.), or I needed to store the request object in a global location. It was quite inconvenient. If I could directly retrieve some basic information from spin.toml, it would be much simpler.
Opening all configurations may seem risky, but we definitely have some very common information that can be safely shared.