Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update to entity, relationship, relationship type and signal in the Python SDK #39

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ disable=duplicate-code,
too-many-arguments,
too-many-locals,
too-many-return-statements,
unsubscriptable-object # Due to a pylint bug which appears when run with Python 3.9.
too-many-instance-attributes,

[BASIC]

Expand Down
496 changes: 301 additions & 195 deletions Pipfile.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions exabel_data_sdk/client/api/api_client/entity_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ListEntityTypesResponse,
SearchEntitiesRequest,
SearchEntitiesResponse,
UpdateEntityRequest,
)


Expand Down Expand Up @@ -41,6 +42,10 @@ def get_entity(self, request: GetEntityRequest) -> Entity:
def create_entity(self, request: CreateEntityRequest) -> Entity:
"""Create an entity."""

@abstractmethod
def update_entity(self, request: UpdateEntityRequest) -> Entity:
"""Update an entity."""

@abstractmethod
def delete_entity(self, request: DeleteEntityRequest) -> None:
"""Delete an entity."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ListEntityTypesResponse,
SearchEntitiesRequest,
SearchEntitiesResponse,
UpdateEntityRequest,
)
from exabel_data_sdk.stubs.exabel.api.data.v1.all_pb2_grpc import EntityServiceStub

Expand Down Expand Up @@ -50,6 +51,10 @@ def get_entity(self, request: GetEntityRequest) -> Entity:
def create_entity(self, request: CreateEntityRequest) -> Entity:
return self.stub.CreateEntity(request, metadata=self.metadata, timeout=self.config.timeout)

@handle_grpc_error
def update_entity(self, request: UpdateEntityRequest) -> Entity:
return self.stub.UpdateEntity(request, metadata=self.metadata, timeout=self.config.timeout)

@handle_grpc_error
def delete_entity(self, request: DeleteEntityRequest) -> None:
self.stub.DeleteEntity(request, metadata=self.metadata, timeout=self.config.timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ListRelationshipTypesResponse,
Relationship,
RelationshipType,
UpdateRelationshipRequest,
UpdateRelationshipTypeRequest,
)
from exabel_data_sdk.stubs.exabel.api.data.v1.all_pb2_grpc import RelationshipServiceStub

Expand Down Expand Up @@ -48,6 +50,12 @@ def create_relationship_type(self, request: CreateRelationshipTypeRequest) -> Re
request, metadata=self.metadata, timeout=self.config.timeout
)

@handle_grpc_error
def update_relationship_type(self, request: UpdateRelationshipTypeRequest) -> RelationshipType:
return self.stub.UpdateRelationshipType(
request, metadata=self.metadata, timeout=self.config.timeout
)

@handle_grpc_error
def delete_relationship_type(self, request: DeleteRelationshipTypeRequest) -> None:
return self.stub.DeleteRelationshipType(
Expand All @@ -72,6 +80,12 @@ def create_relationship(self, request: CreateRelationshipRequest) -> Relationshi
request, metadata=self.metadata, timeout=self.config.timeout
)

@handle_grpc_error
def update_relationship(self, request: UpdateRelationshipRequest) -> Relationship:
return self.stub.UpdateRelationship(
request, metadata=self.metadata, timeout=self.config.timeout
)

@handle_grpc_error
def delete_relationship(self, request: DeleteRelationshipRequest) -> None:
self.stub.DeleteRelationship(request, metadata=self.metadata, timeout=self.config.timeout)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
ListSignalsRequest,
ListSignalsResponse,
Signal,
UpdateSignalRequest,
)
from exabel_data_sdk.stubs.exabel.api.data.v1.all_pb2_grpc import SignalServiceStub

Expand Down Expand Up @@ -46,6 +47,14 @@ def create_signal(self, request: CreateSignalRequest) -> Signal:
timeout=self.config.timeout,
)

@handle_grpc_error
def update_signal(self, request: UpdateSignalRequest) -> Signal:
return self.stub.UpdateSignal(
request,
metadata=self.metadata,
timeout=self.config.timeout,
)

@handle_grpc_error
def delete_signal(self, request: DeleteSignalRequest) -> None:
self.stub.DeleteSignal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ListEntityTypesResponse,
SearchEntitiesRequest,
SearchEntitiesResponse,
UpdateEntityRequest,
)


Expand All @@ -38,6 +39,9 @@ def get_entity(self, request: GetEntityRequest) -> Entity:
def create_entity(self, request: CreateEntityRequest) -> Entity:
return self._request("POST", f"{request.parent}/entities", Entity(), body=request.entity)

def update_entity(self, request: UpdateEntityRequest) -> Entity:
return self._request("PATCH", f"{request.entity.name}", Entity(), body=request.entity)

def delete_entity(self, request: DeleteEntityRequest) -> None:
return self._request("DELETE", f"{request.name}", None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
ListRelationshipTypesResponse,
Relationship,
RelationshipType,
UpdateRelationshipRequest,
UpdateRelationshipTypeRequest,
)


Expand All @@ -35,6 +37,11 @@ def create_relationship_type(self, request: CreateRelationshipTypeRequest) -> Re
"POST", "relationshipTypes", RelationshipType(), body=request.relationship_type
)

def update_relationship_type(self, request: UpdateRelationshipTypeRequest) -> RelationshipType:
return self._request(
"PATCH", "relationshipTypes", RelationshipType(), body=request.relationship_type
)

def delete_relationship_type(self, request: DeleteRelationshipTypeRequest) -> None:
return self._request("DELETE", request.name, None)

Expand Down Expand Up @@ -62,5 +69,13 @@ def create_relationship(self, request: CreateRelationshipRequest) -> Relationshi
body=request.relationship,
)

def update_relationship(self, request: UpdateRelationshipRequest) -> Relationship:
return self._request(
"PATCH",
f"{request.relationship.parent}/relationships",
Relationship(),
body=request.relationship,
)

def delete_relationship(self, request: DeleteRelationshipRequest) -> None:
return self._request("DELETE", f"{request.parent}/relationships", None, body=request)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ListSignalsRequest,
ListSignalsResponse,
Signal,
UpdateSignalRequest,
)


Expand All @@ -29,5 +30,13 @@ def create_signal(self, request: CreateSignalRequest) -> Signal:
request.signal,
)

def update_signal(self, request: UpdateSignalRequest) -> Signal:
return self._request(
"PATCH",
request.signal.name,
Signal(),
request.signal,
)

def delete_signal(self, request: DeleteSignalRequest) -> None:
self._request("DELETE", request.name, None)
10 changes: 10 additions & 0 deletions exabel_data_sdk/client/api/api_client/relationship_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
ListRelationshipTypesResponse,
Relationship,
RelationshipType,
UpdateRelationshipRequest,
UpdateRelationshipTypeRequest,
)


Expand All @@ -35,6 +37,10 @@ def get_relationship_type(self, request: GetRelationshipTypeRequest) -> Relation
def create_relationship_type(self, request: CreateRelationshipTypeRequest) -> RelationshipType:
"""Create a relationship type."""

@abstractmethod
def update_relationship_type(self, request: UpdateRelationshipTypeRequest) -> RelationshipType:
"""Update a relationship type."""

@abstractmethod
def delete_relationship_type(self, request: DeleteRelationshipTypeRequest) -> None:
"""Delete a relationship type."""
Expand All @@ -51,6 +57,10 @@ def get_relationship(self, request: GetRelationshipRequest) -> Relationship:
def create_relationship(self, request: CreateRelationshipRequest) -> Relationship:
"""Create a relationship."""

@abstractmethod
def update_relationship(self, request: UpdateRelationshipRequest) -> Relationship:
"""Update a relationship."""

@abstractmethod
def delete_relationship(self, request: DeleteRelationshipRequest) -> None:
"""Delete a relationship."""
5 changes: 5 additions & 0 deletions exabel_data_sdk/client/api/api_client/signal_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ListSignalsRequest,
ListSignalsResponse,
Signal,
UpdateSignalRequest,
)


Expand All @@ -27,6 +28,10 @@ def get_signal(self, request: GetSignalRequest) -> Signal:
def create_signal(self, request: CreateSignalRequest) -> Signal:
"""Create a signal."""

@abstractmethod
def update_signal(self, request: UpdateSignalRequest) -> Signal:
"""Update a signal."""

@abstractmethod
def delete_signal(self, request: DeleteSignalRequest) -> None:
"""Delete a signal."""
17 changes: 17 additions & 0 deletions exabel_data_sdk/client/api/entity_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Optional, Sequence

from google.protobuf.field_mask_pb2 import FieldMask

from exabel_data_sdk.client.api.api_client.grpc.entity_grpc_client import EntityGrpcClient
from exabel_data_sdk.client.api.api_client.http.entity_http_client import EntityHttpClient
from exabel_data_sdk.client.api.data_classes.entity import Entity
Expand All @@ -17,6 +19,7 @@
ListEntityTypesRequest,
SearchEntitiesRequest,
SearchTerm,
UpdateEntityRequest,
)


Expand Down Expand Up @@ -124,6 +127,20 @@ def create_entity(self, entity: Entity, entity_type: str) -> Entity:
)
return Entity.from_proto(response)

def update_entity(self, entity: Entity, update_mask: FieldMask = None) -> Entity:
"""
Update an entity.

Args:
entity: The entity to update.
update_mask: Fields to update. If not specified, the update behaves as a full update,
overwriting all existing fields and properties.
"""
response = self.client.update_entity(
UpdateEntityRequest(entity=entity.to_proto(), update_mask=update_mask)
)
return Entity.from_proto(response)

def delete_entity(self, name: str) -> None:
"""
Delete one entity.
Expand Down
38 changes: 38 additions & 0 deletions exabel_data_sdk/client/api/relationship_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Optional

from google.protobuf.field_mask_pb2 import FieldMask

from exabel_data_sdk.client.api.api_client.grpc.relationship_grpc_client import (
RelationshipGrpcClient,
)
Expand All @@ -20,6 +22,8 @@
GetRelationshipTypeRequest,
ListRelationshipsRequest,
ListRelationshipTypesRequest,
UpdateRelationshipRequest,
UpdateRelationshipTypeRequest,
)


Expand Down Expand Up @@ -81,6 +85,24 @@ def create_relationship_type(self, relationship_type: RelationshipType) -> Relat
)
return RelationshipType.from_proto(response)

def update_relationship_type(
self, relationship_type: RelationshipType, update_mask: FieldMask = None
) -> RelationshipType:
"""
Update a relationship type.

Args:
relationship_type: The relationship type to update.
update_mask: The fields to update. If not specified, the update behaves as a
full update, overwriting all existing fields and properties.
"""
response = self.client.update_relationship_type(
UpdateRelationshipTypeRequest(
relationship_type=relationship_type.to_proto(), update_mask=update_mask
)
)
return RelationshipType.from_proto(response)

def delete_relationship_type(self, relationship_type: str) -> None:
"""
Delete a relationship type.
Expand Down Expand Up @@ -200,6 +222,22 @@ def create_relationship(self, relationship: Relationship) -> Relationship:
)
return Relationship.from_proto(response)

def update_relationship(
self, relationship: Relationship, update_mask: FieldMask = None
) -> Relationship:
"""
Update a relationship between two entities.

Args:
relationship: The relationship to update.
update_mask: The fields to update. If not specified, the update behaves as a
full update, overwriting all existing fields and properties.
"""
response = self.client.update_relationship(
UpdateRelationshipRequest(relationship=relationship.to_proto(), update_mask=update_mask)
)
return Relationship.from_proto(response)

def delete_relationship(self, relationship_type: str, from_entity: str, to_entity: str) -> None:
"""
Delete a relationship.
Expand Down
17 changes: 17 additions & 0 deletions exabel_data_sdk/client/api/signal_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Optional

from google.protobuf.field_mask_pb2 import FieldMask

from exabel_data_sdk.client.api.api_client.grpc.signal_grpc_client import SignalGrpcClient
from exabel_data_sdk.client.api.api_client.http.signal_http_client import SignalHttpClient
from exabel_data_sdk.client.api.data_classes.paging_result import PagingResult
Expand All @@ -11,6 +13,7 @@
DeleteSignalRequest,
GetSignalRequest,
ListSignalsRequest,
UpdateSignalRequest,
)


Expand Down Expand Up @@ -74,6 +77,20 @@ def create_signal(self, signal: Signal, create_library_signal: bool = False) ->
)
return Signal.from_proto(response)

def update_signal(self, signal: Signal, update_mask: FieldMask = None) -> Signal:
"""
Update one signal and return it.

Args:
signal: The signal to update.
update_mask: The fields to update. If not specified, the update behaves as a
full update, overwriting all existing fields and properties.
"""
response = self.client.update_signal(
UpdateSignalRequest(signal=signal.to_proto(), update_mask=update_mask),
)
return Signal.from_proto(response)

def delete_signal(self, name: str) -> None:
"""
Delete one signal.
Expand Down
6 changes: 2 additions & 4 deletions exabel_data_sdk/scripts/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class CliLogin:
login.access_token
"""

# pylint: disable=too-many-instance-attributes

def __init__(
self,
auth0: str,
Expand Down Expand Up @@ -72,13 +70,13 @@ def read_refresh_token(self) -> None:
"""Read the refresh token from the user’s home directory."""
filename = os.path.expanduser("~/.exabel")
if os.path.isfile(filename):
with open(filename) as file:
with open(filename, encoding="utf-8") as file:
self.refresh_token = file.read()

def write_refresh_token(self) -> None:
"""Write the refresh token to the user’s home directory."""
filename = os.path.expanduser("~/.exabel")
with open(filename, "w") as file:
with open(filename, "w", encoding="utf-8") as file:
file.write(self.refresh_token)

def get_access_token(self) -> bool:
Expand Down
Loading