Skip to content

Commit

Permalink
Add dynamic introspection API
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Gisondi <antonio.gisondi@secomind.com>
  • Loading branch information
harlem88 committed Oct 31, 2023
1 parent 5fa0094 commit a341f29
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Dynamic introspection API.

## [0.5.1] - 2023-10-11

### Added
Expand Down
28 changes: 28 additions & 0 deletions proto/astarteplatform/msghub/interface.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of Astarte.
*
* Copyright 2023 SECO Mind Srl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/

syntax = "proto3";

package astarteplatform.msghub;

/* This message defines a json interface to be added/removed to the Astarte message hub. */
message InterfaceJson{
bytes interface_json = 1; // A byte array representing a json interface.
}
7 changes: 6 additions & 1 deletion proto/astarteplatform/msghub/message_hub_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import "google/protobuf/empty.proto";

import "astarteplatform/msghub/astarte_message.proto";
import "astarteplatform/msghub/astarte_type.proto";
import "astarteplatform/msghub/interface.proto";
import "astarteplatform/msghub/message_hub_error.proto";
import "astarteplatform/msghub/node.proto";

Expand All @@ -38,6 +39,10 @@ service MessageHub {
rpc Send(AstarteMessage) returns (MessageHubResult){}
/* This function should be used to detach a node from an instance of the Astarte message hub. */
rpc Detach(Node) returns (MessageHubResult){}
/* This function should be used to add an interface to an instance of the Astarte message hub. */
rpc AddInterface(InterfaceJson) returns (MessageHubResult){}
/* This function should be used to remove an interface from an instance of the Astarte message hub. */
rpc RemoveInterface(InterfaceJson) returns (MessageHubResult){}
}

/* MessageHubResult is a type of message for returning and propagating errors.
Expand All @@ -49,4 +54,4 @@ message MessageHubResult{
google.protobuf.Empty empty_message = 1; // A message that contains an empty value for success response.
MessageHubError hub_error = 2; // A message that contains a specific Astarte Message Hub error.
}
}
}
4 changes: 3 additions & 1 deletion proto/astarteplatform/msghub/node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ syntax = "proto3";

package astarteplatform.msghub;

import "astarteplatform/msghub/interface.proto";

/* This message defines a node to be attached/detached to the Astarte message hub. */
message Node {
string uuid = 1; // The node identifier.
repeated bytes interface_jsons = 2; // Array of byte arrays representing all .json interface files of the node.
repeated InterfaceJson interface_jsons = 2; // Array of InterfaceJson representing all .json interface files of the node.
}
25 changes: 25 additions & 0 deletions python/astarteplatform/msghub/interface_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions python/astarteplatform/msghub/interface_pb2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from typing import ClassVar as _ClassVar, Optional as _Optional

DESCRIPTOR: _descriptor.FileDescriptor

class InterfaceJson(_message.Message):
__slots__ = ["interface_json"]
INTERFACE_JSON_FIELD_NUMBER: _ClassVar[int]
interface_json: bytes
def __init__(self, interface_json: _Optional[bytes] = ...) -> None: ...
4 changes: 4 additions & 0 deletions python/astarteplatform/msghub/interface_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

11 changes: 6 additions & 5 deletions python/astarteplatform/msghub/message_hub_service_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions python/astarteplatform/msghub/message_hub_service_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from google.protobuf import empty_pb2 as _empty_pb2
from astarteplatform.msghub import astarte_message_pb2 as _astarte_message_pb2
from astarteplatform.msghub import astarte_type_pb2 as _astarte_type_pb2
from astarteplatform.msghub import interface_pb2 as _interface_pb2
from astarteplatform.msghub import message_hub_error_pb2 as _message_hub_error_pb2
from astarteplatform.msghub import node_pb2 as _node_pb2
from google.protobuf import descriptor as _descriptor
Expand Down
69 changes: 69 additions & 0 deletions python/astarteplatform/msghub/message_hub_service_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import grpc

from astarteplatform.msghub import astarte_message_pb2 as astarteplatform_dot_msghub_dot_astarte__message__pb2
from astarteplatform.msghub import interface_pb2 as astarteplatform_dot_msghub_dot_interface__pb2
from astarteplatform.msghub import message_hub_service_pb2 as astarteplatform_dot_msghub_dot_message__hub__service__pb2
from astarteplatform.msghub import node_pb2 as astarteplatform_dot_msghub_dot_node__pb2

Expand Down Expand Up @@ -31,6 +32,16 @@ def __init__(self, channel):
request_serializer=astarteplatform_dot_msghub_dot_node__pb2.Node.SerializeToString,
response_deserializer=astarteplatform_dot_msghub_dot_message__hub__service__pb2.MessageHubResult.FromString,
)
self.AddInterface = channel.unary_unary(
'/astarteplatform.msghub.MessageHub/AddInterface',
request_serializer=astarteplatform_dot_msghub_dot_interface__pb2.InterfaceJson.SerializeToString,
response_deserializer=astarteplatform_dot_msghub_dot_message__hub__service__pb2.MessageHubResult.FromString,
)
self.RemoveInterface = channel.unary_unary(
'/astarteplatform.msghub.MessageHub/RemoveInterface',
request_serializer=astarteplatform_dot_msghub_dot_interface__pb2.InterfaceJson.SerializeToString,
response_deserializer=astarteplatform_dot_msghub_dot_message__hub__service__pb2.MessageHubResult.FromString,
)


class MessageHubServicer(object):
Expand Down Expand Up @@ -58,6 +69,20 @@ def Detach(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def AddInterface(self, request, context):
"""This function should be used to add an interface to an instance of the Astarte message hub.
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def RemoveInterface(self, request, context):
"""This function should be used to remove an interface from an instance of the Astarte message hub.
"""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_MessageHubServicer_to_server(servicer, server):
rpc_method_handlers = {
Expand All @@ -76,6 +101,16 @@ def add_MessageHubServicer_to_server(servicer, server):
request_deserializer=astarteplatform_dot_msghub_dot_node__pb2.Node.FromString,
response_serializer=astarteplatform_dot_msghub_dot_message__hub__service__pb2.MessageHubResult.SerializeToString,
),
'AddInterface': grpc.unary_unary_rpc_method_handler(
servicer.AddInterface,
request_deserializer=astarteplatform_dot_msghub_dot_interface__pb2.InterfaceJson.FromString,
response_serializer=astarteplatform_dot_msghub_dot_message__hub__service__pb2.MessageHubResult.SerializeToString,
),
'RemoveInterface': grpc.unary_unary_rpc_method_handler(
servicer.RemoveInterface,
request_deserializer=astarteplatform_dot_msghub_dot_interface__pb2.InterfaceJson.FromString,
response_serializer=astarteplatform_dot_msghub_dot_message__hub__service__pb2.MessageHubResult.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'astarteplatform.msghub.MessageHub', rpc_method_handlers)
Expand Down Expand Up @@ -136,3 +171,37 @@ def Detach(request,
astarteplatform_dot_msghub_dot_message__hub__service__pb2.MessageHubResult.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def AddInterface(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/astarteplatform.msghub.MessageHub/AddInterface',
astarteplatform_dot_msghub_dot_interface__pb2.InterfaceJson.SerializeToString,
astarteplatform_dot_msghub_dot_message__hub__service__pb2.MessageHubResult.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def RemoveInterface(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/astarteplatform.msghub.MessageHub/RemoveInterface',
astarteplatform_dot_msghub_dot_interface__pb2.InterfaceJson.SerializeToString,
astarteplatform_dot_msghub_dot_message__hub__service__pb2.MessageHubResult.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
7 changes: 4 additions & 3 deletions python/astarteplatform/msghub/node_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions python/astarteplatform/msghub/node_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from astarteplatform.msghub import interface_pb2 as _interface_pb2
from google.protobuf.internal import containers as _containers
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from typing import ClassVar as _ClassVar, Iterable as _Iterable, Optional as _Optional
from typing import ClassVar as _ClassVar, Iterable as _Iterable, Mapping as _Mapping, Optional as _Optional, Union as _Union

DESCRIPTOR: _descriptor.FileDescriptor

Expand All @@ -10,5 +11,5 @@ class Node(_message.Message):
UUID_FIELD_NUMBER: _ClassVar[int]
INTERFACE_JSONS_FIELD_NUMBER: _ClassVar[int]
uuid: str
interface_jsons: _containers.RepeatedScalarFieldContainer[bytes]
def __init__(self, uuid: _Optional[str] = ..., interface_jsons: _Optional[_Iterable[bytes]] = ...) -> None: ...
interface_jsons: _containers.RepeatedCompositeFieldContainer[_interface_pb2.InterfaceJson]
def __init__(self, uuid: _Optional[str] = ..., interface_jsons: _Optional[_Iterable[_Union[_interface_pb2.InterfaceJson, _Mapping]]] = ...) -> None: ...
Loading

0 comments on commit a341f29

Please sign in to comment.