Skip to content

Commit 8bc78ea

Browse files
authored
Merge pull request #45 from elimity-com/feature/44-new-connector-framework
Support endpoints for new connector framework
2 parents c16b27f + 3eda787 commit 8bc78ea

3 files changed

Lines changed: 7 additions & 160 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Insights server.
55

66
## Usage
77

8-
```python
8+
```python3
99
from datetime import datetime
1010

1111
from elimity_insights_client import Client, Config, ConnectorLog, Level
@@ -30,4 +30,5 @@ $ pip install git+https://github.com/elimity-com/insights-client-python.git
3030

3131
| Client version | Insights version |
3232
| -------------- | ---------------- |
33-
| 1 | ^2.8 |
33+
| 1 | 2.8 - 2.10 |
34+
| 2 | ^2.11 |

elimity_insights_client.py

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ class AttributeAssignment:
2727
value: "Value"
2828

2929

30-
@dataclass
31-
class AttributeType:
32-
"""Attribute type for an entity type."""
33-
34-
description: str
35-
entity_type: str
36-
name: str
37-
type: "Type"
38-
39-
4030
@dataclass
4131
class BooleanValue:
4232
"""Value to assign for a boolean attribute type."""
@@ -59,27 +49,15 @@ def __init__(self, config: "Config") -> None:
5949
"""Return a new client with the given configuration."""
6050
self._config = config
6151

62-
def create_attribute_type(self, type_: AttributeType) -> None:
63-
"""Create a new attribute type."""
64-
body = _encode_attribute_type(type_)
65-
self._post(body, "attributeTypes")
66-
6752
def create_connector_logs(self, logs: Iterable["ConnectorLog"]) -> None:
6853
"""Create connector logs."""
6954
body = map(_encode_connector_log, logs)
70-
self._post(body, "connectorLogs")
71-
72-
def create_relationship_attribute_type(
73-
self, type_: "RelationshipAttributeType"
74-
) -> None:
75-
"""Create a new relationship attribute type."""
76-
body = _encode_relationship_attribute_type(type_)
77-
self._post(body, "relationshipAttributeTypes")
55+
self._post(body, "custom-connector-logs")
7856

7957
def reload_domain_graph(self, graph: "DomainGraph") -> None:
8058
"""Reload a domain graph."""
8159
body = _encode_domain_graph(graph)
82-
self._post(body, "domain-graph/reload")
60+
self._post(body, "custom-connector-domain-graphs")
8361

8462
def _post(self, body: Any, path: str) -> None:
8563
data = _encode(body)
@@ -176,17 +154,6 @@ class Relationship:
176154
to_entity_type: str
177155

178156

179-
@dataclass
180-
class RelationshipAttributeType:
181-
"""Attribute type for relationships between entities of specific types."""
182-
183-
description: str
184-
from_entity_type: str
185-
name: str
186-
to_entity_type: str
187-
type: "Type"
188-
189-
190157
@dataclass
191158
class StringValue:
192159
"""Value to assign for a string attribute type."""
@@ -201,17 +168,6 @@ class TimeValue:
201168
value: time
202169

203170

204-
class Type(Enum):
205-
"""Type of an attribute type, determining valid assignment values."""
206-
207-
BOOLEAN = auto()
208-
DATE = auto()
209-
DATE_TIME = auto()
210-
NUMBER = auto()
211-
STRING = auto()
212-
TIME = auto()
213-
214-
215171
Value = Union[
216172
BooleanValue, DateValue, DateTimeValue, NumberValue, StringValue, TimeValue
217173
]
@@ -249,16 +205,6 @@ def _encode_attribute_assignment(assignment: AttributeAssignment) -> Any:
249205
}
250206

251207

252-
def _encode_attribute_type(type_: AttributeType) -> Any:
253-
type__ = _encode_type(type_.type)
254-
return {
255-
"category": type_.entity_type,
256-
"description": type_.description,
257-
"name": type_.name,
258-
"type": type__,
259-
}
260-
261-
262208
def _encode_bool(bool_: bool) -> Any:
263209
return "true" if bool_ else "false"
264210

@@ -327,17 +273,6 @@ def _encode_relationship(relationship: Relationship) -> Any:
327273
}
328274

329275

330-
def _encode_relationship_attribute_type(type_: RelationshipAttributeType) -> Any:
331-
type__ = _encode_type(type_.type)
332-
return {
333-
"childType": type_.to_entity_type,
334-
"description": type_.description,
335-
"name": type_.name,
336-
"parentType": type_.from_entity_type,
337-
"type": type__,
338-
}
339-
340-
341276
def _encode_time(time_: time) -> Any:
342277
datetime_ = datetime(
343278
2000, 1, 1, time_.hour, time_.minute, time_.second, tzinfo=time_.tzinfo,
@@ -346,21 +281,6 @@ def _encode_time(time_: time) -> Any:
346281
return f"{datetime__:%H:%M:%S}Z"
347282

348283

349-
def _encode_type(type_: Type) -> Any:
350-
if type_ == Type.BOOLEAN:
351-
return "boolean"
352-
elif type_ == Type.DATE:
353-
return "date"
354-
elif type_ == Type.DATE_TIME:
355-
return "dateTime"
356-
elif type_ == Type.NUMBER:
357-
return "number"
358-
elif type_ == Type.STRING:
359-
return "string"
360-
else:
361-
return "time"
362-
363-
364284
def _encode_value(value: Value) -> Any:
365285
if isinstance(value, BooleanValue):
366286
boolean_value = _encode_bool(value.value)

test_elimity_insights_client.py

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
from elimity_insights_client import (
1616
Client,
1717
Config,
18-
AttributeType,
19-
Type,
20-
RelationshipAttributeType,
2118
Relationship,
2219
Entity,
2320
DomainGraph,
@@ -34,13 +31,6 @@
3431

3532

3633
class TestClient(TestCase):
37-
def test_create_attribute_type(self) -> None:
38-
type_ = AttributeType(
39-
description="foo", entity_type="bar", name="baz", type=Type.BOOLEAN
40-
)
41-
with _create_client(_CreateAttributeTypeHandler) as client:
42-
client.create_attribute_type(type_)
43-
4434
def test_create_connector_logs(self) -> None:
4535
logs = [
4636
ConnectorLog(
@@ -58,17 +48,6 @@ def test_create_connector_logs(self) -> None:
5848
with _create_client(_CreateConnectorLogsHandler) as client:
5949
client.create_connector_logs(logs_iter)
6050

61-
def test_create_relationship_attribute_type(self) -> None:
62-
type_ = RelationshipAttributeType(
63-
description="foo",
64-
from_entity_type="bar",
65-
name="baz",
66-
to_entity_type="asd",
67-
type=Type.DATE_TIME,
68-
)
69-
with _create_client(_CreateRelationshipAttributeTypeHandler) as client:
70-
client.create_relationship_attribute_type(type_)
71-
7251
def test_encode_datetime(self) -> None:
7352
# use pre-epoch local timestamp to trigger https://bugs.python.org/issue36759
7453
timestamp = datetime(1969, 1, 1)
@@ -164,37 +143,11 @@ def _decode(chunked: BinaryIO) -> Any:
164143
return loads(serialized)
165144

166145

167-
class _CreateAttributeTypeHandler(BaseHTTPRequestHandler):
168-
protocol_version = "HTTP/1.1"
169-
170-
def do_POST(self) -> None:
171-
if self.path != "/attributeTypes":
172-
self.send_error(HTTPStatus.NOT_FOUND)
173-
return
174-
175-
expected = {
176-
"category": "bar",
177-
"description": "foo",
178-
"name": "baz",
179-
"type": "boolean",
180-
}
181-
actual = _decode(self.rfile)
182-
if expected != actual:
183-
self.send_error(HTTPStatus.BAD_REQUEST)
184-
return
185-
186-
self.send_response(HTTPStatus.NO_CONTENT)
187-
self.end_headers()
188-
189-
def log_message(self, format, *args):
190-
pass
191-
192-
193146
class _CreateConnectorLogsHandler(BaseHTTPRequestHandler):
194147
protocol_version = "HTTP/1.1"
195148

196149
def do_POST(self) -> None:
197-
if self.path != "/connectorLogs":
150+
if self.path != "/custom-connector-logs":
198151
self.send_error(HTTPStatus.NOT_FOUND)
199152
return
200153

@@ -222,33 +175,6 @@ def log_message(self, format, *args):
222175
pass
223176

224177

225-
class _CreateRelationshipAttributeTypeHandler(BaseHTTPRequestHandler):
226-
protocol_version = "HTTP/1.1"
227-
228-
def do_POST(self) -> None:
229-
if self.path != "/relationshipAttributeTypes":
230-
self.send_error(HTTPStatus.NOT_FOUND)
231-
return
232-
233-
expected = {
234-
"childType": "asd",
235-
"description": "foo",
236-
"name": "baz",
237-
"parentType": "bar",
238-
"type": "dateTime",
239-
}
240-
actual = _decode(self.rfile)
241-
if expected != actual:
242-
self.send_error(HTTPStatus.BAD_REQUEST)
243-
return
244-
245-
self.send_response(HTTPStatus.NO_CONTENT)
246-
self.end_headers()
247-
248-
def log_message(self, format, *args) -> None:
249-
pass
250-
251-
252178
class _EncodeDatetimeHandler(BaseHTTPRequestHandler):
253179
protocol_version = "HTTP/1.1"
254180

@@ -267,7 +193,7 @@ class _ReloadDomainGraphHandler(BaseHTTPRequestHandler):
267193
protocol_version = "HTTP/1.1"
268194

269195
def do_POST(self) -> None:
270-
if self.path != "/domain-graph/reload":
196+
if self.path != "/custom-connector-domain-graphs":
271197
self.send_error(HTTPStatus.NOT_FOUND)
272198
return
273199

0 commit comments

Comments
 (0)