[docs]classSMIAKBInfrastructure:""" Class to store information about the SMIA KB infrastructure. """# Default values_SMIA_KB_HOST_IP_ADDRESS='http://192.168.186.129'# TODO DE MOMENTO ESTA LA IP DE LA MAQUINA VIRTUAL. PENSARLO SI AĆADIRLO DE FORMA QUE SEA PARAMETRIZABLE (p.e. con variable de entorno para Docker)_SMIA_KB_HOST_PORT=8090SMIA_KB_OPEN_API_VERSION='/api/v3'SMIA_KB_OPEN_API_COMMON_HEADERS={"Accept":"application/json"}
[docs]@classmethoddefset_ip_address_host(cls,ip_address):# Validate and normalize the IP address formatifip_addressandnotip_address.startswith(('http://','https://')):ip_address='http://'+ip_addresscls._SMIA_KB_HOST_IP_ADDRESS=ip_address
[docs]@classmethoddefset_ip_address(cls,ip_address):# Validate and normalize the IP address formatifip_addressandnotip_address.startswith(('http://','https://')):ip_address='http://'+ip_addressparsed=urlparse(ip_address)cls._SMIA_KB_HOST_IP_ADDRESS=f"{parsed.scheme}://{parsed.hostname}"cls._SMIA_KB_HOST_PORT=parsed.portifparsed.portelse(8080ifparsed.scheme=="http"else443)
[docs]@classmethoddefset_port(cls,port):# Validate port is a number and in valid rangetry:port_num=int(port)if1<=port_num<=65535:cls._SMIA_KB_HOST_PORT=port_numelse:raiseValueError(f"ERROR: Port must be between 1-65535, got {port}")except(ValueError,TypeError):raiseValueError(f"ERROR: Port must be a valid integer, got {port}")
# ------------------------------------------------------------# Methods to create URLs for the Capability API of the SMIA KB# ------------------------------------------------------------
[docs]@classmethoddefget_capability_url(cls,capability_iri):""" This method returns the URL to obtain the information of a specific Capability within SMIA KB in JSON format. The Capability identifier must be added Base64-URL-encoded. """capability_iri_encoded=encode_string_in_base64_url(capability_iri)return(f"{cls._SMIA_KB_HOST_IP_ADDRESS}:{cls._SMIA_KB_HOST_PORT}{cls.SMIA_KB_OPEN_API_VERSION}"f"/capabilities/{capability_iri_encoded}")
[docs]@classmethoddefget_capabilities_url(cls):""" This method returns the URL to obtain the information of all Capabilities within SMIA KB in JSON format. """returnf"{cls._SMIA_KB_HOST_IP_ADDRESS}:{cls._SMIA_KB_HOST_PORT}{cls.SMIA_KB_OPEN_API_VERSION}/capabilities"
[docs]@classmethoddefget_assets_of_capability_url(cls,capability_iri):""" This method returns the URL to obtain the information of a specific Capability within SMIA KB in JSON format. The Capability identifier must be added Base64-URL-encoded. """returnf"{cls.get_capability_url(capability_iri)}/assets"
# -------------------------------------------------------# Methods to create URLs for the Skill API of the SMIA KB# -------------------------------------------------------
[docs]@classmethoddefget_skills_url(cls):""" This method returns the URL to obtain the information of all Skills within SMIA KB in JSON format. """returnf"{cls._SMIA_KB_HOST_IP_ADDRESS}:{cls._SMIA_KB_HOST_PORT}{cls.SMIA_KB_OPEN_API_VERSION}/skills"
# ------------------------------------------------------# Methods to create URLs for the SMIA API of the SMIA KB# ------------------------------------------------------
[docs]@classmethoddefget_smia_instances_url(cls):""" This method returns the URL to obtain all the registered SMIA instances in the SMIA KB. """returnf"{cls._SMIA_KB_HOST_IP_ADDRESS}:{cls._SMIA_KB_HOST_PORT}{cls.SMIA_KB_OPEN_API_VERSION}/smiaInstances"
[docs]@classmethoddefget_smia_instance_url(cls,instance_id):""" This method returns the URL to obtain the information of a specific Capability within SMIA KB in JSON format. The Capability identifier must be added Base64-URL-encoded. """return(f"{cls._SMIA_KB_HOST_IP_ADDRESS}:{cls._SMIA_KB_HOST_PORT}{cls.SMIA_KB_OPEN_API_VERSION}"f"/smiaInstances/{instance_id}")
# @classmethod# def get_submodel_json_url_by_id(cls, submodel_id):# """# This method returns the URL to obtain the information of a specific Submodel in JSON format. The Submodel# identifier must be added in Base64-URL-encoded.# """# from swagger_server import util # Local import to avoid circular imports error## return f"{cls._SMIA_KB_HOST_IP_ADDRESS}:{cls._SMIA_KB_HOST_PORT}/submodels/{submodel_id_encoded}"