dn-scribe commited on
Commit
6ef6bfa
·
unverified ·
1 Parent(s): 39e0261

feat: support SCRIBE_TOKEN env

Browse files
Files changed (2) hide show
  1. README.md +7 -0
  2. scribe_python_client/cli.py +10 -5
README.md CHANGED
@@ -20,6 +20,13 @@ The package includes a CLI tool for quick interactions. After installation, you
20
  scribe-client --api_call get-products --api_token YOUR_API_TOKEN
21
  ```
22
 
 
 
 
 
 
 
 
23
  ### Library Usage
24
 
25
  You can also use the library programmatically in your Python code:
 
20
  scribe-client --api_call get-products --api_token YOUR_API_TOKEN
21
  ```
22
 
23
+ Alternatively, you can set the `SCRIBE_TOKEN` environment variable to avoid passing the `--api_token` argument:
24
+
25
+ ```bash
26
+ export SCRIBE_TOKEN=YOUR_API_TOKEN
27
+ scribe-client --api_call get-products
28
+ ```
29
+
30
  ### Library Usage
31
 
32
  You can also use the library programmatically in your Python code:
scribe_python_client/cli.py CHANGED
@@ -1,8 +1,11 @@
1
  import argparse
 
2
  import logging
3
  from .client import ScribeClient
4
 
5
  def main():
 
 
6
  parser = argparse.ArgumentParser(description="Scribe Client CLI")
7
  parser.add_argument("--api_call", choices=[
8
  "get-products",
@@ -13,21 +16,23 @@ def main():
13
  "get-product-vulnerabilities",
14
  "get-latest-attestation"
15
  ], help="Which API call to execute")
16
- parser.add_argument("--api_token", required=False, default=None, help="Your API token from ScribeHub integrations page")
17
  parser.add_argument("--env", default="prod", choices=["prod", "dev", "test", "ci"], help="Which environment to use")
18
 
19
  args = parser.parse_args()
20
 
 
 
 
 
21
  base_url = "https://api.scribesecurity.com"
22
  if args.env != "prod":
23
  base_url = f"https://api.{args.env}.scribesecurity.com"
24
 
25
- if not args.api_token:
26
- logging.error("No API token provided")
27
- exit()
28
-
29
  client = ScribeClient(api_token=args.api_token, base_url=base_url)
30
 
 
 
31
  if args.api_call == "get-products":
32
  print(client.get_products_str())
33
  elif args.api_call == "get-datasets":
 
1
  import argparse
2
+ import os
3
  import logging
4
  from .client import ScribeClient
5
 
6
  def main():
7
+ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
8
+
9
  parser = argparse.ArgumentParser(description="Scribe Client CLI")
10
  parser.add_argument("--api_call", choices=[
11
  "get-products",
 
16
  "get-product-vulnerabilities",
17
  "get-latest-attestation"
18
  ], help="Which API call to execute")
19
+ parser.add_argument("--api_token", required=False, default=os.getenv('SCRIBE_TOKEN'), help="Your API token from ScribeHub integrations page (defaults to SCRIBE_TOKEN environment variable)")
20
  parser.add_argument("--env", default="prod", choices=["prod", "dev", "test", "ci"], help="Which environment to use")
21
 
22
  args = parser.parse_args()
23
 
24
+ if not args.api_token:
25
+ logging.error("No API token provided. Please set the SCRIBE_TOKEN environment variable or pass --api_token.")
26
+ exit(1)
27
+
28
  base_url = "https://api.scribesecurity.com"
29
  if args.env != "prod":
30
  base_url = f"https://api.{args.env}.scribesecurity.com"
31
 
 
 
 
 
32
  client = ScribeClient(api_token=args.api_token, base_url=base_url)
33
 
34
+ logging.info(f"Executing API call: {args.api_call}")
35
+
36
  if args.api_call == "get-products":
37
  print(client.get_products_str())
38
  elif args.api_call == "get-datasets":