Skip to content

Commit e720170

Browse files
committed
dummyTokenProviderManual: Add MQTT topic configuration for token provider
When no mqtt_topic: provided, the module will subscribe to "everest_api/<module_id>/cmd/provide" by default. If mqtt_topic: is provided, the module will subscribe to that topic instead. Signed-off-by: ThatsLucas <lucasmailpro9@gmail.com>
1 parent 16bd96b commit e720170

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

modules/Testing/DummyTokenProviderManual/main/auth_token_providerImpl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ namespace module {
99
namespace main {
1010

1111
void auth_token_providerImpl::init() {
12-
mod->mqtt.subscribe("everest_api/dummy_token_provider/cmd/provide", [this](const std::string& msg) {
12+
std::string topic_path;
13+
if (config.mqtt_topic.empty()) {
14+
topic_path = "everest_api/" + mod->info.id + "/cmd/provide";
15+
} else {
16+
topic_path = config.mqtt_topic;
17+
}
18+
EVLOG_info << "Subscribing to MQTT topic for providing tokens: " << topic_path;
19+
mod->mqtt.subscribe(topic_path, [this](const std::string& msg) {
1320
try {
1421
types::authorization::ProvidedIdToken token = json::parse(msg);
1522
EVLOG_info << "Publishing new dummy token: " << everest::helpers::redact(token);

modules/Testing/DummyTokenProviderManual/main/auth_token_providerImpl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
namespace module {
2020
namespace main {
2121

22-
struct Conf {};
22+
struct Conf {
23+
std::string mqtt_topic;
24+
};
2325

2426
class auth_token_providerImpl : public auth_token_providerImplBase {
2527
public:

modules/Testing/DummyTokenProviderManual/manifest.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
description: Dummy token provider that manually publishes one token
22
provides:
33
main:
4-
description: Main implementation of dummy token provider always returning one configured token
4+
description: Main implementation of dummy token provider
55
interface: auth_token_provider
6+
config:
7+
mqtt_topic:
8+
description: If no mqtt_topic is provided, the module subscribes to "everest_api/<module_id>/cmd/provide" by default. If mqtt_topic is provided, the module subscribes to that topic instead.
9+
type: string
10+
minLength: 0
11+
maxLength: 500
12+
default: ''
613
enable_external_mqtt: true
714
metadata:
815
license: https://opensource.org/licenses/Apache-2.0

0 commit comments

Comments
 (0)