diff --git a/pkgs/clan-cli/bin/gen-python-client b/pkgs/clan-cli/bin/gen-python-client index 5e027f5..3c83d1b 100755 --- a/pkgs/clan-cli/bin/gen-python-client +++ b/pkgs/clan-cli/bin/gen-python-client @@ -81,7 +81,6 @@ def main() -> None: replace_in_directory(directory_path=src_client, pattern=pattern, replacement=replacement) dst_client: Path = args.out / "openapi_client" - breakpoint() shutil.rmtree(dst_client, ignore_errors=True) shutil.copytree(src_client, dst_client) diff --git a/pkgs/clan-cli/clan_cli/webui/app.py b/pkgs/clan-cli/clan_cli/webui/app.py index 173cef8..d34d25d 100644 --- a/pkgs/clan-cli/clan_cli/webui/app.py +++ b/pkgs/clan-cli/clan_cli/webui/app.py @@ -13,12 +13,14 @@ from ..errors import ClanError from . import sql_models from .assets import asset_path from .error_handlers import clan_error_handler, sql_error_handler -from .routers import health, root, socket_manager2, sql_connect # sql router hinzufügen +from .routers import endpoints, health, root, socket_manager2 # sql router hinzufügen from .sql_db import engine from .tags import tags_metadata origins = [ "http://localhost:3000", + "http://127.0.0.1:3000", + "http://0.0.0.0:3000", ] # Logging setup log = logging.getLogger(__name__) @@ -50,7 +52,7 @@ def setup_app() -> FastAPI: app.include_router(health.router) # sql methodes - app.include_router(sql_connect.router) + app.include_router(endpoints.router) app.include_router(socket_manager2.router) diff --git a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py b/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py similarity index 88% rename from pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py rename to pkgs/clan-cli/clan_cli/webui/routers/endpoints.py index e4b1ea6..4aec32b 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/endpoints.py @@ -15,6 +15,7 @@ from ..schemas import ( Resolution, Service, ServiceCreate, + ServicesByName, ) from ..tags import Tags @@ -57,6 +58,24 @@ async def get_service_by_did( return service +@router.get( + "/api/v1/services_by_entity_name", + response_model=ServicesByName, + tags=[Tags.services], +) +async def get_services_by_name( + entity_name: str, + skip: int = 0, + limit: int = 100, + db: Session = Depends(sql_db.get_db), +) -> ServicesByName: + entity = sql_crud.get_entity_by_name(db, name=entity_name) + if entity is None: + raise ClanError(f"Entity with name '{entity_name}' not found") + services = sql_crud.get_services_by_entity_did(db, entity_did=str(entity.did)) + return ServicesByName(entity=entity, services=services) # type: ignore + + @router.delete("/api/v1/{entity_did}/service", tags=[Tags.services]) async def delete_service( entity_did: str = "did:sov:test:1234", @@ -66,33 +85,11 @@ async def delete_service( return {"message": "service deleted"} -######################### -# # -# Client # -# # -######################### -@router.get( - "/api/v1/{entity_did}/clients", response_model=List[Service], tags=[Tags.clients] -) -async def get_all_clients( - entity_did: str = "did:sov:test:1234", - skip: int = 0, - limit: int = 100, - db: Session = Depends(sql_db.get_db), -) -> List[sql_models.Service]: - clients = sql_crud.get_services_without_entity_id( - db, entity_did, skip=skip, limit=limit - ) - return clients - - ######################### # # # REPOSITORY # # # ######################### - - @router.get( "/api/v1/repositories", response_model=List[Service], @@ -117,6 +114,16 @@ async def create_entity( return sql_crud.create_entity(db, entity) +@router.get( + "/api/v1/entity_by_name", response_model=Optional[Entity], tags=[Tags.entities] +) +async def get_entity_by_name( + entity_name: str, db: Session = Depends(sql_db.get_db) +) -> Optional[sql_models.Entity]: + entity = sql_crud.get_entity_by_name(db, name=entity_name) + return entity + + @router.get("/api/v1/entities", response_model=List[Entity], tags=[Tags.entities]) async def get_all_entities( skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db) diff --git a/pkgs/clan-cli/clan_cli/webui/schemas.py b/pkgs/clan-cli/clan_cli/webui/schemas.py index b98b9b7..bdb1a2e 100644 --- a/pkgs/clan-cli/clan_cli/webui/schemas.py +++ b/pkgs/clan-cli/clan_cli/webui/schemas.py @@ -1,7 +1,8 @@ from datetime import datetime from enum import Enum +from typing import List -from pydantic import BaseModel +from pydantic import BaseModel, Field class Status(Enum): @@ -15,43 +16,23 @@ class Machine(BaseModel): status: Status -######################### -# # -# Service # -# # -######################### -class ServiceBase(BaseModel): - uuid: str = "8e285c0c-4e40-430a-a477-26b3b81e30df" - service_name: str = "Carlos Printing" - service_type: str = "3D Printing" - endpoint_url: str = "http://127.0.0.1:8000" - status: str = "unknown" - other: dict = {"action": ["register", "deregister", "delete", "create"]} - - -class ServiceCreate(ServiceBase): - entity_did: str = "did:sov:test:1234" - - -class Service(ServiceCreate): - class Config: - orm_mode = True - - ######################### # # # Entity # # # ######################### class EntityBase(BaseModel): - did: str = "did:sov:test:1234" - name: str = "C1" - ip: str = "127.0.0.1" - visible: bool = True - other: dict = { - "network": "Carlos Home Network", - "roles": ["service repository", "service prosumer"], - } + did: str = Field(..., example="did:sov:test:1234") + name: str = Field(..., example="C1") + ip: str = Field(..., example="127.0.0.1") + visible: bool = Field(..., example=True) + other: dict = Field( + ..., + example={ + "network": "Carlos Home Network", + "roles": ["service repository", "service prosumer"], + }, + ) class EntityCreate(EntityBase): @@ -59,7 +40,42 @@ class EntityCreate(EntityBase): class Entity(EntityCreate): - attached: bool + attached: bool = Field(...) + + class Config: + orm_mode = True + + +######################### +# # +# Service # +# # +######################### +class ServiceBase(BaseModel): + uuid: str = Field(..., example="8e285c0c-4e40-430a-a477-26b3b81e30df") + service_name: str = Field(..., example="Carlos Printing") + service_type: str = Field(..., example="3D Printing") + endpoint_url: str = Field(..., example="http://127.0.0.1:8000") + status: str = Field(..., example="unknown") + other: dict = Field( + ..., example={"action": ["register", "deregister", "delete", "create"]} + ) + + +class ServiceCreate(ServiceBase): + entity_did: str = Field(..., example="did:sov:test:1234") + + +class Service(ServiceCreate): + entity: Entity + + class Config: + orm_mode = True + + +class ServicesByName(BaseModel): + entity: Entity + services: List[Service] class Config: orm_mode = True @@ -71,10 +87,10 @@ class Entity(EntityCreate): # # ######################### class ResolutionBase(BaseModel): - requester_name: str = "C1" - requester_did: str = "did:sov:test:1122" - resolved_did: str = "did:sov:test:1234" - other: dict = {"test": "test"} + requester_name: str = Field(..., example="C1") + requester_did: str = Field(..., example="did:sov:test:1122") + resolved_did: str = Field(..., example="did:sov:test:1234") + other: dict = Field(..., example={"test": "test"}) class ResolutionCreate(ResolutionBase): diff --git a/pkgs/clan-cli/clan_cli/webui/sql_crud.py b/pkgs/clan-cli/clan_cli/webui/sql_crud.py index f10f582..f18bc4e 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_crud.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_crud.py @@ -81,6 +81,10 @@ def get_entity_by_did(db: Session, did: str) -> Optional[sql_models.Entity]: return db.query(sql_models.Entity).filter(sql_models.Entity.did == did).first() +def get_entity_by_name(db: Session, name: str) -> Optional[sql_models.Entity]: + return db.query(sql_models.Entity).filter(sql_models.Entity.name == name).first() + + # get attached def get_attached_entities( db: Session, skip: int = 0, limit: int = 100 diff --git a/pkgs/clan-cli/clan_cli/webui/sql_models.py b/pkgs/clan-cli/clan_cli/webui/sql_models.py index f8341f0..b0358ce 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_models.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_models.py @@ -19,7 +19,7 @@ class Entity(Base): ## Queryable body ## did = Column(String, primary_key=True, index=True) - name = Column(String, index=True) + name = Column(String, index=True, unique=True) ip = Column(String, index=True) attached = Column(Boolean, index=True) visible = Column(Boolean, index=True) diff --git a/pkgs/clan-cli/tests/openapi_client/api/clients_api.py b/pkgs/clan-cli/tests/openapi_client/api/clients_api.py index 52c267e..431c420 100644 --- a/pkgs/clan-cli/tests/openapi_client/api/clients_api.py +++ b/pkgs/clan-cli/tests/openapi_client/api/clients_api.py @@ -45,13 +45,13 @@ class ClientsApi: self.api_client = api_client @validate_arguments - def get_all_clients(self, entity_did : StrictStr, skip : Optional[StrictInt] = None, limit : Optional[StrictInt] = None, **kwargs) -> List[Service]: # noqa: E501 - """Get All Clients # noqa: E501 + def get_clients_by_did(self, entity_did : StrictStr, skip : Optional[StrictInt] = None, limit : Optional[StrictInt] = None, **kwargs) -> List[Service]: # noqa: E501 + """Get Clients By Did # noqa: E501 This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req=True - >>> thread = api.get_all_clients(entity_did, skip, limit, async_req=True) + >>> thread = api.get_clients_by_did(entity_did, skip, limit, async_req=True) >>> result = thread.get() :param entity_did: (required) @@ -73,18 +73,18 @@ class ClientsApi: """ kwargs['_return_http_data_only'] = True if '_preload_content' in kwargs: - message = "Error! Please call the get_all_clients_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501 + message = "Error! Please call the get_clients_by_did_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501 raise ValueError(message) - return self.get_all_clients_with_http_info(entity_did, skip, limit, **kwargs) # noqa: E501 + return self.get_clients_by_did_with_http_info(entity_did, skip, limit, **kwargs) # noqa: E501 @validate_arguments - def get_all_clients_with_http_info(self, entity_did : StrictStr, skip : Optional[StrictInt] = None, limit : Optional[StrictInt] = None, **kwargs) -> ApiResponse: # noqa: E501 - """Get All Clients # noqa: E501 + def get_clients_by_did_with_http_info(self, entity_did : StrictStr, skip : Optional[StrictInt] = None, limit : Optional[StrictInt] = None, **kwargs) -> ApiResponse: # noqa: E501 + """Get Clients By Did # noqa: E501 This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req=True - >>> thread = api.get_all_clients_with_http_info(entity_did, skip, limit, async_req=True) + >>> thread = api.get_clients_by_did_with_http_info(entity_did, skip, limit, async_req=True) >>> result = thread.get() :param entity_did: (required) @@ -142,7 +142,7 @@ class ClientsApi: if _key not in _all_params: raise ApiTypeError( "Got an unexpected keyword argument '%s'" - " to method get_all_clients" % _key + " to method get_clients_by_did" % _key ) _params[_key] = _val del _params['kwargs'] diff --git a/pkgs/clan-cli/tests/openapi_client/api/entities_api.py b/pkgs/clan-cli/tests/openapi_client/api/entities_api.py index e12e7ac..51f4345 100644 --- a/pkgs/clan-cli/tests/openapi_client/api/entities_api.py +++ b/pkgs/clan-cli/tests/openapi_client/api/entities_api.py @@ -1072,3 +1072,142 @@ class EntitiesApi: _request_timeout=_params.get('_request_timeout'), collection_formats=_collection_formats, _request_auth=_params.get('_request_auth')) + + @validate_arguments + def get_entity_by_name(self, entity_name : StrictStr, **kwargs) -> Entity: # noqa: E501 + """Get Entity By Name # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.get_entity_by_name(entity_name, async_req=True) + >>> result = thread.get() + + :param entity_name: (required) + :type entity_name: str + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _request_timeout: timeout setting for this request. + If one number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: Entity + """ + kwargs['_return_http_data_only'] = True + if '_preload_content' in kwargs: + message = "Error! Please call the get_entity_by_name_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data" # noqa: E501 + raise ValueError(message) + return self.get_entity_by_name_with_http_info(entity_name, **kwargs) # noqa: E501 + + @validate_arguments + def get_entity_by_name_with_http_info(self, entity_name : StrictStr, **kwargs) -> ApiResponse: # noqa: E501 + """Get Entity By Name # noqa: E501 + + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + + >>> thread = api.get_entity_by_name_with_http_info(entity_name, async_req=True) + >>> result = thread.get() + + :param entity_name: (required) + :type entity_name: str + :param async_req: Whether to execute the request asynchronously. + :type async_req: bool, optional + :param _preload_content: if False, the ApiResponse.data will + be set to none and raw_data will store the + HTTP response body without reading/decoding. + Default is True. + :type _preload_content: bool, optional + :param _return_http_data_only: response data instead of ApiResponse + object with status code, headers, etc + :type _return_http_data_only: bool, optional + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the authentication + in the spec for a single request. + :type _request_auth: dict, optional + :type _content_type: string, optional: force content-type for the request + :return: Returns the result object. + If the method is called asynchronously, + returns the request thread. + :rtype: tuple(Entity, status_code(int), headers(HTTPHeaderDict)) + """ + + _params = locals() + + _all_params = [ + 'entity_name' + ] + _all_params.extend( + [ + 'async_req', + '_return_http_data_only', + '_preload_content', + '_request_timeout', + '_request_auth', + '_content_type', + '_headers' + ] + ) + + # validate the arguments + for _key, _val in _params['kwargs'].items(): + if _key not in _all_params: + raise ApiTypeError( + "Got an unexpected keyword argument '%s'" + " to method get_entity_by_name" % _key + ) + _params[_key] = _val + del _params['kwargs'] + + _collection_formats = {} + + # process the path parameters + _path_params = {} + + # process the query parameters + _query_params = [] + if _params.get('entity_name') is not None: # noqa: E501 + _query_params.append(('entity_name', _params['entity_name'])) + + # process the header parameters + _header_params = dict(_params.get('_headers', {})) + # process the form parameters + _form_params = [] + _files = {} + # process the body parameter + _body_params = None + # set the HTTP header `Accept` + _header_params['Accept'] = self.api_client.select_header_accept( + ['application/json']) # noqa: E501 + + # authentication setting + _auth_settings = [] # noqa: E501 + + _response_types_map = { + '200': "Entity", + '422': "HTTPValidationError", + } + + return self.api_client.call_api( + '/api/v1/entity_by_name', 'GET', + _path_params, + _query_params, + _header_params, + body=_body_params, + post_params=_form_params, + files=_files, + response_types_map=_response_types_map, + auth_settings=_auth_settings, + async_req=_params.get('async_req'), + _return_http_data_only=_params.get('_return_http_data_only'), # noqa: E501 + _preload_content=_params.get('_preload_content', True), + _request_timeout=_params.get('_request_timeout'), + collection_formats=_collection_formats, + _request_auth=_params.get('_request_auth')) diff --git a/pkgs/clan-cli/tests/openapi_client/docs/ClientsApi.md b/pkgs/clan-cli/tests/openapi_client/docs/ClientsApi.md index a466552..e232dcd 100644 --- a/pkgs/clan-cli/tests/openapi_client/docs/ClientsApi.md +++ b/pkgs/clan-cli/tests/openapi_client/docs/ClientsApi.md @@ -2,15 +2,15 @@ All URIs are relative to _http://localhost_ -| Method | HTTP request | Description | -| ---------------------------------------------------- | ------------------------------------ | --------------- | -| [**get_all_clients**](ClientsApi.md#get_all_clients) | **GET** /api/v1/{entity_did}/clients | Get All Clients | +| Method | HTTP request | Description | +| ---------------------------------------------------------- | ------------------------------------ | ------------------ | +| [**get_clients_by_did**](ClientsApi.md#get_clients_by_did) | **GET** /api/v1/{entity_did}/clients | Get Clients By Did | -# **get_all_clients** +# **get_clients_by_did** -> List[Service] get_all_clients(entity_did, skip=skip, limit=limit) +> List[Service] get_clients_by_did(entity_did, skip=skip, limit=limit) -Get All Clients +Get Clients By Did ### Example @@ -38,12 +38,12 @@ with openapi_client.ApiClient(configuration) as api_client: limit = 100 # int | (optional) (default to 100) try: - # Get All Clients - api_response = api_instance.get_all_clients(entity_did, skip=skip, limit=limit) - print("The response of ClientsApi->get_all_clients:\n") + # Get Clients By Did + api_response = api_instance.get_clients_by_did(entity_did, skip=skip, limit=limit) + print("The response of ClientsApi->get_clients_by_did:\n") pprint(api_response) except Exception as e: - print("Exception when calling ClientsApi->get_all_clients: %s\n" % e) + print("Exception when calling ClientsApi->get_clients_by_did: %s\n" % e) ``` ### Parameters diff --git a/pkgs/clan-cli/tests/openapi_client/docs/EntitiesApi.md b/pkgs/clan-cli/tests/openapi_client/docs/EntitiesApi.md index 518cce7..86785f9 100644 --- a/pkgs/clan-cli/tests/openapi_client/docs/EntitiesApi.md +++ b/pkgs/clan-cli/tests/openapi_client/docs/EntitiesApi.md @@ -11,6 +11,7 @@ All URIs are relative to _http://localhost_ | [**get_all_entities**](EntitiesApi.md#get_all_entities) | **GET** /api/v1/entities | Get All Entities | | [**get_attached_entities**](EntitiesApi.md#get_attached_entities) | **GET** /api/v1/attached_entities | Get Attached Entities | | [**get_entity_by_did**](EntitiesApi.md#get_entity_by_did) | **GET** /api/v1/{entity_did}/entity | Get Entity By Did | +| [**get_entity_by_name**](EntitiesApi.md#get_entity_by_name) | **GET** /api/v1/entity_by_name | Get Entity By Name | # **attach_entity** @@ -484,3 +485,69 @@ No authorization required | **422** | Validation Error | - | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **get_entity_by_name** + +> Entity get_entity_by_name(entity_name) + +Get Entity By Name + +### Example + +```python +import time +import os +import openapi_client +from openapi_client.models.entity import Entity +from openapi_client.rest import ApiException +from pprint import pprint + +# Defining the host is optional and defaults to http://localhost +# See configuration.py for a list of all supported configuration parameters. +configuration = openapi_client.Configuration( + host = "http://localhost" +) + + +# Enter a context with an instance of the API client +with openapi_client.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = openapi_client.EntitiesApi(api_client) + entity_name = 'entity_name_example' # str | + + try: + # Get Entity By Name + api_response = api_instance.get_entity_by_name(entity_name) + print("The response of EntitiesApi->get_entity_by_name:\n") + pprint(api_response) + except Exception as e: + print("Exception when calling EntitiesApi->get_entity_by_name: %s\n" % e) +``` + +### Parameters + +| Name | Type | Description | Notes | +| --------------- | ------- | ----------- | ----- | +| **entity_name** | **str** | | + +### Return type + +[**Entity**](Entity.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +### HTTP response details + +| Status code | Description | Response headers | +| ----------- | ------------------- | ---------------- | +| **200** | Successful Response | - | +| **422** | Validation Error | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) diff --git a/pkgs/clan-cli/tests/openapi_client/docs/Entity.md b/pkgs/clan-cli/tests/openapi_client/docs/Entity.md index 75d6e99..fc0e2d7 100644 --- a/pkgs/clan-cli/tests/openapi_client/docs/Entity.md +++ b/pkgs/clan-cli/tests/openapi_client/docs/Entity.md @@ -2,13 +2,13 @@ ## Properties -| Name | Type | Description | Notes | -| ------------ | ---------- | ----------- | ------------------------------------------- | -| **did** | **str** | | [optional] [default to 'did:sov:test:1234'] | -| **name** | **str** | | [optional] [default to 'C1'] | -| **ip** | **str** | | [optional] [default to '127.0.0.1'] | -| **visible** | **bool** | | [optional] [default to True] | -| **other** | **object** | | [optional] | +| Name | Type | Description | Notes | +| ------------ | ---------- | ----------- | ----- | +| **did** | **str** | | +| **name** | **str** | | +| **ip** | **str** | | +| **visible** | **bool** | | +| **other** | **object** | | | **attached** | **bool** | | ## Example diff --git a/pkgs/clan-cli/tests/openapi_client/docs/EntityCreate.md b/pkgs/clan-cli/tests/openapi_client/docs/EntityCreate.md index ab0f28a..4fff16a 100644 --- a/pkgs/clan-cli/tests/openapi_client/docs/EntityCreate.md +++ b/pkgs/clan-cli/tests/openapi_client/docs/EntityCreate.md @@ -2,13 +2,13 @@ ## Properties -| Name | Type | Description | Notes | -| ----------- | ---------- | ----------- | ------------------------------------------- | -| **did** | **str** | | [optional] [default to 'did:sov:test:1234'] | -| **name** | **str** | | [optional] [default to 'C1'] | -| **ip** | **str** | | [optional] [default to '127.0.0.1'] | -| **visible** | **bool** | | [optional] [default to True] | -| **other** | **object** | | [optional] | +| Name | Type | Description | Notes | +| ----------- | ---------- | ----------- | ----- | +| **did** | **str** | | +| **name** | **str** | | +| **ip** | **str** | | +| **visible** | **bool** | | +| **other** | **object** | | ## Example diff --git a/pkgs/clan-cli/tests/openapi_client/docs/Resolution.md b/pkgs/clan-cli/tests/openapi_client/docs/Resolution.md index 11bfaee..27928d5 100644 --- a/pkgs/clan-cli/tests/openapi_client/docs/Resolution.md +++ b/pkgs/clan-cli/tests/openapi_client/docs/Resolution.md @@ -2,12 +2,12 @@ ## Properties -| Name | Type | Description | Notes | -| ------------------ | ------------ | ----------- | ------------------------------------------- | -| **requester_name** | **str** | | [optional] [default to 'C1'] | -| **requester_did** | **str** | | [optional] [default to 'did:sov:test:1122'] | -| **resolved_did** | **str** | | [optional] [default to 'did:sov:test:1234'] | -| **other** | **object** | | [optional] | +| Name | Type | Description | Notes | +| ------------------ | ------------ | ----------- | ----- | +| **requester_name** | **str** | | +| **requester_did** | **str** | | +| **resolved_did** | **str** | | +| **other** | **object** | | | **timestamp** | **datetime** | | | **id** | **int** | | diff --git a/pkgs/clan-cli/tests/openapi_client/docs/Service.md b/pkgs/clan-cli/tests/openapi_client/docs/Service.md index dea7f6d..5798f74 100644 --- a/pkgs/clan-cli/tests/openapi_client/docs/Service.md +++ b/pkgs/clan-cli/tests/openapi_client/docs/Service.md @@ -2,15 +2,16 @@ ## Properties -| Name | Type | Description | Notes | -| ---------------- | ---------- | ----------- | -------------------------------------------------------------- | -| **uuid** | **str** | | [optional] [default to '8e285c0c-4e40-430a-a477-26b3b81e30df'] | -| **service_name** | **str** | | [optional] [default to 'Carlos Printing'] | -| **service_type** | **str** | | [optional] [default to '3D Printing'] | -| **endpoint_url** | **str** | | [optional] [default to 'http://127.0.0.1:8000'] | -| **status** | **str** | | [optional] [default to 'unknown'] | -| **other** | **object** | | [optional] | -| **entity_did** | **str** | | [optional] [default to 'did:sov:test:1234'] | +| Name | Type | Description | Notes | +| ---------------- | ----------------------- | ----------- | ----- | +| **uuid** | **str** | | +| **service_name** | **str** | | +| **service_type** | **str** | | +| **endpoint_url** | **str** | | +| **status** | **str** | | +| **other** | **object** | | +| **entity_did** | **str** | | +| **entity** | [**Entity**](Entity.md) | | ## Example diff --git a/pkgs/clan-cli/tests/openapi_client/docs/ServiceCreate.md b/pkgs/clan-cli/tests/openapi_client/docs/ServiceCreate.md index 891a492..7843b1a 100644 --- a/pkgs/clan-cli/tests/openapi_client/docs/ServiceCreate.md +++ b/pkgs/clan-cli/tests/openapi_client/docs/ServiceCreate.md @@ -2,15 +2,15 @@ ## Properties -| Name | Type | Description | Notes | -| ---------------- | ---------- | ----------- | -------------------------------------------------------------- | -| **uuid** | **str** | | [optional] [default to '8e285c0c-4e40-430a-a477-26b3b81e30df'] | -| **service_name** | **str** | | [optional] [default to 'Carlos Printing'] | -| **service_type** | **str** | | [optional] [default to '3D Printing'] | -| **endpoint_url** | **str** | | [optional] [default to 'http://127.0.0.1:8000'] | -| **status** | **str** | | [optional] [default to 'unknown'] | -| **other** | **object** | | [optional] | -| **entity_did** | **str** | | [optional] [default to 'did:sov:test:1234'] | +| Name | Type | Description | Notes | +| ---------------- | ---------- | ----------- | ----- | +| **uuid** | **str** | | +| **service_name** | **str** | | +| **service_type** | **str** | | +| **endpoint_url** | **str** | | +| **status** | **str** | | +| **other** | **object** | | +| **entity_did** | **str** | | ## Example diff --git a/pkgs/clan-cli/tests/openapi_client/models/entity.py b/pkgs/clan-cli/tests/openapi_client/models/entity.py index 888c1ae..e478804 100644 --- a/pkgs/clan-cli/tests/openapi_client/models/entity.py +++ b/pkgs/clan-cli/tests/openapi_client/models/entity.py @@ -18,18 +18,18 @@ import re # noqa: F401 import json -from typing import Any, Dict, Optional +from typing import Any, Dict from pydantic import BaseModel, Field, StrictBool, StrictStr class Entity(BaseModel): """ Entity """ - did: Optional[StrictStr] = 'did:sov:test:1234' - name: Optional[StrictStr] = 'C1' - ip: Optional[StrictStr] = '127.0.0.1' - visible: Optional[StrictBool] = True - other: Optional[Dict[str, Any]] = None + did: StrictStr = Field(...) + name: StrictStr = Field(...) + ip: StrictStr = Field(...) + visible: StrictBool = Field(...) + other: Dict[str, Any] = Field(...) attached: StrictBool = Field(...) __properties = ["did", "name", "ip", "visible", "other", "attached"] @@ -69,10 +69,10 @@ class Entity(BaseModel): return Entity.parse_obj(obj) _obj = Entity.parse_obj({ - "did": obj.get("did") if obj.get("did") is not None else 'did:sov:test:1234', - "name": obj.get("name") if obj.get("name") is not None else 'C1', - "ip": obj.get("ip") if obj.get("ip") is not None else '127.0.0.1', - "visible": obj.get("visible") if obj.get("visible") is not None else True, + "did": obj.get("did"), + "name": obj.get("name"), + "ip": obj.get("ip"), + "visible": obj.get("visible"), "other": obj.get("other"), "attached": obj.get("attached") }) diff --git a/pkgs/clan-cli/tests/openapi_client/models/entity_create.py b/pkgs/clan-cli/tests/openapi_client/models/entity_create.py index 0204840..f9df72b 100644 --- a/pkgs/clan-cli/tests/openapi_client/models/entity_create.py +++ b/pkgs/clan-cli/tests/openapi_client/models/entity_create.py @@ -18,18 +18,18 @@ import re # noqa: F401 import json -from typing import Any, Dict, Optional -from pydantic import BaseModel, StrictBool, StrictStr +from typing import Any, Dict +from pydantic import BaseModel, Field, StrictBool, StrictStr class EntityCreate(BaseModel): """ EntityCreate """ - did: Optional[StrictStr] = 'did:sov:test:1234' - name: Optional[StrictStr] = 'C1' - ip: Optional[StrictStr] = '127.0.0.1' - visible: Optional[StrictBool] = True - other: Optional[Dict[str, Any]] = None + did: StrictStr = Field(...) + name: StrictStr = Field(...) + ip: StrictStr = Field(...) + visible: StrictBool = Field(...) + other: Dict[str, Any] = Field(...) __properties = ["did", "name", "ip", "visible", "other"] class Config: @@ -68,10 +68,10 @@ class EntityCreate(BaseModel): return EntityCreate.parse_obj(obj) _obj = EntityCreate.parse_obj({ - "did": obj.get("did") if obj.get("did") is not None else 'did:sov:test:1234', - "name": obj.get("name") if obj.get("name") is not None else 'C1', - "ip": obj.get("ip") if obj.get("ip") is not None else '127.0.0.1', - "visible": obj.get("visible") if obj.get("visible") is not None else True, + "did": obj.get("did"), + "name": obj.get("name"), + "ip": obj.get("ip"), + "visible": obj.get("visible"), "other": obj.get("other") }) return _obj diff --git a/pkgs/clan-cli/tests/openapi_client/models/resolution.py b/pkgs/clan-cli/tests/openapi_client/models/resolution.py index 4e97999..05d480b 100644 --- a/pkgs/clan-cli/tests/openapi_client/models/resolution.py +++ b/pkgs/clan-cli/tests/openapi_client/models/resolution.py @@ -18,17 +18,17 @@ import re # noqa: F401 import json from datetime import datetime -from typing import Any, Dict, Optional +from typing import Any, Dict from pydantic import BaseModel, Field, StrictInt, StrictStr class Resolution(BaseModel): """ Resolution """ - requester_name: Optional[StrictStr] = 'C1' - requester_did: Optional[StrictStr] = 'did:sov:test:1122' - resolved_did: Optional[StrictStr] = 'did:sov:test:1234' - other: Optional[Dict[str, Any]] = None + requester_name: StrictStr = Field(...) + requester_did: StrictStr = Field(...) + resolved_did: StrictStr = Field(...) + other: Dict[str, Any] = Field(...) timestamp: datetime = Field(...) id: StrictInt = Field(...) __properties = ["requester_name", "requester_did", "resolved_did", "other", "timestamp", "id"] @@ -69,9 +69,9 @@ class Resolution(BaseModel): return Resolution.parse_obj(obj) _obj = Resolution.parse_obj({ - "requester_name": obj.get("requester_name") if obj.get("requester_name") is not None else 'C1', - "requester_did": obj.get("requester_did") if obj.get("requester_did") is not None else 'did:sov:test:1122', - "resolved_did": obj.get("resolved_did") if obj.get("resolved_did") is not None else 'did:sov:test:1234', + "requester_name": obj.get("requester_name"), + "requester_did": obj.get("requester_did"), + "resolved_did": obj.get("resolved_did"), "other": obj.get("other"), "timestamp": obj.get("timestamp"), "id": obj.get("id") diff --git a/pkgs/clan-cli/tests/openapi_client/models/service.py b/pkgs/clan-cli/tests/openapi_client/models/service.py index 14cc136..9d85092 100644 --- a/pkgs/clan-cli/tests/openapi_client/models/service.py +++ b/pkgs/clan-cli/tests/openapi_client/models/service.py @@ -18,21 +18,23 @@ import re # noqa: F401 import json -from typing import Any, Dict, Optional -from pydantic import BaseModel, StrictStr +from typing import Any, Dict +from pydantic import BaseModel, Field, StrictStr +from openapi_client.models.entity import Entity class Service(BaseModel): """ Service """ - uuid: Optional[StrictStr] = '8e285c0c-4e40-430a-a477-26b3b81e30df' - service_name: Optional[StrictStr] = 'Carlos Printing' - service_type: Optional[StrictStr] = '3D Printing' - endpoint_url: Optional[StrictStr] = 'http://127.0.0.1:8000' - status: Optional[StrictStr] = 'unknown' - other: Optional[Dict[str, Any]] = None - entity_did: Optional[StrictStr] = 'did:sov:test:1234' - __properties = ["uuid", "service_name", "service_type", "endpoint_url", "status", "other", "entity_did"] + uuid: StrictStr = Field(...) + service_name: StrictStr = Field(...) + service_type: StrictStr = Field(...) + endpoint_url: StrictStr = Field(...) + status: StrictStr = Field(...) + other: Dict[str, Any] = Field(...) + entity_did: StrictStr = Field(...) + entity: Entity = Field(...) + __properties = ["uuid", "service_name", "service_type", "endpoint_url", "status", "other", "entity_did", "entity"] class Config: """Pydantic configuration""" @@ -58,6 +60,9 @@ class Service(BaseModel): exclude={ }, exclude_none=True) + # override the default output from pydantic by calling `to_dict()` of entity + if self.entity: + _dict['entity'] = self.entity.to_dict() return _dict @classmethod @@ -70,13 +75,14 @@ class Service(BaseModel): return Service.parse_obj(obj) _obj = Service.parse_obj({ - "uuid": obj.get("uuid") if obj.get("uuid") is not None else '8e285c0c-4e40-430a-a477-26b3b81e30df', - "service_name": obj.get("service_name") if obj.get("service_name") is not None else 'Carlos Printing', - "service_type": obj.get("service_type") if obj.get("service_type") is not None else '3D Printing', - "endpoint_url": obj.get("endpoint_url") if obj.get("endpoint_url") is not None else 'http://127.0.0.1:8000', - "status": obj.get("status") if obj.get("status") is not None else 'unknown', + "uuid": obj.get("uuid"), + "service_name": obj.get("service_name"), + "service_type": obj.get("service_type"), + "endpoint_url": obj.get("endpoint_url"), + "status": obj.get("status"), "other": obj.get("other"), - "entity_did": obj.get("entity_did") if obj.get("entity_did") is not None else 'did:sov:test:1234' + "entity_did": obj.get("entity_did"), + "entity": Entity.from_dict(obj.get("entity")) if obj.get("entity") is not None else None }) return _obj diff --git a/pkgs/clan-cli/tests/openapi_client/models/service_create.py b/pkgs/clan-cli/tests/openapi_client/models/service_create.py index 3d6b732..348695e 100644 --- a/pkgs/clan-cli/tests/openapi_client/models/service_create.py +++ b/pkgs/clan-cli/tests/openapi_client/models/service_create.py @@ -18,20 +18,20 @@ import re # noqa: F401 import json -from typing import Any, Dict, Optional -from pydantic import BaseModel, StrictStr +from typing import Any, Dict +from pydantic import BaseModel, Field, StrictStr class ServiceCreate(BaseModel): """ ServiceCreate """ - uuid: Optional[StrictStr] = '8e285c0c-4e40-430a-a477-26b3b81e30df' - service_name: Optional[StrictStr] = 'Carlos Printing' - service_type: Optional[StrictStr] = '3D Printing' - endpoint_url: Optional[StrictStr] = 'http://127.0.0.1:8000' - status: Optional[StrictStr] = 'unknown' - other: Optional[Dict[str, Any]] = None - entity_did: Optional[StrictStr] = 'did:sov:test:1234' + uuid: StrictStr = Field(...) + service_name: StrictStr = Field(...) + service_type: StrictStr = Field(...) + endpoint_url: StrictStr = Field(...) + status: StrictStr = Field(...) + other: Dict[str, Any] = Field(...) + entity_did: StrictStr = Field(...) __properties = ["uuid", "service_name", "service_type", "endpoint_url", "status", "other", "entity_did"] class Config: @@ -70,13 +70,13 @@ class ServiceCreate(BaseModel): return ServiceCreate.parse_obj(obj) _obj = ServiceCreate.parse_obj({ - "uuid": obj.get("uuid") if obj.get("uuid") is not None else '8e285c0c-4e40-430a-a477-26b3b81e30df', - "service_name": obj.get("service_name") if obj.get("service_name") is not None else 'Carlos Printing', - "service_type": obj.get("service_type") if obj.get("service_type") is not None else '3D Printing', - "endpoint_url": obj.get("endpoint_url") if obj.get("endpoint_url") is not None else 'http://127.0.0.1:8000', - "status": obj.get("status") if obj.get("status") is not None else 'unknown', + "uuid": obj.get("uuid"), + "service_name": obj.get("service_name"), + "service_type": obj.get("service_type"), + "endpoint_url": obj.get("endpoint_url"), + "status": obj.get("status"), "other": obj.get("other"), - "entity_did": obj.get("entity_did") if obj.get("entity_did") is not None else 'did:sov:test:1234' + "entity_did": obj.get("entity_did") }) return _obj diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_clients_api.py b/pkgs/clan-cli/tests/openapi_client/test/test_clients_api.py index 6170b17..a78453a 100644 --- a/pkgs/clan-cli/tests/openapi_client/test/test_clients_api.py +++ b/pkgs/clan-cli/tests/openapi_client/test/test_clients_api.py @@ -26,10 +26,10 @@ class TestClientsApi(unittest.TestCase): def tearDown(self) -> None: pass - def test_get_all_clients(self) -> None: - """Test case for get_all_clients + def test_get_clients_by_did(self) -> None: + """Test case for get_clients_by_did - Get All Clients # noqa: E501 + Get Clients By Did # noqa: E501 """ pass diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_entities_api.py b/pkgs/clan-cli/tests/openapi_client/test/test_entities_api.py index 75c7fb4..ecbc5b8 100644 --- a/pkgs/clan-cli/tests/openapi_client/test/test_entities_api.py +++ b/pkgs/clan-cli/tests/openapi_client/test/test_entities_api.py @@ -75,6 +75,13 @@ class TestEntitiesApi(unittest.TestCase): """ pass + def test_get_entity_by_name(self) -> None: + """Test case for get_entity_by_name + + Get Entity By Name # noqa: E501 + """ + pass + if __name__ == '__main__': unittest.main() diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_entity.py b/pkgs/clan-cli/tests/openapi_client/test/test_entity.py index 8f87b61..5733915 100644 --- a/pkgs/clan-cli/tests/openapi_client/test/test_entity.py +++ b/pkgs/clan-cli/tests/openapi_client/test/test_entity.py @@ -40,11 +40,16 @@ class TestEntity(unittest.TestCase): name = 'C1', ip = '127.0.0.1', visible = True, - other = openapi_client.models.other.Other(), + other = {network=Carlos Home Network, roles=[service repository, service prosumer]}, attached = True ) else: return Entity( + did = 'did:sov:test:1234', + name = 'C1', + ip = '127.0.0.1', + visible = True, + other = {network=Carlos Home Network, roles=[service repository, service prosumer]}, attached = True, ) """ diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_entity_create.py b/pkgs/clan-cli/tests/openapi_client/test/test_entity_create.py index 457eee1..e6c4565 100644 --- a/pkgs/clan-cli/tests/openapi_client/test/test_entity_create.py +++ b/pkgs/clan-cli/tests/openapi_client/test/test_entity_create.py @@ -40,10 +40,15 @@ class TestEntityCreate(unittest.TestCase): name = 'C1', ip = '127.0.0.1', visible = True, - other = openapi_client.models.other.Other() + other = {network=Carlos Home Network, roles=[service repository, service prosumer]} ) else: return EntityCreate( + did = 'did:sov:test:1234', + name = 'C1', + ip = '127.0.0.1', + visible = True, + other = {network=Carlos Home Network, roles=[service repository, service prosumer]}, ) """ diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_resolution.py b/pkgs/clan-cli/tests/openapi_client/test/test_resolution.py index 62e85bf..08ecde0 100644 --- a/pkgs/clan-cli/tests/openapi_client/test/test_resolution.py +++ b/pkgs/clan-cli/tests/openapi_client/test/test_resolution.py @@ -39,12 +39,16 @@ class TestResolution(unittest.TestCase): requester_name = 'C1', requester_did = 'did:sov:test:1122', resolved_did = 'did:sov:test:1234', - other = openapi_client.models.other.Other(), + other = {test=test}, timestamp = datetime.datetime.strptime('2013-10-20 19:20:30.00', '%Y-%m-%d %H:%M:%S.%f'), id = 56 ) else: return Resolution( + requester_name = 'C1', + requester_did = 'did:sov:test:1122', + resolved_did = 'did:sov:test:1234', + other = {test=test}, timestamp = datetime.datetime.strptime('2013-10-20 19:20:30.00', '%Y-%m-%d %H:%M:%S.%f'), id = 56, ) diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_service.py b/pkgs/clan-cli/tests/openapi_client/test/test_service.py index 75e01ff..a681b0d 100644 --- a/pkgs/clan-cli/tests/openapi_client/test/test_service.py +++ b/pkgs/clan-cli/tests/openapi_client/test/test_service.py @@ -41,11 +41,32 @@ class TestService(unittest.TestCase): service_type = '3D Printing', endpoint_url = 'http://127.0.0.1:8000', status = 'unknown', - other = openapi_client.models.other.Other(), - entity_did = 'did:sov:test:1234' + other = {action=[register, deregister, delete, create]}, + entity_did = 'did:sov:test:1234', + entity = openapi_client.models.entity.Entity( + did = 'did:sov:test:1234', + name = 'C1', + ip = '127.0.0.1', + visible = True, + other = {network=Carlos Home Network, roles=[service repository, service prosumer]}, + attached = True, ) ) else: return Service( + uuid = '8e285c0c-4e40-430a-a477-26b3b81e30df', + service_name = 'Carlos Printing', + service_type = '3D Printing', + endpoint_url = 'http://127.0.0.1:8000', + status = 'unknown', + other = {action=[register, deregister, delete, create]}, + entity_did = 'did:sov:test:1234', + entity = openapi_client.models.entity.Entity( + did = 'did:sov:test:1234', + name = 'C1', + ip = '127.0.0.1', + visible = True, + other = {network=Carlos Home Network, roles=[service repository, service prosumer]}, + attached = True, ), ) """ diff --git a/pkgs/clan-cli/tests/openapi_client/test/test_service_create.py b/pkgs/clan-cli/tests/openapi_client/test/test_service_create.py index 23adb04..588bb66 100644 --- a/pkgs/clan-cli/tests/openapi_client/test/test_service_create.py +++ b/pkgs/clan-cli/tests/openapi_client/test/test_service_create.py @@ -41,11 +41,18 @@ class TestServiceCreate(unittest.TestCase): service_type = '3D Printing', endpoint_url = 'http://127.0.0.1:8000', status = 'unknown', - other = openapi_client.models.other.Other(), + other = {action=[register, deregister, delete, create]}, entity_did = 'did:sov:test:1234' ) else: return ServiceCreate( + uuid = '8e285c0c-4e40-430a-a477-26b3b81e30df', + service_name = 'Carlos Printing', + service_type = '3D Printing', + endpoint_url = 'http://127.0.0.1:8000', + status = 'unknown', + other = {action=[register, deregister, delete, create]}, + entity_did = 'did:sov:test:1234', ) """ diff --git a/pkgs/clan-cli/tests/test_db_api.py b/pkgs/clan-cli/tests/test_db_api.py index 53dedce..faa5442 100644 --- a/pkgs/clan-cli/tests/test_db_api.py +++ b/pkgs/clan-cli/tests/test_db_api.py @@ -1,16 +1,81 @@ from openapi_client import ApiClient -from openapi_client.api import default_api -from openapi_client.models import Machine, Status +from openapi_client.api import DefaultApi +from openapi_client.api.entities_api import EntitiesApi +from openapi_client.api.services_api import ServicesApi +from openapi_client.models import ( + Entity, + EntityCreate, + Machine, + ServiceCreate, + Status, +) -default_entity_did_url = "entity_did=did%3Asov%3Atest%3A1234" -default_entity_did = "did:sov:test:1234" -default_entity_did2 = "did:sov:test:1235" -default_entity_did3 = "did:sov:test:1236" -default_entity_did4 = "did:sov:test:1237" -default_entity_did5 = "did:sov:test:1238" +uuids = [ + "e95bb72f-b1b3-4452-8065-c7acf09068fc", + "411d772e-1ad0-4d99-8da0-133ab2972322", + "8cfdf359-c3b9-4951-9e51-08dce797725a", + "24b5b4de-9f5f-4e60-878e-cc5be085fd0d", + "d45f9687-c413-43b9-8e0d-cb610b39fcaf", + "083e09a0-1d71-4819-83e2-ce2a6d831713", + "e6f74e55-c163-4368-98c0-a2b04c99d6e3", + "1b577ba7-c9dd-4e66-b695-9350e9db0b6c", + "bfd9e653-98a4-4451-9d97-bcc2908f213d", + "0e481624-b886-437c-89a0-b9e73651cc72", +] def test_health(api_client: ApiClient) -> None: - default = default_api.DefaultApi(api_client=api_client) + default = DefaultApi(api_client=api_client) res: Machine = default.health() assert res.status == Status.ONLINE + + +def test_entities_empty(api_client: ApiClient) -> None: + entity = EntitiesApi(api_client=api_client) + res = entity.get_all_entities() + assert res == [] + + +def create_entities(num: int = 10) -> list[EntityCreate]: + res = [] + for i in range(num): + en = EntityCreate( + did=f"did:sov:test:12{i}", + name=f"C{i}", + ip=f"127.0.0.1:{7000+i}", + visible=True, + other={}, + ) + res.append(en) + return res + + +def create_service(idx: int, entity: Entity) -> ServiceCreate: + se = ServiceCreate( + uuid=uuids[idx], + service_name=f"Carlos Printing{idx}", + service_type="3D Printing", + endpoint_url=f"{entity.ip}/v1/print_daemon{idx}", + status="unknown", + other={"action": ["register", "deregister", "delete", "create"]}, + entity_did=entity.did, + ) + + return se + + +def test_create_entities(api_client: ApiClient) -> None: + api = EntitiesApi(api_client=api_client) + for own_entity in create_entities(): + res: Entity = api.create_entity(own_entity) + assert res.did == own_entity.did + assert res.attached is False + + +def test_create_services(api_client: ApiClient) -> None: + sapi = ServicesApi(api_client=api_client) + eapi = EntitiesApi(api_client=api_client) + for idx, entity in enumerate(eapi.get_all_entities()): + service_obj = create_service(idx, entity) + service = sapi.create_service(service_obj) + assert service.uuid == service_obj.uuid diff --git a/pkgs/ui/shell.nix b/pkgs/ui/shell.nix index 573aecd..44f89ea 100644 --- a/pkgs/ui/shell.nix +++ b/pkgs/ui/shell.nix @@ -20,13 +20,13 @@ pkgs.mkShell { fi ln -sf ${pkgs.roboto}/share/fonts ./src - + export PATH="$PATH:$(realpath ./node_modules)/.bin" - # re-generate the api code + # re-generate the api code rm -rf src/api openapi.json - cp ${clanPkgs.clan-openapi}/openapi.json . + cp ${clanPkgs.clan-openapi}/openapi.json . orval ''; } diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 91bd903..b5de9d8 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -2,7 +2,7 @@ import { mutate } from "swr"; import { useGetAttachedEntities } from "@/api/entities/entities"; -import { useGetRepositories } from "@/api/repositories/repositories"; +import { useGetAllRepositories } from "@/api/repositories/repositories"; import SummaryDetails from "@/components/summary_card"; import CustomTable from "@/components/table"; import { @@ -22,7 +22,7 @@ export default function AccessPoint() { data: APRepositories, isLoading: laodingRepositories, swrKey: repositoriesKeyFunc, - } = useGetRepositories(); + } = useGetAllRepositories(); const onRefresh = () => { const attachedEntitiesKey = diff --git a/pkgs/ui/src/app/client-1/page.tsx b/pkgs/ui/src/app/client-1/page.tsx deleted file mode 100644 index c0343de..0000000 --- a/pkgs/ui/src/app/client-1/page.tsx +++ /dev/null @@ -1,168 +0,0 @@ -"use client"; -import { useEffect, useRef, useState } from "react"; -import { - Client1ConsumerTableConfig, - Client1ProducerTableConfig, -} from "@/config/client_1"; -import CustomTable from "@/components/table"; -import useGetEntityByName from "@/components/hooks/useGetEntityById"; -import { - Alert, - Button, - Card, - CardContent, - CardHeader, - Skeleton, - Snackbar, - Typography, -} from "@mui/material"; -import CopyToClipboard from "@/components/copy_to_clipboard"; -import { mutate } from "swr"; -import { useGetEntity } from "@/api/entities/entities"; -import { BASE_URL } from "@/constants"; -import axios from "axios"; - -export default function Client1() { - const { entity } = useGetEntityByName("C1"); - const { - data: client1, - isLoading, - swrKey: entityKeyFunc, - } = useGetEntity({ entity_did: entity?.did }); - const cardContentRef = useRef(null); - const [isAttached, setIsAttached] = useState(entity?.attached || false); - const [snackbarOpen, setSnackbarOpen] = useState(false); - const [snackbarMessage, setSnackbarMessage] = useState(""); - - const closeSnackBar = () => { - setSnackbarMessage(""); - setSnackbarOpen(false); - }; - - const onAttachEntity = async () => { - try { - const response = await axios.post(`${BASE_URL}/attach`, { - entity_did: entity?.did, - }); - setSnackbarMessage(response.data.message); - setSnackbarOpen(true); - } catch (error) { - console.error(error); - } finally { - setIsAttached(true); - } - }; - - const onDetachEntity = async () => { - try { - const response = await axios.post(`${BASE_URL}/detach`, { - entity_did: entity?.did, - }); - console.log(response); - setSnackbarMessage("Entity detached successfully."); - setSnackbarOpen(true); - } catch (error) { - console.error(error); - } finally { - setIsAttached(false); - } - }; - - const onRefresh = () => { - const entityKey = - typeof entityKeyFunc === "function" ? entityKeyFunc() : entityKeyFunc; - if (entityKey) mutate(entityKey); - }; - - useEffect(() => { - const interval = setInterval(() => { - onRefresh(); - }, 1000); - - return () => clearInterval(interval); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - - if (isLoading) return ; - - return ( -
-
-

Client 1

-
- {isAttached === false ? ( - - ) : ( - - )} - - -
-
- - - } - /> - - - DID: {client1?.data?.did} - - - IP: {client1?.data?.ip} - - - Network: {client1?.data?.other?.network} - - - -
-

Consumer View

- -
-
-

Producer View

- -
- - - {snackbarMessage} - - -
- ); -} diff --git a/pkgs/ui/src/app/client-2/page.tsx b/pkgs/ui/src/app/client/[client_name]/page.tsx similarity index 60% rename from pkgs/ui/src/app/client-2/page.tsx rename to pkgs/ui/src/app/client/[client_name]/page.tsx index 31526a5..55028e9 100644 --- a/pkgs/ui/src/app/client-2/page.tsx +++ b/pkgs/ui/src/app/client/[client_name]/page.tsx @@ -1,70 +1,50 @@ "use client"; -import { useEffect, useRef, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { - Client2ConsumerTableConfig, - Client2ProducerTableConfig, -} from "@/config/client_2"; + ClientTableConfig, + ServiceTableConfig, +} from "@/config/client_1"; import CustomTable from "@/components/table"; -import useGetEntityByName from "@/components/hooks/useGetEntityById"; import { + Alert, Button, Card, CardContent, CardHeader, - Skeleton, - Typography, Snackbar, - Alert, + Typography, } from "@mui/material"; import CopyToClipboard from "@/components/copy_to_clipboard"; -import { useGetEntity } from "@/api/entities/entities"; +import { useGetServicesByName } from "@/api/services/services"; +import { attachEntity, detachEntity } from "@/api/entities/entities"; import { mutate } from "swr"; -import axios from "axios"; -import { BASE_URL } from "@/constants"; +import { Skeleton } from "@mui/material"; +import { Service } from "@/api/model"; + +export default function Client({ + params, +}: { + params: { client_name: string }; +}) { + const { client_name } = params; -export default function Client2() { - const { entity } = useGetEntityByName("C2"); const { - data: client2, - isLoading, + data: services, + isLoading: services_loading, swrKey: entityKeyFunc, - } = useGetEntity({ entity_did: entity?.did }); - const cardContentRef = useRef(null); - const [isAttached, setIsAttached] = useState(entity?.attached); - const [snackbarOpen, setSnackbarOpen] = useState(false); - const [snackbarMessage, setSnackbarMessage] = useState(""); + } = useGetServicesByName({ + entity_name: client_name, + }); - const closeSnackBar = () => { - setSnackbarMessage(""); - setSnackbarOpen(false); - }; - - const onAttachEntity = async () => { - try { - const response = await axios.post(`${BASE_URL}/attach`, { - entity_did: entity?.did, + const entity = services?.data?.entity; + const clients: Service[] = useMemo(() => { + if (services?.data?.services) { + return services.data.services.filter((service) => { + if (service.entity_did !== entity?.did) return true; }); - alert(response.data.message); - } catch (error) { - console.error(error); - } finally { - setIsAttached(true); } - }; - - const onDetachEntity = async () => { - try { - const response = await axios.post(`${BASE_URL}/detach`, { - entity_did: entity?.did, - }); - console.log("detach", response); - alert("Entity Detached Successfully."); - } catch (error) { - console.error(error); - } finally { - setIsAttached(false); - } - }; + return []; + }, [services]); const onRefresh = () => { const entityKey = @@ -81,7 +61,51 @@ export default function Client2() { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - if (isLoading) return ; + const cardContentRef = useRef(null); + const [snackbarOpen, setSnackbarOpen] = useState(false); + const [snackbarMessage, setSnackbarMessage] = useState(""); + const [isAttached, setIsAttached] = useState(entity?.attached); + + const closeSnackBar = () => { + setSnackbarMessage(""); + setSnackbarOpen(false); + }; + + const onAttachEntity = async () => { + try { + if (entity) { + const response = await attachEntity(entity.did); + setSnackbarMessage(response.data.message); + setSnackbarOpen(true); + } else { + console.error("no entity"); + } + } catch (error) { + console.error(error); + } finally { + setIsAttached(true); + } + }; + + const onDetachEntity = async () => { + try { + if (entity) { + const response = await detachEntity(entity.did); + console.log(response); + setSnackbarMessage("Entity detached successfully."); + setSnackbarOpen(true); + } else { + console.error("no entity"); + } + } catch (error) { + console.error(error); + } finally { + setIsAttached(false); + } + }; + + if (services_loading) return ; + if (!services) return Client not found; return (
@@ -92,7 +116,7 @@ export default function Client2() { justifyContent: "space-between", }} > -

Client 2

+

Client 1

{isAttached === false ? ( @@ -124,30 +149,32 @@ export default function Client2() { /> - DID: {client2?.data?.did} + DID: {entity?.did} - IP: {client2?.data?.ip} + IP: {entity?.ip} - Network: {client2?.data?.other?.network} + Network: {entity?.other?.network}
-

Consumer View

+

Client View

-

Producer View

+

Service View

{ const { children } = props; - const { data: entityData, swrKey: entitiesKeyFunc } = useGetEntities(); + const { data: entityData, swrKey: entitiesKeyFunc } = useGetAllEntities(); const isLoading = false; const error = undefined; diff --git a/pkgs/ui/src/components/sidebar/index.tsx b/pkgs/ui/src/components/sidebar/index.tsx index 3b46170..a7cb52b 100644 --- a/pkgs/ui/src/components/sidebar/index.tsx +++ b/pkgs/ui/src/components/sidebar/index.tsx @@ -35,13 +35,13 @@ const menuEntityEntries: MenuEntry[] = [ { icon: , label: "C1", - to: "/client-1", + to: "/client/C1", disabled: false, }, { icon: , label: "C2", - to: "/client-2", + to: "/client/C2", disabled: false, }, ]; diff --git a/pkgs/ui/src/components/table/index.tsx b/pkgs/ui/src/components/table/index.tsx index 25af334..52b8b5f 100644 --- a/pkgs/ui/src/components/table/index.tsx +++ b/pkgs/ui/src/components/table/index.tsx @@ -11,7 +11,7 @@ import { StyledTableCell, StyledTableRow } from "./style"; import { ICustomTable, CustomTableConfiguration } from "@/types"; import { Checkbox, Skeleton } from "@mui/material"; -const CustomTable = ({ configuration, data, loading }: ICustomTable) => { +const CustomTable = ({ configuration, data, loading, key }: ICustomTable) => { if (loading) return ; @@ -25,7 +25,7 @@ const CustomTable = ({ configuration, data, loading }: ICustomTable) => { render?: (param: any) => void | undefined, ) => { let renderedValue = value; - + console.log(cellKey) // cover use case if the data is an array if (Array.isArray(value)) renderedValue = value.join(", "); @@ -56,11 +56,11 @@ const CustomTable = ({ configuration, data, loading }: ICustomTable) => { {data.map((data: any, rowIndex: number) => ( - {configuration.map((column: CustomTableConfiguration) => { + {configuration.map((column: CustomTableConfiguration, columnIndex: number) => { const cellValue: any = data[column.key]; - const cellKey = column.key; + const cellKey = key + ":" + column.key + ":" + rowIndex; const renderComponent = column?.render; - return renderTableCell(cellValue, cellKey, renderComponent); + return renderTableCell(cellValue, cellKey + ":" + columnIndex, renderComponent); })} ))} diff --git a/pkgs/ui/src/config/client_1/index.tsx b/pkgs/ui/src/config/client_1/index.tsx index ca3a025..3a1db60 100644 --- a/pkgs/ui/src/config/client_1/index.tsx +++ b/pkgs/ui/src/config/client_1/index.tsx @@ -1,6 +1,6 @@ import { Button } from "@mui/material"; -export const Client1ConsumerTableConfig = [ +export const ClientTableConfig = [ { key: "service_name", label: "Service name", @@ -34,7 +34,7 @@ export const Client1ConsumerTableConfig = [ // }, ]; -export const Client1ProducerTableConfig = [ +export const ServiceTableConfig = [ { key: "service_name", label: "Service name", diff --git a/pkgs/ui/src/config/home/index.ts b/pkgs/ui/src/config/home/index.ts index 7f72fe5..4f0a122 100644 --- a/pkgs/ui/src/config/home/index.ts +++ b/pkgs/ui/src/config/home/index.ts @@ -8,7 +8,7 @@ export const HomeTableConfig = [ label: "Entity DID", }, { - key: "other", + key: "network", label: "Network", render: (value: any) => { const renderedValue = typeof value === "object" ? value?.network : "-"; @@ -20,7 +20,7 @@ export const HomeTableConfig = [ label: "IP address", }, { - key: "other", + key: "roles", label: "Roles", render: (value: any) => { const renderedValue = diff --git a/pkgs/ui/src/types/index.ts b/pkgs/ui/src/types/index.ts index fc40cbd..6ac86cc 100644 --- a/pkgs/ui/src/types/index.ts +++ b/pkgs/ui/src/types/index.ts @@ -8,6 +8,7 @@ export interface ICustomTable { configuration: CustomTableConfiguration[]; data: any; loading?: boolean; + key: string; } export interface EntityDetails {