Read service bindings from a file - #37
Merged
Merged
Conversation
With the file-based-vcap-services app feature enabled, Cloud Foundry sets VCAP_SERVICES_FILE_PATH and does not set VCAP_SERVICES at all, so New unmarshalled an empty string and every such app failed outright. The feature exists because bindings can exceed the environment variable size limit (RFC-0030). The file wins when both are set. Cloud Foundry never sets both, so this only decides the tie in a synthetic environment. An unreadable file is an error rather than a fall back to VCAP_SERVICES: on a file-based app that variable is unset, so falling back would hand the caller an app with no services and no explanation. The K8s service-binding form of the RFC is deliberately not implemented. It cannot be translated into VCAP_SERVICES shape. Closes #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #28.
The failure this fixes
With the
file-based-vcap-servicesapp feature enabled, Cloud Foundry setsVCAP_SERVICES_FILE_PATHand does not setVCAP_SERVICESat all.Newthen unmarshalled an empty string, so
cfenv.Current()failed outright onevery such app — not a missing convenience, a hard error.
The feature exists because bindings can exceed the environment variable size
limit (RFC-0030).
Precedence, and where it comes from
The RFC and both docs pages are silent on whether the two coexist. The Cloud
Controller presenter answers it —
app/presenters/system_environment/system_env_presenter.rbreturns early:
It never reaches the code that populates
VCAP_SERVICES. The two are mutuallyexclusive by construction, so the file winning here only decides the tie in a
synthetic environment.
Decisions
VCAP_SERVICESis unset, so falling back would hand the caller an app withno services and no explanation. The error names the variable and wraps the
underlying cause.
SERVICE_BINDING_ROOTis out of scope, as the reporter argued: thosebindings follow the servicebinding.io layout, which has no faithful
translation into
VCAP_SERVICESshape.go.modis untouched. The go directive floor bump is deliberately notbundled here.
On the gosec annotation
Reading a platform-supplied path is the entire feature, so the path is
necessarily a variable and gosec's G304 fires. The
#nosec G304is scoped tothat single line with the reason in a comment. Verified it is load-bearing —
removing it reproduces:
API impact
goreleasereports no exported API change: the helper is unexported and thisis behavior only. Backward-compatible new functionality, so v1.22.0.
Verification
make checkclean,make test-racepasses,make goseccleanVCAP_SERVICESis absent, the filewinning when both are set, a hard error on an unreadable file, malformed JSON
in the file, and the unchanged
VCAP_SERVICESpathAlso carries the
changelog.dsweep for the fragment v1.21.0 consumed.