pangea-sdk 6.1.1__py3-none-any.whl → 6.2.0b2__py3-none-any.whl

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 (54) hide show
  1. pangea/__init__.py +9 -1
  2. pangea/asyncio/__init__.py +1 -0
  3. pangea/asyncio/file_uploader.py +4 -2
  4. pangea/asyncio/request.py +199 -35
  5. pangea/asyncio/services/__init__.py +3 -0
  6. pangea/asyncio/services/ai_guard.py +91 -2
  7. pangea/asyncio/services/audit.py +307 -2
  8. pangea/asyncio/services/authn.py +12 -2
  9. pangea/asyncio/services/base.py +4 -0
  10. pangea/asyncio/services/file_scan.py +7 -1
  11. pangea/asyncio/services/intel.py +6 -2
  12. pangea/asyncio/services/management.py +576 -0
  13. pangea/asyncio/services/prompt_guard.py +112 -2
  14. pangea/asyncio/services/redact.py +269 -4
  15. pangea/asyncio/services/sanitize.py +5 -1
  16. pangea/asyncio/services/share.py +5 -1
  17. pangea/asyncio/services/vault.py +4 -0
  18. pangea/audit_logger.py +3 -1
  19. pangea/deep_verify.py +13 -13
  20. pangea/deprecated.py +1 -1
  21. pangea/dump_audit.py +2 -3
  22. pangea/exceptions.py +8 -5
  23. pangea/file_uploader.py +4 -0
  24. pangea/request.py +205 -52
  25. pangea/response.py +15 -12
  26. pangea/services/__init__.py +3 -0
  27. pangea/services/ai_guard.py +497 -16
  28. pangea/services/audit/audit.py +310 -8
  29. pangea/services/audit/models.py +279 -0
  30. pangea/services/audit/signing.py +1 -1
  31. pangea/services/audit/util.py +10 -10
  32. pangea/services/authn/authn.py +12 -2
  33. pangea/services/authn/models.py +3 -0
  34. pangea/services/authz.py +4 -0
  35. pangea/services/base.py +5 -1
  36. pangea/services/embargo.py +6 -0
  37. pangea/services/file_scan.py +7 -1
  38. pangea/services/intel.py +4 -0
  39. pangea/services/management.py +720 -0
  40. pangea/services/prompt_guard.py +193 -2
  41. pangea/services/redact.py +477 -7
  42. pangea/services/sanitize.py +5 -1
  43. pangea/services/share/share.py +13 -7
  44. pangea/services/vault/models/asymmetric.py +4 -0
  45. pangea/services/vault/models/common.py +4 -0
  46. pangea/services/vault/models/symmetric.py +4 -0
  47. pangea/services/vault/vault.py +2 -4
  48. pangea/tools.py +13 -9
  49. pangea/utils.py +3 -5
  50. pangea/verify_audit.py +23 -27
  51. {pangea_sdk-6.1.1.dist-info → pangea_sdk-6.2.0b2.dist-info}/METADATA +4 -4
  52. pangea_sdk-6.2.0b2.dist-info/RECORD +62 -0
  53. pangea_sdk-6.1.1.dist-info/RECORD +0 -60
  54. {pangea_sdk-6.1.1.dist-info → pangea_sdk-6.2.0b2.dist-info}/WHEEL +0 -0
@@ -1,9 +1,17 @@
1
1
  # Copyright 2022 Pangea Cyber Corporation
2
2
  # Author: Pangea Cyber Corporation
3
+
4
+ # TODO: Modernize.
5
+ # ruff: noqa: UP006, UP035
6
+
3
7
  from __future__ import annotations
4
8
 
5
9
  import datetime
6
- from typing import Any, Dict, Iterable, List, Optional, Sequence, Union
10
+ from collections.abc import Mapping
11
+ from typing import Any, Dict, Iterable, List, Optional, Sequence, Union, cast, overload
12
+
13
+ from pydantic import TypeAdapter
14
+ from typing_extensions import Literal
7
15
 
8
16
  import pangea.exceptions as pexc
9
17
  from pangea.asyncio.services.base import ServiceBaseAsync
@@ -12,11 +20,13 @@ from pangea.response import PangeaResponse, PangeaResponseResult
12
20
  from pangea.services.audit.audit import AuditBase
13
21
  from pangea.services.audit.exceptions import AuditException
14
22
  from pangea.services.audit.models import (
23
+ AuditSchema,
15
24
  DownloadFormat,
16
25
  DownloadRequest,
17
26
  DownloadResult,
18
27
  Event,
19
28
  ExportRequest,
29
+ ForwardingConfiguration,
20
30
  LogBulkResult,
21
31
  LogResult,
22
32
  PublishedRoot,
@@ -29,6 +39,9 @@ from pangea.services.audit.models import (
29
39
  SearchRequest,
30
40
  SearchResultOutput,
31
41
  SearchResultRequest,
42
+ ServiceConfig,
43
+ ServiceConfigFilter,
44
+ ServiceConfigListResult,
32
45
  )
33
46
  from pangea.services.audit.util import format_datetime
34
47
 
@@ -63,7 +76,7 @@ class AuditAsync(ServiceBaseAsync, AuditBase):
63
76
  token: str,
64
77
  config: PangeaConfig | None = None,
65
78
  private_key_file: str = "",
66
- public_key_info: dict[str, str] = {},
79
+ public_key_info: Mapping[str, str] = {},
67
80
  tenant_id: str | None = None,
68
81
  logger_name: str = "pangea",
69
82
  config_id: str | None = None,
@@ -590,6 +603,298 @@ class AuditAsync(ServiceBaseAsync, AuditBase):
590
603
  )
591
604
  return await self.request.post("v1/download_results", DownloadResult, data=input.model_dump(exclude_none=True))
592
605
 
606
+ async def get_service_config(self, config_id: str) -> PangeaResponse[ServiceConfig]:
607
+ """
608
+ Get a service config.
609
+
610
+ OperationId: audit_post_v1beta_config
611
+
612
+ Args:
613
+ id: The config ID
614
+ """
615
+
616
+ response = await self.request.post("v1beta/config", PangeaResponseResult, data={"id": config_id})
617
+ response.result = TypeAdapter(ServiceConfig).validate_python(response.json["result"])
618
+ return cast(PangeaResponse[ServiceConfig], response)
619
+
620
+ @overload
621
+ async def create_service_config(
622
+ self,
623
+ version: Literal[1],
624
+ name: str,
625
+ *,
626
+ cold_query_result_retention: str | None = None,
627
+ hot_storage: str | None = None,
628
+ query_result_retention: str | None = None,
629
+ redact_service_config_id: str | None = None,
630
+ redaction_fields: Sequence[str] | None = None,
631
+ retention: str | None = None,
632
+ vault_key_id: str | None = None,
633
+ vault_service_config_id: str | None = None,
634
+ vault_sign: bool | None = None,
635
+ ) -> PangeaResponse[ServiceConfig]:
636
+ """
637
+ Create a v1 service config.
638
+
639
+ OperationId: audit_post_v1beta_config_create
640
+
641
+ Args:
642
+ name: Configuration name
643
+ cold_query_result_retention: Retention window for cold query result / state information.
644
+ hot_storage: Retention window to keep audit logs in hot storage.
645
+ query_result_retention: Length of time to preserve server-side query result caching.
646
+ redact_service_config_id: A redact service config that will be used to redact PII from logs.
647
+ redaction_fields: Fields to perform redaction against.
648
+ retention: Retention window to store audit logs.
649
+ vault_key_id: ID of the Vault key used for signing. If missing, use a default Audit key.
650
+ vault_service_config_id: A vault service config that will be used to sign logs.
651
+ vault_sign: Enable/disable event signing.
652
+ """
653
+
654
+ @overload
655
+ async def create_service_config(
656
+ self,
657
+ version: Literal[2],
658
+ name: str,
659
+ *,
660
+ schema: AuditSchema,
661
+ cold_query_result_retention: str | None = None,
662
+ forwarding_configuration: ForwardingConfiguration | None = None,
663
+ hot_storage: str | None = None,
664
+ query_result_retention: str | None = None,
665
+ redact_service_config_id: str | None = None,
666
+ retention: str | None = None,
667
+ vault_key_id: str | None = None,
668
+ vault_service_config_id: str | None = None,
669
+ vault_sign: bool | None = None,
670
+ ) -> PangeaResponse[ServiceConfig]:
671
+ """
672
+ Create a v2 service config.
673
+
674
+ OperationId: audit_post_v1beta_config_create
675
+
676
+ Args:
677
+ name: Configuration name
678
+ schema: Audit log field configuration. Only settable at create time.
679
+ cold_query_result_retention: Retention window for cold query result / state information.
680
+ forwarding_configuration: Configuration for forwarding audit logs to external systems.
681
+ hot_storage: Retention window to keep audit logs in hot storage.
682
+ query_result_retention: Length of time to preserve server-side query result caching.
683
+ redact_service_config_id: A redact service config that will be used to redact PII from logs.
684
+ retention: Retention window to store audit logs.
685
+ vault_key_id: ID of the Vault key used for signing. If missing, use a default Audit key.
686
+ vault_service_config_id: A vault service config that will be used to sign logs.
687
+ vault_sign: Enable/disable event signing.
688
+ """
689
+
690
+ @overload
691
+ async def create_service_config(
692
+ self,
693
+ version: Literal[3],
694
+ name: str,
695
+ *,
696
+ schema: AuditSchema,
697
+ cold_storage: str | None = None,
698
+ hot_storage: str | None = None,
699
+ warm_storage: str | None = None,
700
+ redact_service_config_id: str | None = None,
701
+ vault_service_config_id: str | None = None,
702
+ vault_key_id: str | None = None,
703
+ vault_sign: bool | None = None,
704
+ forwarding_configuration: ForwardingConfiguration | None = None,
705
+ ) -> PangeaResponse[ServiceConfig]:
706
+ """
707
+ Create a v3 service config.
708
+
709
+ OperationId: audit_post_v1beta_config_create
710
+
711
+ Args:
712
+ name: Configuration name
713
+ schema: Audit log field configuration. Only settable at create time.
714
+ cold_storage: Retention window for logs in cold storage. Deleted afterwards.
715
+ hot_storage: Retention window for logs in hot storage. Migrated to warm, cold, or deleted afterwards.
716
+ warm_storage: Retention window for logs in warm storage. Migrated to cold or deleted afterwards.
717
+ redact_service_config_id: A redact service config that will be used to redact PII from logs.
718
+ vault_service_config_id: A vault service config that will be used to sign logs.
719
+ vault_key_id: ID of the Vault key used for signing. If missing, use a default Audit key.
720
+ vault_sign: Enable/disable event signing.
721
+ forwarding_configuration: Configuration for forwarding audit logs to external systems.
722
+ """
723
+
724
+ async def create_service_config(
725
+ self,
726
+ version: Literal[1, 2, 3],
727
+ name: str,
728
+ *,
729
+ cold_query_result_retention: str | None = None,
730
+ cold_storage: str | None = None,
731
+ forwarding_configuration: ForwardingConfiguration | None = None,
732
+ hot_storage: str | None = None,
733
+ query_result_retention: str | None = None,
734
+ redact_service_config_id: str | None = None,
735
+ redaction_fields: Sequence[str] | None = None,
736
+ retention: str | None = None,
737
+ schema: AuditSchema | None = None,
738
+ vault_key_id: str | None = None,
739
+ vault_service_config_id: str | None = None,
740
+ vault_sign: bool | None = None,
741
+ warm_storage: str | None = None,
742
+ ) -> PangeaResponse[ServiceConfig]:
743
+ """
744
+ Create a service config.
745
+
746
+ OperationId: audit_post_v1beta_config_create
747
+
748
+ Args:
749
+ name: Configuration name
750
+ cold_query_result_retention: Retention window for cold query result / state information.
751
+ cold_storage: Retention window for logs in cold storage. Deleted afterwards.
752
+ forwarding_configuration: Configuration for forwarding audit logs to external systems.
753
+ hot_storage: Retention window to keep audit logs in hot storage.
754
+ query_result_retention: Length of time to preserve server-side query result caching.
755
+ redact_service_config_id: A redact service config that will be used to redact PII from logs.
756
+ redaction_fields: Fields to perform redaction against.
757
+ retention: Retention window to store audit logs.
758
+ schema: Audit log field configuration. Only settable at create time.
759
+ vault_key_id: ID of the Vault key used for signing. If missing, use a default Audit key.
760
+ vault_service_config_id: A vault service config that will be used to sign logs.
761
+ vault_sign: Enable/disable event signing.
762
+ warm_storage: Retention window for logs in warm storage. Migrated to cold or deleted afterwards.
763
+ """
764
+
765
+ response = await self.request.post(
766
+ "v1beta/config/create",
767
+ PangeaResponseResult,
768
+ data={
769
+ "cold_query_result_retention": cold_query_result_retention,
770
+ "cold_storage": cold_storage,
771
+ "forwarding_configuration": forwarding_configuration,
772
+ "hot_storage": hot_storage,
773
+ "name": name,
774
+ "query_result_retention": query_result_retention,
775
+ "redact_service_config_id": redact_service_config_id,
776
+ "redaction_fields": redaction_fields,
777
+ "retention": retention,
778
+ "schema": schema,
779
+ "vault_key_id": vault_key_id,
780
+ "vault_service_config_id": vault_service_config_id,
781
+ "vault_sign": vault_sign,
782
+ "warm_storage": warm_storage,
783
+ "version": version,
784
+ },
785
+ )
786
+ response.result = TypeAdapter(ServiceConfig).validate_python(response.json["result"])
787
+ return cast(PangeaResponse[ServiceConfig], response)
788
+
789
+ async def update_service_config(
790
+ self,
791
+ config_id: str,
792
+ *,
793
+ name: str,
794
+ updated_at: datetime.datetime,
795
+ # Optionals.
796
+ cold_query_result_retention: str | None = None,
797
+ cold_storage: str | None = None,
798
+ forwarding_configuration: ForwardingConfiguration | None = None,
799
+ hot_storage: str | None = None,
800
+ query_result_retention: str | None = None,
801
+ redact_service_config_id: str | None = None,
802
+ retention: str | None = None,
803
+ schema: AuditSchema | None = None,
804
+ vault_key_id: str | None = None,
805
+ vault_service_config_id: str | None = None,
806
+ vault_sign: bool | None = None,
807
+ warm_storage: str | None = None,
808
+ ) -> PangeaResponse[ServiceConfig]:
809
+ """
810
+ Update a service config.
811
+
812
+ OperationId: audit_post_v1beta_config_update
813
+
814
+ Args:
815
+ id: The config ID
816
+ name: Configuration name
817
+ updated_at: The DB timestamp when this config was last updated at
818
+ cold_query_result_retention: Retention window for cold query result / state information.
819
+ cold_storage: Retention window for logs in cold storage. Deleted afterwards.
820
+ forwarding_configuration: Configuration for forwarding audit logs to external systems
821
+ hot_storage: Retention window to keep audit logs in hot storage
822
+ query_result_retention: Length of time to preserve server-side query result caching
823
+ redact_service_config_id: A redact service config that will be used to redact PII from logs
824
+ retention: Retention window to store audit logs
825
+ schema: Audit log field configuration
826
+ vault_key_id: ID of the Vault key used for signing. If missing, use a default Audit key.
827
+ vault_service_config_id: A vault service config that will be used to sign logs
828
+ vault_sign: Enable/disable event signing
829
+ warm_storage: Retention window for logs in warm storage. Migrated to cold or deleted afterwards.
830
+ """
831
+
832
+ response = await self.request.post(
833
+ "v1beta/config/update",
834
+ PangeaResponseResult,
835
+ data={
836
+ "id": config_id,
837
+ "name": name,
838
+ "updated_at": updated_at,
839
+ # Optionals.
840
+ "cold_query_result_retention": cold_query_result_retention,
841
+ "cold_storage": cold_storage,
842
+ "forwarding_configuration": forwarding_configuration,
843
+ "hot_storage": hot_storage,
844
+ "query_result_retention": query_result_retention,
845
+ "redact_service_config_id": redact_service_config_id,
846
+ "retention": retention,
847
+ "schema": schema,
848
+ "vault_key_id": vault_key_id,
849
+ "vault_service_config_id": vault_service_config_id,
850
+ "vault_sign": vault_sign,
851
+ "warm_storage": warm_storage,
852
+ },
853
+ )
854
+ response.result = TypeAdapter(ServiceConfig).validate_python(response.json["result"])
855
+ return cast(PangeaResponse[ServiceConfig], response)
856
+
857
+ async def delete_service_config(self, config_id: str) -> PangeaResponse[ServiceConfig]:
858
+ """
859
+ Delete a service config.
860
+
861
+ OperationId: audit_post_v1beta_config_delete
862
+
863
+ Args:
864
+ id: The config ID
865
+ """
866
+
867
+ response = await self.request.post("v1beta/config/delete", PangeaResponseResult, data={"id": config_id})
868
+ response.result = TypeAdapter(ServiceConfig).validate_python(response.json["result"])
869
+ return cast(PangeaResponse[ServiceConfig], response)
870
+
871
+ async def list_service_configs(
872
+ self,
873
+ *,
874
+ filter: ServiceConfigFilter | None = None,
875
+ last: str | None = None,
876
+ order: Literal["asc", "desc"] | None = None,
877
+ order_by: Literal["id", "created_at", "updated_at"] | None = None,
878
+ size: int | None = None,
879
+ ) -> PangeaResponse[ServiceConfigListResult]:
880
+ """
881
+ List service configs.
882
+
883
+ OperationId: audit_post_v1beta_config_list
884
+
885
+ Args:
886
+ last: Reflected value from a previous response to obtain the next page of results.
887
+ order: Order results asc(ending) or desc(ending).
888
+ order_by: Which field to order results by.
889
+ size: Maximum results to include in the response.
890
+ """
891
+
892
+ return await self.request.post(
893
+ "v1beta/config/list",
894
+ ServiceConfigListResult,
895
+ data={"filter": filter, "last": last, "order": order, "order_by": order_by, "size": size},
896
+ )
897
+
593
898
  async def update_published_roots(self, result: SearchResultOutput):
594
899
  """Fetches series of published root hashes from Arweave
595
900
 
@@ -1,5 +1,9 @@
1
1
  # Copyright 2022 Pangea Cyber Corporation
2
2
  # Author: Pangea Cyber Corporation
3
+
4
+ # TODO: Modernize.
5
+ # ruff: noqa: UP006, UP035
6
+
3
7
  from __future__ import annotations
4
8
 
5
9
  from typing import Dict, List, Literal, Optional, Union
@@ -995,7 +999,10 @@ class AuthNAsync(ServiceBaseAsync):
995
999
  )
996
1000
 
997
1001
  async def restart(
998
- self, flow_id: str, choice: m.FlowChoice, data: m.FlowRestartData = {}
1002
+ self,
1003
+ flow_id: str,
1004
+ choice: m.FlowChoice,
1005
+ data: m.FlowRestartData = {}, # noqa: B006
999
1006
  ) -> PangeaResponse[m.FlowRestartResult]:
1000
1007
  """
1001
1008
  Restart a sign-up/sign-in flow
@@ -1068,7 +1075,10 @@ class AuthNAsync(ServiceBaseAsync):
1068
1075
  return await self.request.post("v2/flow/start", m.FlowStartResult, data=input.model_dump(exclude_none=True))
1069
1076
 
1070
1077
  async def update(
1071
- self, flow_id: str, choice: m.FlowChoice, data: m.FlowUpdateData = {}
1078
+ self,
1079
+ flow_id: str,
1080
+ choice: m.FlowChoice,
1081
+ data: m.FlowUpdateData = {}, # noqa: B006
1072
1082
  ) -> PangeaResponse[m.FlowUpdateResult]:
1073
1083
  """
1074
1084
  Update a sign-up/sign-in flow
@@ -1,5 +1,9 @@
1
1
  # Copyright 2022 Pangea Cyber Corporation
2
2
  # Author: Pangea Cyber Corporation
3
+
4
+ # TODO: Modernize.
5
+ # ruff: noqa: UP006, UP035
6
+
3
7
  from __future__ import annotations
4
8
 
5
9
  from typing import Dict, Optional, Type, Union
@@ -1,5 +1,11 @@
1
1
  # Copyright 2022 Pangea Cyber Corporation
2
2
  # Author: Pangea Cyber Corporation
3
+
4
+ # TODO: Modernize.
5
+ # ruff: noqa: UP006, UP035
6
+
7
+ from __future__ import annotations
8
+
3
9
  import io
4
10
  import logging
5
11
  from typing import Dict, List, Optional, Tuple
@@ -98,7 +104,7 @@ class FileScanAsync(ServiceBaseAsync):
98
104
  files: Optional[List[Tuple]] = None
99
105
  if file or file_path:
100
106
  if file_path:
101
- file = open(file_path, "rb")
107
+ file = open(file_path, "rb") # noqa: SIM115
102
108
  if transfer_method == TransferMethod.POST_URL:
103
109
  params = get_file_upload_params(file) # type: ignore[arg-type]
104
110
  crc = params.crc_hex
@@ -1,5 +1,9 @@
1
1
  # Copyright 2022 Pangea Cyber Corporation
2
2
  # Author: Pangea Cyber Corporation
3
+
4
+ # TODO: Modernize.
5
+ # ruff: noqa: UP006, UP035
6
+
3
7
  import hashlib
4
8
  from typing import List, Optional
5
9
 
@@ -144,8 +148,8 @@ class FileIntelAsync(ServiceBaseAsync):
144
148
  )
145
149
  """
146
150
 
147
- data = open(filepath, "rb")
148
- hash = hashlib.sha256(data.read()).hexdigest()
151
+ with open(filepath, "rb") as data:
152
+ hash = hashlib.sha256(data.read()).hexdigest()
149
153
 
150
154
  input = m.FileReputationRequest(hash=hash, hash_type="sha256", verbose=verbose, raw=raw, provider=provider)
151
155
  return await self.request.post(