@@ -122,14 +122,32 @@ def write_context(*, context: dict) -> None:
122122 yaml .dump (context , file )
123123
124124
125+ def populate_envrc () -> None :
126+ """Create and populate the .envrc file with API key."""
127+ envrc_path = Path (".envrc" )
128+ zenable_api_key = os .environ .get ("ZENABLE_API_KEY" )
129+
130+ if zenable_api_key :
131+ envrc_path .write_text (f'export API_KEY="{ zenable_api_key } "\n ' )
132+ else :
133+ envrc_path .write_text ('export API_KEY="<YOUR_ZENABLE_API_KEY>"\n ' )
134+
135+ # Restrict permissions to read-only, by the owner/current user
136+ envrc_path .chmod (0o600 )
137+
138+
125139def notify_envrc () -> None :
140+ zenable_api_key = os .environ .get ("ZENABLE_API_KEY" )
126141 print ("\n " + "=" * 70 )
127142 print ("NOTE: Environment Configuration" )
128143 print ("=" * 70 )
129144 print ("\n A .envrc file has been created in your project directory" )
130145 print ("To use services that require API keys, update the .envrc file with your keys" )
131146 print ("The .envrc file has already been added to your .gitignore" )
132147 print ("=" * 70 + "\n " )
148+ if zenable_api_key :
149+ print ("Your ZENABLE_API_KEY has been automatically populated from the environment" )
150+ print ("=" * 70 + "\n " )
133151
134152
135153def notify_dockerhub_secrets () -> None :
@@ -251,8 +269,7 @@ def run_post_gen_hook():
251269 )
252270
253271 # Create .envrc file with API key template
254- envrc_path = Path (".envrc" )
255- envrc_path .write_text ('export API_KEY="<YOUR_ZENABLE_API_KEY>"\n ' )
272+ populate_envrc ()
256273
257274 # Run the initial setup step automatically so pre-commit hooks, etc. are pre-installed. However, if it fails, don't fail the overall repo generation
258275 # (i.e. check=False)
0 commit comments