pangea-sdk 3.8.0b1__py3-none-any.whl → 5.4.0b1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. pangea/__init__.py +1 -1
  2. pangea/asyncio/file_uploader.py +1 -1
  3. pangea/asyncio/request.py +56 -34
  4. pangea/asyncio/services/__init__.py +4 -0
  5. pangea/asyncio/services/ai_guard.py +75 -0
  6. pangea/asyncio/services/audit.py +192 -31
  7. pangea/asyncio/services/authn.py +187 -109
  8. pangea/asyncio/services/authz.py +285 -0
  9. pangea/asyncio/services/base.py +21 -2
  10. pangea/asyncio/services/embargo.py +2 -2
  11. pangea/asyncio/services/file_scan.py +24 -9
  12. pangea/asyncio/services/intel.py +108 -34
  13. pangea/asyncio/services/prompt_guard.py +73 -0
  14. pangea/asyncio/services/redact.py +72 -4
  15. pangea/asyncio/services/sanitize.py +217 -0
  16. pangea/asyncio/services/share.py +246 -73
  17. pangea/asyncio/services/vault.py +1710 -750
  18. pangea/crypto/rsa.py +135 -0
  19. pangea/deep_verify.py +7 -1
  20. pangea/dump_audit.py +9 -8
  21. pangea/request.py +87 -59
  22. pangea/response.py +49 -31
  23. pangea/services/__init__.py +4 -0
  24. pangea/services/ai_guard.py +128 -0
  25. pangea/services/audit/audit.py +205 -42
  26. pangea/services/audit/models.py +56 -8
  27. pangea/services/audit/signing.py +6 -5
  28. pangea/services/audit/util.py +3 -3
  29. pangea/services/authn/authn.py +140 -70
  30. pangea/services/authn/models.py +167 -11
  31. pangea/services/authz.py +400 -0
  32. pangea/services/base.py +39 -8
  33. pangea/services/embargo.py +2 -2
  34. pangea/services/file_scan.py +32 -15
  35. pangea/services/intel.py +157 -32
  36. pangea/services/prompt_guard.py +83 -0
  37. pangea/services/redact.py +152 -4
  38. pangea/services/sanitize.py +371 -0
  39. pangea/services/share/share.py +683 -107
  40. pangea/services/vault/models/asymmetric.py +120 -18
  41. pangea/services/vault/models/common.py +439 -141
  42. pangea/services/vault/models/keys.py +94 -0
  43. pangea/services/vault/models/secret.py +27 -3
  44. pangea/services/vault/models/symmetric.py +68 -22
  45. pangea/services/vault/vault.py +1690 -749
  46. pangea/tools.py +6 -7
  47. pangea/utils.py +16 -27
  48. pangea/verify_audit.py +270 -83
  49. {pangea_sdk-3.8.0b1.dist-info → pangea_sdk-5.4.0b1.dist-info}/METADATA +43 -35
  50. pangea_sdk-5.4.0b1.dist-info/RECORD +60 -0
  51. {pangea_sdk-3.8.0b1.dist-info → pangea_sdk-5.4.0b1.dist-info}/WHEEL +1 -1
  52. pangea_sdk-3.8.0b1.dist-info/RECORD +0 -50
pangea/tools.py CHANGED
@@ -95,7 +95,7 @@ def file_events(root_hashes: Dict[int, str], f: io.TextIOWrapper) -> Iterator[Ev
95
95
  else:
96
96
  raise ValueError("invalid data")
97
97
  except (json.JSONDecodeError, ValueError, KeyError) as e:
98
- exit_with_error(f"failed to parse line {idx}: {str(e)}")
98
+ exit_with_error(f"failed to parse line {idx}: {e!s}")
99
99
 
100
100
 
101
101
  def init_audit(token: str, domain: str) -> Audit:
@@ -108,15 +108,14 @@ def init_audit(token: str, domain: str) -> Audit:
108
108
  def make_aware_datetime(d: datetime) -> datetime:
109
109
  if d.tzinfo is None or d.tzinfo.utcoffset(d) is None:
110
110
  return d.replace(tzinfo=timezone.utc)
111
- else:
112
- return d
111
+ return d
113
112
 
114
113
 
115
114
  def filter_deep_none(data: Dict) -> Dict:
116
115
  return {k: v if not isinstance(v, Dict) else filter_deep_none(v) for k, v in data.items() if v is not None}
117
116
 
118
117
 
119
- def _load_env_var(env_var_name: str):
118
+ def _load_env_var(env_var_name: str) -> str:
120
119
  value = os.getenv(env_var_name)
121
120
  if not value:
122
121
  raise PangeaException(f"{env_var_name} env var need to be set")
@@ -124,12 +123,12 @@ def _load_env_var(env_var_name: str):
124
123
  return value
125
124
 
126
125
 
127
- def get_test_domain(environment: TestEnvironment):
126
+ def get_test_domain(environment: TestEnvironment) -> str:
128
127
  env_var_name = f"PANGEA_INTEGRATION_DOMAIN_{environment}"
129
128
  return _load_env_var(env_var_name)
130
129
 
131
130
 
132
- def get_test_token(environment: TestEnvironment):
131
+ def get_test_token(environment: TestEnvironment) -> str:
133
132
  env_var_name = f"PANGEA_INTEGRATION_TOKEN_{environment}"
134
133
  return _load_env_var(env_var_name)
135
134
 
@@ -200,7 +199,7 @@ loggers: Dict[str, bool] = {}
200
199
 
201
200
 
202
201
  def logger_set_pangea_config(logger_name: str, level=logging.DEBUG):
203
- if loggers.get(logger_name, None) is not None:
202
+ if loggers.get(logger_name) is not None:
204
203
  return
205
204
 
206
205
  loggers[logger_name] = True
pangea/utils.py CHANGED
@@ -1,13 +1,13 @@
1
+ from __future__ import annotations
2
+
1
3
  import base64
2
4
  import copy
3
5
  import datetime
4
6
  import io
5
7
  import json
6
- from collections import OrderedDict
7
8
  from hashlib import md5, new, sha1, sha256, sha512
8
- from typing import Union
9
9
 
10
- from google_crc32c import Checksum as CRC32C # type: ignore[import]
10
+ from google_crc32c import Checksum as CRC32C
11
11
  from pydantic import BaseModel
12
12
 
13
13
 
@@ -31,24 +31,13 @@ def default_encoder(obj) -> str:
31
31
  return str(obj)
32
32
 
33
33
 
34
- def str2str_b64(data: str):
35
- return base64.b64encode(data.encode("ascii")).decode("ascii")
36
-
37
-
38
- def dict_order_keys(data: dict) -> OrderedDict:
39
- if isinstance(data, dict):
40
- return OrderedDict(sorted(data.items()))
41
- else:
42
- return data
43
-
34
+ def str2str_b64(data: str, encoding: str = "utf-8") -> str:
35
+ return base64.b64encode(data.encode(encoding)).decode("ascii")
44
36
 
45
- def dict_order_keys_recursive(data: dict) -> OrderedDict:
46
- if isinstance(data, dict):
47
- for k, v in data.items():
48
- if type(v) is dict:
49
- data[k] = dict_order_keys_recursive(v)
50
37
 
51
- return data # type: ignore[return-value]
38
+ def str_b64_2bytes(data: str) -> bytes:
39
+ data += "=" * ((4 - len(data) % 4) % 4) # add padding if needed
40
+ return base64.urlsafe_b64decode(data)
52
41
 
53
42
 
54
43
  def canonicalize_nested_json(data: dict) -> dict:
@@ -77,7 +66,7 @@ def canonicalize(data: dict) -> str:
77
66
  return str(data)
78
67
 
79
68
 
80
- def hash_sha256(input: Union[str, io.BufferedReader]) -> str:
69
+ def hash_sha256(input: str | io.BufferedReader) -> str:
81
70
  # Return SHA256 hash in hex format
82
71
  hash = sha256()
83
72
  if isinstance(input, io.BufferedReader):
@@ -90,12 +79,12 @@ def hash_sha256(input: Union[str, io.BufferedReader]) -> str:
90
79
 
91
80
  input.seek(0) # restart reading
92
81
  else:
93
- hash.update(input) # type: ignore
82
+ hash.update(input.encode("utf-8"))
94
83
 
95
84
  return hash.hexdigest()
96
85
 
97
86
 
98
- def hash_sha1(input: Union[str, io.BufferedReader]) -> str:
87
+ def hash_sha1(input: str | io.BufferedReader) -> str:
99
88
  # Return SHA1 hash in hex format
100
89
  hash = sha1()
101
90
  if isinstance(input, io.BufferedReader):
@@ -108,12 +97,12 @@ def hash_sha1(input: Union[str, io.BufferedReader]) -> str:
108
97
 
109
98
  input.seek(0) # restart reading
110
99
  else:
111
- hash.update(input) # type: ignore
100
+ hash.update(input.encode("utf-8"))
112
101
 
113
102
  return hash.hexdigest()
114
103
 
115
104
 
116
- def hash_sha512(input: Union[str, io.BufferedReader]) -> str:
105
+ def hash_sha512(input: str | io.BufferedReader) -> str:
117
106
  # Return SHA512 hash in hex format
118
107
  hash = sha512()
119
108
  if isinstance(input, io.BufferedReader):
@@ -126,7 +115,7 @@ def hash_sha512(input: Union[str, io.BufferedReader]) -> str:
126
115
 
127
116
  input.seek(0) # restart reading
128
117
  else:
129
- hash.update(input) # type: ignore
118
+ hash.update(input.encode("utf-8"))
130
119
 
131
120
  return hash.hexdigest()
132
121
 
@@ -136,7 +125,7 @@ def hash_ntlm(data: str) -> str:
136
125
  return new("md4", data.encode("utf-16le")).hexdigest()
137
126
 
138
127
 
139
- def hash_md5(input: Union[str, io.BufferedReader]) -> str:
128
+ def hash_md5(input: str | io.BufferedReader) -> str:
140
129
  # Return MD5 hash in hex format
141
130
  hash = md5()
142
131
  if isinstance(input, io.BufferedReader):
@@ -150,7 +139,7 @@ def hash_md5(input: Union[str, io.BufferedReader]) -> str:
150
139
 
151
140
  input.seek(0) # restart reading
152
141
  else:
153
- hash.update(input) # type: ignore
142
+ hash.update(input.encode("utf-8"))
154
143
 
155
144
  return hash.hexdigest()
156
145