# Add Post-Retrieve Hooks Prepared by: Akash Shinde(akshinde@redhat.com), Avni Sharma(avsharma@redhat.com) ## Abstract This proposal aims to add support for custom hooks which would get executed before storing bindable variables in Secret. ## Motivation There are use cases where we would need to update/process bindable variable and then store back to secrets. One such a usecase we are going through is adding support of custom env variables. ## Design ### Architecture ![](https://i.imgur.com/xZmVAO3.png) ### Implementation Current Retrieve() call ``` func (r *Retriever) Retrieve() error { .... Run []hooks return r.saveDataOnSecret() } ``` Hook will accept the Retriever instance. ``` struct Hook interface { // This would run before storing secrets. Run(*Retriever) error } ``` Then we can implement this hook to add support custom env variables. ##### CustomEnvHook ``` struct CustomEnvHook { Hook } func (c *CustomEnvHook) Run(r *Retriever) error { // TODO: Read SBR and figure out all custom env variables to bind // Add logic to prepare [key-value] of custom variables. Update r.Data // Then r.Data gets persisted. } ``` ## Pros 1. Keeps `Retrieve` modulerized-easy to use. 2. Easy to test and maintain functional components. 3. Create re-usable, isolated components to avoid redundant logic. ## Cons 1. Implemented in a synchronized manner which might experience some delay.