cloakapi 1.4.1-x86_64-linux

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 (45) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +160 -0
  3. data/LICENSE +202 -0
  4. data/NOTICE +18 -0
  5. data/README.md +407 -0
  6. data/THIRD-PARTY-NOTICES.md +22 -0
  7. data/TRADEMARKS.md +19 -0
  8. data/examples/fake_gateway.rb +78 -0
  9. data/examples/hello.rb +64 -0
  10. data/lib/cloakapi/_lib/linux-x86_64/libcloak_engine.so +0 -0
  11. data/lib/cloakapi/client.rb +1272 -0
  12. data/lib/cloakapi/degraded.rb +77 -0
  13. data/lib/cloakapi/disclosure.rb +252 -0
  14. data/lib/cloakapi/engine.rb +702 -0
  15. data/lib/cloakapi/errors.rb +65 -0
  16. data/lib/cloakapi/pii/bundled_rules.rb +670 -0
  17. data/lib/cloakapi/pii/card_spans.rb +300 -0
  18. data/lib/cloakapi/pii/detector.rb +1925 -0
  19. data/lib/cloakapi/pii/patterns.json +2238 -0
  20. data/lib/cloakapi/pii/pii_match.rb +7 -0
  21. data/lib/cloakapi/pii/pii_type.rb +7 -0
  22. data/lib/cloakapi/pii/ruleset.rb +65 -0
  23. data/lib/cloakapi/pii/tokenizer.rb +411 -0
  24. data/lib/cloakapi/posture.rb +82 -0
  25. data/lib/cloakapi/receipts.rb +406 -0
  26. data/lib/cloakapi/resources/chat.rb +82 -0
  27. data/lib/cloakapi/resources/messages.rb +90 -0
  28. data/lib/cloakapi/resources/models.rb +25 -0
  29. data/lib/cloakapi/resources/receipts.rb +162 -0
  30. data/lib/cloakapi/resources/reconstruct.rb +120 -0
  31. data/lib/cloakapi/resources/request_strings.rb +485 -0
  32. data/lib/cloakapi/resources/reviewable.rb +163 -0
  33. data/lib/cloakapi/resources/tokens.rb +28 -0
  34. data/lib/cloakapi/routing/bundled-catalogue.json +107 -0
  35. data/lib/cloakapi/routing.rb +500 -0
  36. data/lib/cloakapi/streaming.rb +196 -0
  37. data/lib/cloakapi/surrogate_mode.rb +233 -0
  38. data/lib/cloakapi/version.rb +15 -0
  39. data/lib/cloakapi/warnings.rb +137 -0
  40. data/lib/cloakapi.rb +37 -0
  41. data/licenses/Apache-2.0.txt +202 -0
  42. data/licenses/CC-BY-4.0.txt +104 -0
  43. data/licenses/MIT-Faker.txt +21 -0
  44. data/licenses/MIT.txt +21 -0
  45. metadata +150 -0
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CloakAPI
4
+ class TokensCountUnavailableError < StandardError; end
5
+
6
+ class ApiError < StandardError
7
+ SAFE_CODES = %w[invalid_api_key permission_denied permission_error tokenisation_suspended
8
+ invalid_request rate_limit_exceeded not_found service_unavailable
9
+ internal_error bad_request hourly_quota_exceeded daily_quota_exceeded
10
+ quota_counter_corrupt quota_counter_unavailable insufficient_balance stream_truncated
11
+ stream_error gateway_error].freeze
12
+ SAFE_TYPES = %w[invalid_request_error authentication_error permission_error
13
+ rate_limit_error api_error server_error].freeze
14
+ attr_reader :status_code, :code, :type, :retry_after
15
+
16
+ def initialize(message, status_code, code, type, retry_after = nil)
17
+ # Response bodies and transport exception messages can echo request data.
18
+ # Keep the public message stable and content-free; only retain constrained
19
+ # protocol identifiers for programmatic handling.
20
+ safe_status = status_code.to_i
21
+ safe_code = safe_identifier(code, SAFE_CODES)
22
+ safe_type = safe_identifier(type, SAFE_TYPES)
23
+ safe_message = safe_status == 402 && safe_code == "insufficient_balance" ?
24
+ "Insufficient credit balance. Please top up your account to continue." : "CloakAPI HTTP #{safe_status}"
25
+ super(safe_message)
26
+ @status_code = safe_status
27
+ @code = safe_code
28
+ @type = safe_type
29
+ @retry_after = retry_after
30
+ end
31
+
32
+ # Returns true when the error indicates break-glass mode is active
33
+ # (HTTP 503, code = tokenisation_suspended).
34
+ def tokenisation_suspended?
35
+ status_code == 503 && code == "tokenisation_suspended"
36
+ end
37
+
38
+ private
39
+
40
+ def safe_identifier(value, allowlist)
41
+ text = value.to_s
42
+ allowlist.include?(text) ? text : ""
43
+ end
44
+ end
45
+
46
+ # Raised when the SDK could not obtain the per-body pre-tokenised passthrough
47
+ # MAC from POST /api/v1/pretokenised/mac (transport error, non-2xx, or a
48
+ # missing/empty +mac+ field). Under the Level-1-only STRICT gateway the relay
49
+ # is FAIL-LOUD: without a valid X-Cloak-Client-MAC the gateway would reject the
50
+ # call, so the SDK refuses to relay rather than send raw/unproven content —
51
+ # there is deliberately NO no-MAC fallback. Mirrors the Go PretokenisedMacError
52
+ # / Python PretokenisedMacError / TypeScript `pretokenised_mac_unavailable`.
53
+ class PretokenisedMacError < StandardError
54
+ # The underlying cause (an ApiError from the /mac endpoint, a transport
55
+ # error, or a sentinel for a missing `mac` field).
56
+ attr_reader :cause_error
57
+
58
+ def initialize(cause_error)
59
+ # Do not retain the exception object: its message/inspect/cause may hold
60
+ # request bytes or server-controlled response text.
61
+ @cause_error = nil
62
+ super("CloakAPI: could not obtain the pre-tokenised MAC; refusing to relay without proof of on-device tokenisation")
63
+ end
64
+ end
65
+ end