Skip to content

Commit

Permalink
Add config for advertised address to GRPC proxy (#79)
Browse files Browse the repository at this point in the history
* add advertised config address

* updated docs

* fmt

* minor update
  • Loading branch information
wilyle authored Nov 10, 2023
1 parent e82b561 commit 045fdc2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
7 changes: 4 additions & 3 deletions provider_proxies/grpc/v1/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# GRPC Provider Proxy
# gRPC Provider Proxy

The GRPC Provider Proxy interfaces with providers which support GRPC. It acts as a consumer for digital twin providers. This proxy supports the `Get` and `Subscribe` operations as defined for the [Ibeji mixed sample](https://github.com/eclipse-ibeji/ibeji/tree/main/samples/mixed). To use this proxy with other providers, those providers will need to support the same API(s) as the provider in that sample (see [Integrating with this Proxy](#integrating-with-this-proxy) for more information).
The gRPC Provider Proxy interfaces with providers which support gRPC. It acts as a consumer for digital twin providers. This proxy supports the `Get` and `Subscribe` operations as defined for the [Ibeji mixed sample](https://github.com/eclipse-ibeji/ibeji/tree/main/samples/mixed). To use this proxy with other providers, those providers will need to support the same API(s) as the provider in that sample (see [Integrating with this Proxy](#integrating-with-this-proxy) for more information).

## Configuration

This proxy supports the following configuration settings:

- `consumer_address`: The address for the proxy's consumer
- `consumer_address`: The address for the proxy's consumer. The proxy's gRPC server will be hosted on this address.
- `advertised_consumer_address`: (Optional) The advertised address for the proxy's consumer. This is the address that will be reported as the callback address to providers, enabling scenarios where the providers should use a different address from the actual hosting address. If not specified, this proxy will default to using the consumer address.

This adapter supports [config overrides](../../../docs/config-overrides.md). The override filename is `grpc_proxy_config.json`, and the default config is located at `res/grpc_proxy_config.default.json`.

Expand Down
17 changes: 16 additions & 1 deletion provider_proxies/grpc/v1/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ use serde::{Deserialize, Serialize};
/// The GRPC provider proxy config
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Config {
/// The set of config values
/// The hosting address
pub consumer_address: String,

/// The advertised address given to providers as the callback address
/// If not specified, the `consumer_address` will be used
pub advertised_consumer_address: Option<String>,
}

impl Config {
/// Gets the advertised address.
/// Returns the value of `self.advertised_consumer_address` if it's not `None`,
/// otherwise returns `self.consumer_address`.
pub fn get_advertised_address(&self) -> &String {
self.advertised_consumer_address
.as_ref()
.unwrap_or(&self.consumer_address)
}
}
5 changes: 3 additions & 2 deletions provider_proxies/grpc/v1/src/grpc_provider_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl ProviderProxy for GRPCProviderProxy {
/// # Arguments
/// - `entity_id`: the entity id that needs a value
async fn send_request_to_provider(&self, entity_id: &str) -> Result<(), ProviderProxyError> {
let consumer_uri = format!("http://{}", self.config.consumer_address); // Devskim: ignore DS137138
let consumer_uri = format!("http://{}", self.config.get_advertised_address()); // Devskim: ignore DS137138

let operation_result;
{
Expand Down Expand Up @@ -174,7 +174,7 @@ impl ProviderProxy for GRPCProviderProxy {
.insert(String::from(entity_id), String::from(selected_operation));

if selected_operation == SUBSCRIBE_OPERATION {
let consumer_uri = format!("http://{}", self.config.consumer_address); // Devskim: ignore DS137138
let consumer_uri = format!("http://{}", self.config.get_advertised_address()); // Devskim: ignore DS137138
let mut client = self.provider_client.clone();
let request = tonic::Request::new(SubscribeRequest {
entity_id: String::from(entity_id),
Expand Down Expand Up @@ -323,6 +323,7 @@ mod grpc_provider_proxy_v1_tests {
let grpc_provider_proxy = GRPCProviderProxy {
config: Config {
consumer_address: "[::1]:60010".to_string(),
advertised_consumer_address: None,
},
provider_client: client,
entity_operation_map: Mutex::new(HashMap::new()),
Expand Down

0 comments on commit 045fdc2

Please sign in to comment.