Skip to content

Commit 5a7d6a6

Browse files
committed
lint fixes
1 parent e908874 commit 5a7d6a6

18 files changed

+109
-203
lines changed

src/client/action_runs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ def __init__(self, client: PortClient):
1010

1111
async def create_global_action_run(self, action_identifier: str, **kwargs) -> ActionRun:
1212
logger.info(f"Creating global action run for: {action_identifier}")
13-
response = self._client.make_request(
14-
"POST", f"actions/{action_identifier}/runs", json=kwargs
15-
)
13+
response = self._client.make_request("POST", f"actions/{action_identifier}/runs", json=kwargs)
1614
action_run_data = response.json().get("run", response.json())
1715
return ActionRun.construct(**action_run_data)
1816

src/client/actions.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def get_action(self, action_identifier: str) -> Action:
7171
else:
7272
logger.debug("Skipping API validation for action")
7373
return Action.construct(**result)
74-
74+
7575
async def create_action(self, action_data: dict[str, Any]) -> Action:
7676
"""Create a new action"""
7777
data_json = json.dumps(action_data)
@@ -104,9 +104,7 @@ async def update_action(self, action_identifier: str, action_data: dict[str, Any
104104
logger.info(f"Updating action '{action_identifier}' in Port")
105105
logger.debug(f"Input from tool to update action: {data_json}")
106106

107-
response = self._client.make_request(
108-
"PUT", f"actions/{action_identifier}", json=action_data
109-
)
107+
response = self._client.make_request("PUT", f"actions/{action_identifier}", json=action_data)
110108
result = response.json()
111109
if not result.get("ok"):
112110
message = f"Failed to update action: {result}"
@@ -134,4 +132,4 @@ async def delete_action(self, action_identifier: str) -> bool:
134132
logger.warning(message)
135133
logger.info(f"Action '{action_identifier}' deleted from Port")
136134

137-
return True
135+
return True

src/client/client.py

Lines changed: 32 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from src.utils.user_agent import get_user_agent
2424

2525
T = TypeVar("T")
26+
27+
2628
class PortClient:
2729
"""Client for interacting with the Port API."""
2830

@@ -46,9 +48,9 @@ def __init__(
4648
client_secret=client_secret,
4749
us_region=(region == "US"),
4850
)
49-
51+
5052
self._setup_custom_headers()
51-
53+
5254
self.agent = PortAgentClient(self._client)
5355
self.blueprints = PortBlueprintClient(self._client)
5456
self.entities = PortEntityClient(self._client)
@@ -61,25 +63,23 @@ def _setup_custom_headers(self):
6163
"""Setup custom headers for all HTTP requests."""
6264
user_agent = get_user_agent()
6365
logger.debug(f"Setting User-Agent header: {user_agent}")
64-
66+
6567
original_make_request = self._client.make_request
66-
68+
6769
def make_request_with_headers(*args, **kwargs):
6870
"""Wrapper to add custom headers to all requests."""
69-
if 'headers' not in kwargs:
70-
kwargs['headers'] = {}
71-
72-
kwargs['headers']['User-Agent'] = user_agent
73-
71+
if "headers" not in kwargs:
72+
kwargs["headers"] = {}
73+
74+
kwargs["headers"]["User-Agent"] = user_agent
75+
7476
return original_make_request(*args, **kwargs)
75-
77+
7678
self._client.make_request = make_request_with_headers
7779

7880
def handle_http_error(self, e: requests.exceptions.HTTPError) -> PortError:
7981
result = e.response.json()
80-
message = (
81-
f"Error in {e.request.method} {e.request.url} - {e.response.status_code}: {result}"
82-
)
82+
message = f"Error in {e.request.method} {e.request.url} - {e.response.status_code}: {result}"
8383
logger.error(message)
8484
raise PortError(message)
8585

@@ -110,99 +110,63 @@ async def update_blueprint(self, blueprint_data: dict[str, Any]) -> Blueprint:
110110
return await self.wrap_request(lambda: self.blueprints.update_blueprint(blueprint_data))
111111

112112
async def delete_blueprint(self, blueprint_identifier: str) -> bool:
113-
return await self.wrap_request(
114-
lambda: self.blueprints.delete_blueprint(blueprint_identifier)
115-
)
113+
return await self.wrap_request(lambda: self.blueprints.delete_blueprint(blueprint_identifier))
116114

117115
async def get_entity(self, blueprint_identifier: str, entity_identifier: str) -> EntityResult:
118-
return await self.wrap_request(
119-
lambda: self.entities.get_entity(blueprint_identifier, entity_identifier)
120-
)
116+
return await self.wrap_request(lambda: self.entities.get_entity(blueprint_identifier, entity_identifier))
121117

122118
async def get_entities(self, blueprint_identifier: str) -> list[EntityResult]:
123119
return await self.wrap_request(lambda: self.entities.get_entities(blueprint_identifier))
124120

125121
async def search_entities(self, blueprint_identifier: str, search_query: dict[str, Any]) -> list[EntityResult]:
126122
return await self.wrap_request(lambda: self.entities.search_entities(blueprint_identifier, search_query))
127123

128-
async def create_entity(
129-
self, blueprint_identifier: str, entity_data: dict[str, Any], query: dict[str, Any]
130-
) -> EntityResult:
131-
return await self.wrap_request(
132-
lambda: self.entities.create_entity(blueprint_identifier, entity_data, query)
133-
)
124+
async def create_entity(self, blueprint_identifier: str, entity_data: dict[str, Any], query: dict[str, Any]) -> EntityResult:
125+
return await self.wrap_request(lambda: self.entities.create_entity(blueprint_identifier, entity_data, query))
134126

135-
async def update_entity(
136-
self, blueprint_identifier: str, entity_identifier: str, entity_data: dict[str, Any]
137-
) -> EntityResult:
138-
return await self.wrap_request(
139-
lambda: self.entities.update_entity(
140-
blueprint_identifier, entity_identifier, entity_data
141-
)
142-
)
127+
async def update_entity(self, blueprint_identifier: str, entity_identifier: str, entity_data: dict[str, Any]) -> EntityResult:
128+
return await self.wrap_request(lambda: self.entities.update_entity(blueprint_identifier, entity_identifier, entity_data))
143129

144-
async def delete_entity(
145-
self, blueprint_identifier: str, entity_identifier: str, delete_dependents: bool = False
146-
) -> bool:
130+
async def delete_entity(self, blueprint_identifier: str, entity_identifier: str, delete_dependents: bool = False) -> bool:
147131
return await self.wrap_request(
148-
lambda: self.entities.delete_entity(
149-
blueprint_identifier, entity_identifier, delete_dependents
150-
)
132+
lambda: self.entities.delete_entity(blueprint_identifier, entity_identifier, delete_dependents)
151133
)
152134

153135
async def get_scorecard(self, blueprint_id: str, scorecard_id: str) -> Scorecard:
154-
return await self.wrap_request(
155-
lambda: self.scorecards.get_scorecard(blueprint_id, scorecard_id)
156-
)
136+
return await self.wrap_request(lambda: self.scorecards.get_scorecard(blueprint_id, scorecard_id))
157137

158138
async def get_scorecards(self, blueprint_identifier: str) -> list[Scorecard]:
159139
return await self.wrap_request(lambda: self.scorecards.get_scorecards(blueprint_identifier))
160140

161-
async def create_scorecard(
162-
self, blueprint_id: str, scorecard_data: dict[str, Any]
163-
) -> Scorecard:
164-
return await self.wrap_request(
165-
lambda: self.scorecards.create_scorecard(blueprint_id, scorecard_data)
166-
)
141+
async def create_scorecard(self, blueprint_id: str, scorecard_data: dict[str, Any]) -> Scorecard:
142+
return await self.wrap_request(lambda: self.scorecards.create_scorecard(blueprint_id, scorecard_data))
167143

168-
async def update_scorecard(
169-
self, blueprint_id: str, scorecard_id: str, scorecard_data: dict[str, Any]
170-
) -> Scorecard:
171-
return await self.wrap_request(
172-
lambda: self.scorecards.update_scorecard(blueprint_id, scorecard_id, scorecard_data)
173-
)
144+
async def update_scorecard(self, blueprint_id: str, scorecard_id: str, scorecard_data: dict[str, Any]) -> Scorecard:
145+
return await self.wrap_request(lambda: self.scorecards.update_scorecard(blueprint_id, scorecard_id, scorecard_data))
174146

175147
async def delete_scorecard(self, scorecard_id: str, blueprint_id: str) -> bool:
176-
return await self.wrap_request(
177-
lambda: self.scorecards.delete_scorecard(scorecard_id, blueprint_id)
178-
)
148+
return await self.wrap_request(lambda: self.scorecards.delete_scorecard(scorecard_id, blueprint_id))
179149

180150
async def get_all_actions(self, trigger_type: str = "self-service") -> list[Action]:
181151
return await self.wrap_request(lambda: self.actions.get_all_actions(trigger_type))
182152

183153
async def get_action(self, action_identifier: str) -> Action:
184154
return await self.wrap_request(lambda: self.actions.get_action(action_identifier))
185-
155+
186156
async def create_action(self, action_data: dict[str, Any]) -> Action:
187157
return await self.wrap_request(lambda: self.actions.create_action(action_data))
188158

189159
async def update_action(self, action_identifier: str, action_data: dict[str, Any]) -> Action:
190-
return await self.wrap_request(
191-
lambda: self.actions.update_action(action_identifier, action_data)
192-
)
160+
return await self.wrap_request(lambda: self.actions.update_action(action_identifier, action_data))
193161

194162
async def delete_action(self, action_identifier: str) -> bool:
195163
return await self.wrap_request(lambda: self.actions.delete_action(action_identifier))
196-
164+
197165
async def create_global_action_run(self, action_identifier: str, **kwargs) -> ActionRun:
198-
return await self.wrap_request(
199-
lambda: self.action_runs.create_global_action_run(action_identifier, **kwargs)
200-
)
166+
return await self.wrap_request(lambda: self.action_runs.create_global_action_run(action_identifier, **kwargs))
201167

202168
async def create_entity_action_run(self, action_identifier: str, **kwargs) -> ActionRun:
203-
return await self.wrap_request(
204-
lambda: self.action_runs.create_entity_action_run(action_identifier, **kwargs)
205-
)
169+
return await self.wrap_request(lambda: self.action_runs.create_entity_action_run(action_identifier, **kwargs))
206170

207171
async def get_action_run(self, run_id: str) -> ActionRun:
208172
return await self.wrap_request(lambda: self.action_runs.get_action_run(run_id))

src/client/permissions.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, client: PortClient):
1616
async def get_action_permissions(self, action_identifier: str) -> dict[str, Any]:
1717
"""Get permissions configuration for a specific action."""
1818
logger.info(f"Getting permissions for action: {action_identifier}")
19-
19+
2020
try:
2121
response = self._client.make_request("GET", f"actions/{action_identifier}/permissions")
2222
result = response.json()
@@ -41,21 +41,18 @@ async def get_action_permissions(self, action_identifier: str) -> dict[str, Any]
4141
async def update_action_policies(self, action_identifier: str, policies: dict[str, Any]) -> dict[str, Any]:
4242
"""Update policies configuration for a specific action."""
4343
logger.info(f"Updating policies for action: {action_identifier}")
44-
44+
4545
try:
4646
# Prepare the payload for updating policies - the policies should be sent directly
4747
payload = policies
48-
48+
4949
response = self._client.make_request("PATCH", f"actions/{action_identifier}/permissions", json=payload)
5050
result = response.json()
5151
permissions = result.get("permissions", {})
5252
if result.get("ok"):
5353
updated_info = {
5454
"action_identifier": action_identifier,
55-
"updated_policies": {
56-
"execute": permissions.get("execute", {}),
57-
"approve": permissions.get("approve", {})
58-
},
55+
"updated_policies": {"execute": permissions.get("execute", {}), "approve": permissions.get("approve", {})},
5956
"success": True,
6057
}
6158
logger.info(f"Successfully updated policies for action: {action_identifier}")
@@ -75,4 +72,4 @@ async def update_action_policies(self, action_identifier: str, policies: dict[st
7572
"updated_policies": {},
7673
"success": False,
7774
"error": str(e),
78-
}
75+
}

src/models/actions/action.py

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,17 @@
1212
class ActionSchema(BaseModel):
1313
"""Schema for action inputs."""
1414

15-
properties: dict[str, Any] = Field(
16-
default_factory=dict, description="Properties schema for action inputs"
17-
)
18-
required: list[str] = Field(
19-
default_factory=list, description="Required properties for the action"
20-
)
15+
properties: dict[str, Any] = Field(default_factory=dict, description="Properties schema for action inputs")
16+
required: list[str] = Field(default_factory=list, description="Required properties for the action")
2117

2218

2319
class ActionTrigger(BaseModel):
2420
"""Action trigger configuration."""
2521

2622
type: str = Field(..., description="The type of trigger")
27-
operation: str | SkipJsonSchema[None] = Field(
28-
None, description="The operation type (CREATE, DAY-2, DELETE)"
29-
)
30-
event: str | SkipJsonSchema[None] = Field(
31-
None, description="The event that triggers the action"
32-
)
33-
condition: dict[str, Any] | SkipJsonSchema[None] = Field(
34-
None, description="Conditions for the trigger"
35-
)
23+
operation: str | SkipJsonSchema[None] = Field(None, description="The operation type (CREATE, DAY-2, DELETE)")
24+
event: str | SkipJsonSchema[None] = Field(None, description="The event that triggers the action")
25+
condition: dict[str, Any] | SkipJsonSchema[None] = Field(None, description="Conditions for the trigger")
3626
user_inputs: ActionSchema | SkipJsonSchema[None] = Field(
3727
None, description="User input schema for the trigger", alias="userInputs"
3828
)
@@ -49,12 +39,8 @@ class ActionInvocationMethodGitHub(BaseModel):
4939
repo: str = Field(..., description="GitHub repository")
5040
workflow: str = Field(..., description="GitHub workflow filename")
5141
omit_payload: bool | SkipJsonSchema[None] = Field(None, description="Whether to omit payload")
52-
omit_user_inputs: bool | SkipJsonSchema[None] = Field(
53-
None, description="Whether to omit user inputs"
54-
)
55-
report_workflow_status: bool | SkipJsonSchema[None] = Field(
56-
None, description="Whether to report workflow status"
57-
)
42+
omit_user_inputs: bool | SkipJsonSchema[None] = Field(None, description="Whether to omit user inputs")
43+
report_workflow_status: bool | SkipJsonSchema[None] = Field(None, description="Whether to report workflow status")
5844

5945

6046
class ActionInvocationMethodGitLab(BaseModel):
@@ -64,15 +50,9 @@ class ActionInvocationMethodGitLab(BaseModel):
6450
project_name: str = Field(..., description="GitLab project name", alias="projectName")
6551
group_name: str = Field(..., description="GitLab group name", alias="groupName")
6652
agent: Literal[True] = Field(..., description="Agent must be true for GitLab")
67-
omit_payload: bool | SkipJsonSchema[None] = Field(
68-
None, description="Whether to omit payload", alias="omitPayload"
69-
)
70-
omit_user_inputs: bool | SkipJsonSchema[None] = Field(
71-
None, description="Whether to omit user inputs", alias="omitUserInputs"
72-
)
73-
default_ref: str | SkipJsonSchema[None] = Field(
74-
None, description="Default Git reference", alias="defaultRef"
75-
)
53+
omit_payload: bool | SkipJsonSchema[None] = Field(None, description="Whether to omit payload", alias="omitPayload")
54+
omit_user_inputs: bool | SkipJsonSchema[None] = Field(None, description="Whether to omit user inputs", alias="omitUserInputs")
55+
default_ref: str | SkipJsonSchema[None] = Field(None, description="Default Git reference", alias="defaultRef")
7656

7757

7858
class ActionInvocationMethodAzureDevOps(BaseModel):
@@ -88,15 +68,9 @@ class ActionInvocationMethodWebhook(BaseModel):
8868

8969
type: Literal["WEBHOOK"] = Field(..., description="The type of invocation method")
9070
url: str = Field(..., description="Webhook URL")
91-
agent: bool | SkipJsonSchema[None] = Field(
92-
None, description="Whether to use agent for invocation"
93-
)
94-
synchronized: bool | SkipJsonSchema[None] = Field(
95-
None, description="Whether the webhook is synchronized"
96-
)
97-
method: Literal["POST", "DELETE", "PATCH", "PUT"] | SkipJsonSchema[None] = Field(
98-
None, description="HTTP method for webhook"
99-
)
71+
agent: bool | SkipJsonSchema[None] = Field(None, description="Whether to use agent for invocation")
72+
synchronized: bool | SkipJsonSchema[None] = Field(None, description="Whether the webhook is synchronized")
73+
method: Literal["POST", "DELETE", "PATCH", "PUT"] | SkipJsonSchema[None] = Field(None, description="HTTP method for webhook")
10074
headers: dict[str, str] | SkipJsonSchema[None] = Field(None, description="Headers for webhook")
10175
body: str | dict[str, Any] | SkipJsonSchema[None] = Field(
10276
None, description="Body template for webhook (can be string or dict)"
@@ -124,9 +98,7 @@ class ActionCommon(BaseModel):
12498

12599
identifier: str = Field(..., description="The unique identifier of the action")
126100
title: str = Field(..., description="The title of the action")
127-
description: str | SkipJsonSchema[None] = Field(
128-
None, description="The description of the action"
129-
)
101+
description: str | SkipJsonSchema[None] = Field(None, description="The description of the action")
130102
icon: Icon | SkipJsonSchema[None] = Field(None, description="The icon of the action")
131103
trigger: ActionTrigger = Field(..., description="The trigger configuration")
132104
invocation_method: ActionInvocationMethod = Field(
@@ -154,12 +126,8 @@ class ActionSummary(BaseModel):
154126

155127
identifier: str = Field(..., description="The unique identifier of the action")
156128
title: str = Field(..., description="The title of the action")
157-
description: str | SkipJsonSchema[None] = Field(
158-
None, description="The description of the action"
159-
)
160-
blueprint: str | SkipJsonSchema[None] = Field(
161-
None, description="The blueprint this action belongs to"
162-
)
129+
description: str | SkipJsonSchema[None] = Field(None, description="The description of the action")
130+
blueprint: str | SkipJsonSchema[None] = Field(None, description="The blueprint this action belongs to")
163131

164132

165133
class Action(ActionCommon):

src/models/permissions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
"GetActionPermissionsToolSchema",
99
"UpdateActionPoliciesToolResponse",
1010
"UpdateActionPoliciesToolSchema",
11-
]
11+
]

src/models/permissions/get_action_permissions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
class GetActionPermissionsToolSchema(BaseModel):
1111
"""Schema for get action permissions tool."""
12-
12+
1313
action_identifier: str = Field(description="The identifier of the action to get permissions configuration for")
1414

1515

1616
class GetActionPermissionsToolResponse(BaseModel):
1717
"""Response model for get action permissions tool."""
18-
19-
permissions: dict[str, Any] = Field(description="Permissions configuration for the action")
18+
19+
permissions: dict[str, Any] = Field(description="Permissions configuration for the action")

0 commit comments

Comments
 (0)