Skip to content

Conversation

@FragmentedPacket
Copy link
Contributor

@FragmentedPacket FragmentedPacket commented Oct 10, 2025

Summary by CodeRabbit

  • New Features
    • Added automatic fallback to environment variables for configuration: uses IPF_URL when base URL is missing and IPF_TOKEN when authentication is missing, storing them into settings.
  • Bug Fixes
    • Improved configuration validation: if required values are still missing after fallback, the system now raises a clear error (“Both url and auth must be specified!”), preventing silent misconfiguration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Walkthrough

Adds environment-based fallbacks in the IP Fabric sync adapter: if base_url is absent in settings, it reads IPF_URL from the environment and stores it back; if auth is absent, it reads IPF_TOKEN and stores it back. Imports os to access environment variables. After attempting fallbacks, enforces configuration by raising ValueError("Both url and auth must be specified!") if either remains missing. Adjusts control flow in _create_ipfabric_client to populate settings from environment before client creation. No changes to public APIs.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title clearly identifies the IPFabric adapter context and succinctly describes the primary change of fetching the URL and token from environment variables, which aligns directly with the code modifications.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch may-202510-ipfabric-support-env-vars

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

Deploying infrahub-sync with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7c90fec
Status: ✅  Deploy successful!
Preview URL: https://38b80744.infrahub-sync.pages.dev
Branch Preview URL: https://may-202510-ipfabric-support.infrahub-sync.pages.dev

View logs

@BeArchiTek BeArchiTek added the type/task Body of work related to an epic label Oct 10, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
infrahub_sync/adapters/ipfabricsync.py (3)

52-54: Avoid storing None when the environment variable is absent.

The current implementation stores None into settings["base_url"] when IPF_URL is not set in the environment. While this doesn't break functionality (the validation at line 61 catches it), it's unnecessary mutation of the settings dictionary.

Consider this refactor to only update settings when a value is found:

-if not base_url:
-    base_url = os.environ.get("IPF_URL", None)
-    settings["base_url"] = base_url
+if not base_url:
+    env_url = os.environ.get("IPF_URL")
+    if env_url:
+        base_url = env_url
+        settings["base_url"] = base_url

57-59: Avoid storing None when the environment variable is absent.

Same issue as with base_url: storing None into settings["auth"] when IPF_TOKEN is not set is unnecessary mutation. While functionally correct, it's cleaner to only update settings when a value is actually found.

Apply this diff:

-if not auth:
-    auth = os.environ.get("IPF_TOKEN", None)
-    settings["auth"] = auth
+if not auth:
+    env_token = os.environ.get("IPF_TOKEN")
+    if env_token:
+        auth = env_token
+        settings["auth"] = auth

52-59: Consider using constants for environment variable names.

For better maintainability and to prevent typos, consider defining constants for the environment variable names at the module level:

IPF_URL_ENV = "IPF_URL"
IPF_TOKEN_ENV = "IPF_TOKEN"

Then reference them in the code:

env_url = os.environ.get(IPF_URL_ENV)
# ...
env_token = os.environ.get(IPF_TOKEN_ENV)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac621e4 and 7c90fec.

📒 Files selected for processing (1)
  • infrahub_sync/adapters/ipfabricsync.py (2 hunks)
🔇 Additional comments (1)
infrahub_sync/adapters/ipfabricsync.py (1)

3-3: LGTM!

The os import is appropriate for accessing environment variables.

@FragmentedPacket FragmentedPacket merged commit e94d059 into main Oct 10, 2025
15 checks passed
@FragmentedPacket FragmentedPacket deleted the may-202510-ipfabric-support-env-vars branch October 10, 2025 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/task Body of work related to an epic

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants