-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add helper method to config.Secret to load a file #320
base: main
Are you sure you want to change the base?
Conversation
Where would this be used? When we load from file, we should get a String, not a Secret. The code path should be different: if a Secret is used directly, we should not have extra roundtrippers asking secrets every time. This helper would: generate conversion from/to Secret on every request and request that everywhere we use a secret from file, we use a getter roundtripper. |
LoadFromFile is a very small helper to avoid repeating this code over and over again. This is related to prometheus/prometheus#8551 Signed-off-by: Marcelo E. Magallon <[email protected]>
cebfad9
to
9789762
Compare
@@ -11,6 +11,7 @@ | |||
// See the License for the specific language governing permissions and | |||
// limitations under the License. | |||
|
|||
//go:build go1.8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of these are here because of linting errors...
Oops, sorry, I missed this reply among all the notifications, @roidelapluie
I think I see what you mean... In Prometheus there are two roundtrippers: one stores a static secret and the other keeps a filename and reloads the secret on every request (if the secret changes, a new roundtripper is created). If I look at So in other words, it's not enough to load the secret when marshaling YAML, something has to be added so that the knowledge of the existence of the file is preserved. But since a The thing I was trying to avoid was having code everywhere asking "does this come from a file? yes, do this; no, do this other thing". I can imagine adding a prefix to the string to signal that it's a file, not a plain string. And then add a method to return the secret (either the string or the contents of the file) as well as an indication as to whether the secret changed or not, but I also imagine that's prone to problems. What about adding an interface? The question obviously is how to migrate smoothly from the |
In order to have something concrete to talk about, I uploaded a change along those lines here: https://github.com/prometheus/common/tree/mem/secret_loader It's not even passing all unit tests, but most. It's trying to preserve the current behavior, but it will break with existing programs because the type is no longer a string but a struct. Please bear I'm mind that I have looked at this too much, so I might be missing obvious things... |
LoadFromFile is a very small helper to avoid repeating this code over
and over again.
This is related to prometheus/prometheus#8551
Signed-off-by: Marcelo E. Magallon [email protected]