permiscope 2.2.0__tar.gz → 2.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: permiscope
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: Dependency-free Python client for the Permiscope governance sidecar
5
5
  Author: Shubham Sharma
6
6
  License-Expression: MIT
@@ -46,8 +46,12 @@ decision = scope.decide("run_command", {"command": "echo hello"})
46
46
  if scope.allowed("read_file", {"path": "config.json"}):
47
47
  ...
48
48
 
49
- result = scope.execute("run_command", {"command": "echo governed"})
50
- print(result["decision"], result["success"])
49
+ result = scope.execute(
50
+ "run_command",
51
+ {"command": "echo governed"},
52
+ idempotency_key="operation-1",
53
+ )
54
+ print(result["decision"], result["success"], result.get("outcome"))
51
55
  ```
52
56
 
53
57
  Run the complete example from a checkout with
@@ -34,8 +34,12 @@ decision = scope.decide("run_command", {"command": "echo hello"})
34
34
  if scope.allowed("read_file", {"path": "config.json"}):
35
35
  ...
36
36
 
37
- result = scope.execute("run_command", {"command": "echo governed"})
38
- print(result["decision"], result["success"])
37
+ result = scope.execute(
38
+ "run_command",
39
+ {"command": "echo governed"},
40
+ idempotency_key="operation-1",
41
+ )
42
+ print(result["decision"], result["success"], result.get("outcome"))
39
43
  ```
40
44
 
41
45
  Run the complete example from a checkout with
@@ -43,9 +43,19 @@ class Permiscope:
43
43
  action_name: str,
44
44
  parameters: Optional[Dict[str, Any]] = None,
45
45
  reason: Optional[str] = None,
46
+ idempotency_key: Optional[str] = None,
46
47
  ) -> Dict[str, Any]:
47
- """Ask the sidecar to govern and execute a built-in action."""
48
- return self._post("/v1/execute", self._payload(action_name, parameters, reason))
48
+ """Ask the sidecar to govern and execute a built-in action.
49
+
50
+ ``idempotency_key`` binds a retry to the same request contents. Reusing
51
+ the key for a different action or parameters returns HTTP 409.
52
+ """
53
+ headers = {"Idempotency-Key": idempotency_key} if idempotency_key else None
54
+ return self._post(
55
+ "/v1/execute",
56
+ self._payload(action_name, parameters, reason),
57
+ headers=headers,
58
+ )
49
59
 
50
60
  def allowed(
51
61
  self,
@@ -69,13 +79,19 @@ class Permiscope:
69
79
  payload["reason"] = reason
70
80
  return payload
71
81
 
72
- def _post(self, path: str, payload: Dict[str, Any]) -> Dict[str, Any]:
82
+ def _post(
83
+ self,
84
+ path: str,
85
+ payload: Dict[str, Any],
86
+ headers: Optional[Dict[str, str]] = None,
87
+ ) -> Dict[str, Any]:
73
88
  request = urllib.request.Request(
74
89
  self.base_url + path,
75
90
  data=json.dumps(payload).encode("utf-8"),
76
91
  headers={
77
92
  "Content-Type": "application/json",
78
93
  "Authorization": f"Bearer {self.token}",
94
+ **(headers or {}),
79
95
  },
80
96
  method="POST",
81
97
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: permiscope
3
- Version: 2.2.0
3
+ Version: 2.2.1
4
4
  Summary: Dependency-free Python client for the Permiscope governance sidecar
5
5
  Author: Shubham Sharma
6
6
  License-Expression: MIT
@@ -46,8 +46,12 @@ decision = scope.decide("run_command", {"command": "echo hello"})
46
46
  if scope.allowed("read_file", {"path": "config.json"}):
47
47
  ...
48
48
 
49
- result = scope.execute("run_command", {"command": "echo governed"})
50
- print(result["decision"], result["success"])
49
+ result = scope.execute(
50
+ "run_command",
51
+ {"command": "echo governed"},
52
+ idempotency_key="operation-1",
53
+ )
54
+ print(result["decision"], result["success"], result.get("outcome"))
51
55
  ```
52
56
 
53
57
  Run the complete example from a checkout with
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "permiscope"
7
- version = "2.2.0"
7
+ version = "2.2.1"
8
8
  description = "Dependency-free Python client for the Permiscope governance sidecar"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
File without changes