mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-29 02:23:44 +02:00
Feature/config service (#332)
Configuration service provides an API to change configuration. Complete configuration is pushed down a config queue so that users have a complete copy of config object.
This commit is contained in:
parent
21bda863a7
commit
fa09dc319e
17 changed files with 1002 additions and 5 deletions
77
trustgraph-flow/trustgraph/gateway/config.py
Normal file
77
trustgraph-flow/trustgraph/gateway/config.py
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
|
||||
from .. schema import ConfigRequest, ConfigResponse, ConfigKey, ConfigValue
|
||||
from .. schema import config_request_queue
|
||||
from .. schema import config_response_queue
|
||||
|
||||
from . endpoint import ServiceEndpoint
|
||||
from . requestor import ServiceRequestor
|
||||
|
||||
class ConfigRequestor(ServiceRequestor):
|
||||
def __init__(self, pulsar_client, timeout, auth):
|
||||
|
||||
super(ConfigRequestor, self).__init__(
|
||||
pulsar_client=pulsar_client,
|
||||
request_queue=config_request_queue,
|
||||
response_queue=config_response_queue,
|
||||
request_schema=ConfigRequest,
|
||||
response_schema=ConfigResponse,
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
def to_request(self, body):
|
||||
|
||||
if "keys" in body:
|
||||
keys = [
|
||||
ConfigKey(
|
||||
type = k["type"],
|
||||
key = k["key"],
|
||||
)
|
||||
for k in body["keys"]
|
||||
]
|
||||
else:
|
||||
keys = None
|
||||
|
||||
if "values" in body:
|
||||
values = [
|
||||
ConfigValue(
|
||||
type = v["type"],
|
||||
key = v["key"],
|
||||
value = v["value"],
|
||||
)
|
||||
for v in body["values"]
|
||||
]
|
||||
else:
|
||||
values = None
|
||||
|
||||
return ConfigRequest(
|
||||
operation = body.get("operation", None),
|
||||
keys = keys,
|
||||
type = body.get("type", None),
|
||||
values = values
|
||||
)
|
||||
|
||||
def from_response(self, message):
|
||||
|
||||
response = { }
|
||||
|
||||
if message.version:
|
||||
response["version"] = message.version
|
||||
|
||||
if message.values:
|
||||
response["values"] = [
|
||||
{
|
||||
"type": v.type,
|
||||
"key": v.key,
|
||||
"value": v.value,
|
||||
}
|
||||
for v in message.values
|
||||
]
|
||||
|
||||
if message.directory:
|
||||
response["directory"] = message.directory
|
||||
|
||||
if message.config:
|
||||
response["config"] = message.config
|
||||
|
||||
return response, True
|
||||
|
||||
|
|
@ -38,6 +38,7 @@ from . agent import AgentRequestor
|
|||
from . dbpedia import DbpediaRequestor
|
||||
from . internet_search import InternetSearchRequestor
|
||||
from . librarian import LibrarianRequestor
|
||||
from . config import ConfigRequestor
|
||||
from . triples_stream import TriplesStreamEndpoint
|
||||
from . graph_embeddings_stream import GraphEmbeddingsStreamEndpoint
|
||||
from . document_embeddings_stream import DocumentEmbeddingsStreamEndpoint
|
||||
|
|
@ -141,6 +142,10 @@ class Api:
|
|||
pulsar_client=self.pulsar_client, timeout=self.timeout,
|
||||
auth = self.auth,
|
||||
),
|
||||
"config": ConfigRequestor(
|
||||
pulsar_client=self.pulsar_client, timeout=self.timeout,
|
||||
auth = self.auth,
|
||||
),
|
||||
"encyclopedia": EncyclopediaRequestor(
|
||||
pulsar_client=self.pulsar_client, timeout=self.timeout,
|
||||
auth = self.auth,
|
||||
|
|
@ -199,6 +204,10 @@ class Api:
|
|||
endpoint_path = "/api/v1/librarian", auth=self.auth,
|
||||
requestor = self.services["librarian"],
|
||||
),
|
||||
ServiceEndpoint(
|
||||
endpoint_path = "/api/v1/config", auth=self.auth,
|
||||
requestor = self.services["config"],
|
||||
),
|
||||
ServiceEndpoint(
|
||||
endpoint_path = "/api/v1/encyclopedia", auth=self.auth,
|
||||
requestor = self.services["encyclopedia"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue