Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
hooks:
- id: ruff-check
types_or: [ python, pyi, jupyter ]
args: [ --fix, -v ]
args: [ --fix ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -24,7 +24,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/lycheeverse/lychee
rev: 92a9bca23f7a16124315d49f5b5e334311e29356 # frozen: nightly
rev: 696a7cafc842c2c7728a3808b5ac5666bb3b652c # frozen: nightly
hooks:
- id: lychee-docker
# Keep all other configs in the config file
Expand Down
21 changes: 19 additions & 2 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,32 @@ def write_context(*, context: dict) -> None:
yaml.dump(context, file)


def populate_envrc() -> None:
"""Create and populate the .envrc file with API key."""
envrc_path = Path(".envrc")
zenable_api_key = os.environ.get("ZENABLE_API_KEY")

if zenable_api_key:
envrc_path.write_text(f'export API_KEY="{zenable_api_key}"\n')
Comment thread
JonZeolla marked this conversation as resolved.
else:
envrc_path.write_text('export API_KEY="<YOUR_ZENABLE_API_KEY>"\n')

# Restrict permissions to read-only, by the owner/current user
envrc_path.chmod(0o600)


def notify_envrc() -> None:
zenable_api_key = os.environ.get("ZENABLE_API_KEY")
print("\n" + "=" * 70)
print("NOTE: Environment Configuration")
print("=" * 70)
print("\nA .envrc file has been created in your project directory")
print("To use services that require API keys, update the .envrc file with your keys")
print("The .envrc file has already been added to your .gitignore")
print("=" * 70 + "\n")
if zenable_api_key:
print("Your ZENABLE_API_KEY has been automatically populated from the environment")
print("=" * 70 + "\n")


def notify_dockerhub_secrets() -> None:
Expand Down Expand Up @@ -251,8 +269,7 @@ def run_post_gen_hook():
)

# Create .envrc file with API key template
envrc_path = Path(".envrc")
envrc_path.write_text('export API_KEY="<YOUR_ZENABLE_API_KEY>"\n')
populate_envrc()

# 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
# (i.e. check=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
hooks:
- id: ruff-check
types_or: [ python, pyi, jupyter ]
args: [ --fix, -v ]
args: [ --fix ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -23,7 +23,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/lycheeverse/lychee
rev: 92a9bca23f7a16124315d49f5b5e334311e29356 # frozen: nightly
rev: 696a7cafc842c2c7728a3808b5ac5666bb3b652c # frozen: nightly
hooks:
- id: lychee-docker
# Keep all other configs in the config file
Expand Down
Loading