polyapi-python 0.2.9__tar.gz → 0.3.1.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/PKG-INFO +1 -1
  2. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/cli.py +13 -3
  3. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/config.py +23 -5
  4. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/function_cli.py +5 -0
  5. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/utils.py +21 -1
  6. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi_python.egg-info/PKG-INFO +1 -1
  7. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/pyproject.toml +1 -1
  8. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/LICENSE +0 -0
  9. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/README.md +0 -0
  10. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/__init__.py +0 -0
  11. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/__main__.py +0 -0
  12. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/api.py +0 -0
  13. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/auth.py +0 -0
  14. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/client.py +0 -0
  15. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/constants.py +0 -0
  16. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/error_handler.py +0 -0
  17. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/exceptions.py +0 -0
  18. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/execute.py +0 -0
  19. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/generate.py +0 -0
  20. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/py.typed +0 -0
  21. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/rendered_spec.py +0 -0
  22. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/schema.py +0 -0
  23. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/server.py +0 -0
  24. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/typedefs.py +0 -0
  25. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/variables.py +0 -0
  26. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi/webhook.py +0 -0
  27. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi_python.egg-info/SOURCES.txt +0 -0
  28. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi_python.egg-info/dependency_links.txt +0 -0
  29. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi_python.egg-info/requires.txt +0 -0
  30. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/polyapi_python.egg-info/top_level.txt +0 -0
  31. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/setup.cfg +0 -0
  32. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/tests/test_api.py +0 -0
  33. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/tests/test_auth.py +0 -0
  34. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/tests/test_function_cli.py +0 -0
  35. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/tests/test_rendered_spec.py +0 -0
  36. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/tests/test_schema.py +0 -0
  37. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/tests/test_server.py +0 -0
  38. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/tests/test_utils.py +0 -0
  39. {polyapi_python-0.2.9 → polyapi_python-0.3.1.dev0}/tests/test_variables.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.9
3
+ Version: 0.3.1.dev0
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -2,7 +2,7 @@ import argparse
2
2
 
3
3
  from polyapi.utils import print_green
4
4
 
5
- from .config import clear_config, set_api_key_and_url
5
+ from .config import initialize_config, set_api_key_and_url
6
6
  from .generate import generate, clear
7
7
  from .function_cli import function_add_or_update, function_execute
8
8
  from .rendered_spec import get_and_update_rendered_spec
@@ -28,6 +28,7 @@ def execute_from_cli() -> None:
28
28
  parser.add_argument("--server", action="store_true", help="Pass --server when adding function to add a server function.")
29
29
  parser.add_argument("--logs", action="store_true", help="Pass --logs when adding function if you want to store and see the function logs.")
30
30
  parser.add_argument("--skip-generate", action="store_true", help="Pass --skip-generate to skip generating the library after adding a function.")
31
+ parser.add_argument("--execution-api-key", required=False, default="", help="API key for execution (for server functions only).")
31
32
  parser.add_argument("command", choices=CLI_COMMANDS)
32
33
  parser.add_argument("subcommands", nargs="*")
33
34
  args = parser.parse_args()
@@ -42,7 +43,7 @@ def execute_from_cli() -> None:
42
43
  elif command == "setup" and len(args.subcommands) == 2:
43
44
  set_api_key_and_url(args.subcommands[1], args.subcommands[0])
44
45
  elif command == "setup":
45
- clear_config()
46
+ initialize_config(force=True)
46
47
  generate()
47
48
  elif command == "update_rendered_spec":
48
49
  assert len(args.subcommands) == 1
@@ -59,4 +60,13 @@ def execute_from_cli() -> None:
59
60
  if args.subcommands[0] == "execute":
60
61
  print(function_execute(args.context, args.subcommands))
61
62
  else:
62
- function_add_or_update(args.context, args.description, args.client, args.server, args.logs, args.subcommands, not args.skip_generate)
63
+ function_add_or_update(
64
+ context=args.context,
65
+ description=args.description,
66
+ client=args.client,
67
+ server=args.server,
68
+ logs_enabled=args.logs,
69
+ subcommands=args.subcommands,
70
+ generate=not args.skip_generate,
71
+ execution_api_key=args.execution_api_key
72
+ )
@@ -3,6 +3,8 @@ import os
3
3
  import configparser
4
4
  from typing import Tuple
5
5
 
6
+ from polyapi.utils import is_valid_polyapi_url, is_valid_uuid, print_green, print_yellow
7
+
6
8
  # cached values
7
9
  API_KEY = None
8
10
  API_URL = None
@@ -55,18 +57,34 @@ def set_api_key_and_url(key: str, url: str):
55
57
  config.write(f)
56
58
 
57
59
 
58
- def initialize_config():
60
+ def initialize_config(force=False):
59
61
  key, url = get_api_key_and_url()
60
- if not key or not url:
62
+ if force or (not key or not url):
63
+ url = url or "https://na1.polyapi.io"
61
64
  print("Please setup your connection to PolyAPI.")
62
- url = input("? Poly API Base URL (https://na1.polyapi.io): ") or "https://na1.polyapi.io"
63
- key = input("? Poly App Key or User Key: ")
65
+ url = input(f"? Poly API Base URL ({url}): ").strip() or url
66
+
67
+ if not key:
68
+ key = input("? Poly App Key or User Key: ").strip()
69
+ else:
70
+ key_input = input(f"? Poly App Key or User Key ({key}): ").strip()
71
+ key = key_input if key_input else key
64
72
 
65
73
  if url and key:
74
+ errors = []
75
+ if not is_valid_polyapi_url(url):
76
+ errors.append(f"{url} is not a valid Poly API Base URL")
77
+ if not is_valid_uuid(key):
78
+ errors.append(f"{key} is not a valid Poly App Key or User Key")
79
+ if errors:
80
+ print_yellow("\n".join(errors))
81
+ sys.exit(1)
82
+
66
83
  set_api_key_and_url(key, url)
84
+ print_green(f"Poly setup complete.")
67
85
 
68
86
  if not key or not url:
69
- print("Poly API Key and Poly API Base URL are required.")
87
+ print_yellow("Poly API Key and Poly API Base URL are required.")
70
88
  sys.exit(1)
71
89
 
72
90
  return key, url
@@ -208,6 +208,7 @@ def function_add_or_update(
208
208
  logs_enabled: bool,
209
209
  subcommands: List,
210
210
  generate: bool = True,
211
+ execution_api_key: str = ""
211
212
  ):
212
213
  parser = argparse.ArgumentParser()
213
214
  parser.add_argument("subcommand", choices=["add"])
@@ -256,6 +257,10 @@ def function_add_or_update(
256
257
  assert api_key
257
258
  if server:
258
259
  url = f"{api_url}/functions/server"
260
+
261
+ if execution_api_key:
262
+ data["executionApiKey"] = execution_api_key
263
+
259
264
  elif client:
260
265
  url = f"{api_url}/functions/client"
261
266
  else:
@@ -1,6 +1,7 @@
1
1
  import keyword
2
2
  import re
3
3
  import os
4
+ import uuid
4
5
  from typing import Tuple, List
5
6
  from colorama import Fore, Style
6
7
  from polyapi.constants import BASIC_PYTHON_TYPES
@@ -208,4 +209,23 @@ def rewrite_reserved(s: str) -> str:
208
209
 
209
210
 
210
211
  def rewrite_arg_name(s: str):
211
- return rewrite_reserved(camelCase(s))
212
+ return rewrite_reserved(camelCase(s))
213
+
214
+
215
+ valid_subdomains = ["na[1-2]", "eu[1-2]", "dev"]
216
+
217
+
218
+ def is_valid_polyapi_url(_url: str):
219
+ # Join the subdomains into a pattern
220
+ subdomain_pattern = "|".join(valid_subdomains)
221
+ pattern = rf"^https://({subdomain_pattern})\.polyapi\.io$"
222
+ return re.match(pattern, _url) is not None
223
+
224
+
225
+ def is_valid_uuid(uuid_string, version=4):
226
+ try:
227
+ uuid_obj = uuid.UUID(uuid_string, version=version)
228
+ except ValueError:
229
+ return False
230
+
231
+ return str(uuid_obj) == uuid_string
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: polyapi-python
3
- Version: 0.2.9
3
+ Version: 0.3.1.dev0
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
3
3
 
4
4
  [project]
5
5
  name = "polyapi-python"
6
- version = "0.2.9"
6
+ version = "0.3.1.dev0"
7
7
  description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
8
8
  authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
9
9
  dependencies = [