Skip to content

Commit b0bfe0c

Browse files
committed
feat(mcp): pull API keys from environment at setup time
1 parent 1982a95 commit b0bfe0c

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

hooks/post_gen_project.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,29 @@ 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+
125136
def notify_envrc() -> None:
137+
zenable_api_key = os.environ.get("ZENABLE_API_KEY")
126138
print("\n" + "=" * 70)
127139
print("NOTE: Environment Configuration")
128140
print("=" * 70)
129141
print("\nA .envrc file has been created in your project directory")
130142
print("To use services that require API keys, update the .envrc file with your keys")
131143
print("The .envrc file has already been added to your .gitignore")
132144
print("=" * 70 + "\n")
145+
if zenable_api_key:
146+
print("Your ZENABLE_API_KEY has been automatically populated from the environment")
147+
print("=" * 70 + "\n")
133148

134149

135150
def notify_dockerhub_secrets() -> None:
@@ -251,8 +266,7 @@ def run_post_gen_hook():
251266
)
252267

253268
# 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')
269+
populate_envrc()
256270

257271
# 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
258272
# (i.e. check=False)

0 commit comments

Comments
 (0)