"""Hello World: the first script to run after installing the SDK. Confirms your Barbara API Credentials are set up correctly, then says hello to your company's fleet: one call to authenticate, one call to list its nodes. Nothing else — if this doesn't work, nothing built on top of the SDK will either. Credentials are read from environment variables (BBR_API_CLIENT_ID / BBR_API_CLIENT_SECRET / BBR_API_USERNAME / BBR_API_PASSWORD), optionally loaded from a .env file first — see load_dotenv() below and README.md. """ from __future__ import annotations import argparse import os from barbara import BarbaraAuthError, BarbaraClient def load_dotenv(path: str) -> None: """Minimal .env loader (no extra dependency). Variables already set in the environment always take precedence over the file. """ if not os.path.isfile(path): return with open(path, encoding="utf-8") as fh: for line in fh: line = line.strip() if not line or line.startswith("#") or "=" not in line: continue key, _, value = line.partition("=") os.environ.setdefault(key.strip(), value.strip().strip('"').strip("'")) def main() -> None: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument( "--env-file", default=".env", help="Path to a .env file with Barbara API Credentials" ) args = parser.parse_args() load_dotenv(args.env_file) with BarbaraClient.from_env() as client: try: client.api_version() except BarbaraAuthError as exc: raise SystemExit(f"Login failed — check your Barbara API Credentials: {exc}") print("Login OK.") nodes = client.nodes.list() print(f"Hello! You have {len(nodes)} node(s) in your fleet:") for node in nodes: print(f" - {node.node_name} ({node.id}) status={node.status}") if __name__ == "__main__": main()