Skip to content

Commit 779544d

Browse files
authored
feat(mcp): pull API keys from environment at setup time (#36)
1 parent 1982a95 commit 779544d

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ repos:
66
hooks:
77
- id: ruff-check
88
types_or: [ python, pyi, jupyter ]
9-
args: [ --fix, -v ]
9+
args: [ --fix ]
1010
- id: ruff-format
1111
types_or: [ python, pyi, jupyter ]
1212
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -24,7 +24,7 @@ repos:
2424
- id: end-of-file-fixer
2525
- id: trailing-whitespace
2626
- repo: https://github.com/lycheeverse/lychee
27-
rev: 92a9bca23f7a16124315d49f5b5e334311e29356 # frozen: nightly
27+
rev: 696a7cafc842c2c7728a3808b5ac5666bb3b652c # frozen: nightly
2828
hooks:
2929
- id: lychee-docker
3030
# Keep all other configs in the config file

hooks/post_gen_project.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
125139
def 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("\nA .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

135153
def 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)

{{cookiecutter.project_name|replace(" ", "")}}/.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repos:
55
hooks:
66
- id: ruff-check
77
types_or: [ python, pyi, jupyter ]
8-
args: [ --fix, -v ]
8+
args: [ --fix ]
99
- id: ruff-format
1010
types_or: [ python, pyi, jupyter ]
1111
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -23,7 +23,7 @@ repos:
2323
- id: end-of-file-fixer
2424
- id: trailing-whitespace
2525
- repo: https://github.com/lycheeverse/lychee
26-
rev: 92a9bca23f7a16124315d49f5b5e334311e29356 # frozen: nightly
26+
rev: 696a7cafc842c2c7728a3808b5ac5666bb3b652c # frozen: nightly
2727
hooks:
2828
- id: lychee-docker
2929
# Keep all other configs in the config file

0 commit comments

Comments
 (0)