Skip to content

Commit

Permalink
Update hub configurations to support providing idp and consolidator e…
Browse files Browse the repository at this point in the history
…ndpoints as env-variables
  • Loading branch information
ayeshLK committed Dec 29, 2023
1 parent 1b0e8dd commit 95f856d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
36 changes: 30 additions & 6 deletions examples/kafka-hub/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ services:
hub-2:
condition: service_healthy
restart: true
network_mode: "host"
networks:
- hub_network

hub-1:
image: 'ayeshalmeida/kafkahub:7.0.0'
image: 'ballerina/kafkahub:7.0.0'
container_name: hub-1
ports:
- '9000:9000'
depends_on:
consolidator:
condition: service_healthy
Expand All @@ -29,6 +32,12 @@ services:
SERVER_ID: "hub-1"
# Update following enviornment variable to point to the relevant kafka-cluster
KAFKA_BOOTSTRAP_NODE: "localhost:9094"
# Update following enviornment variable to point to the consolidator state-snapshot endpoint
STATE_SNAPSHOT_ENDPOINT: "http://consolidator:10001"
# Update following enviornment variable to point to the IdP token endpoint
IDP_TOKEN_ENDPOINT: "https://idp:9443/oauth2/token"
# Update following enviornment variable to point to the IdP JWKS endpoint
IDP_JWKS_ENDPOINT: "https://idp:9443/oauth2/jwks"
# Consumer group name uses for `websub-events` consumer
WEBSUB_EVENTS_CONSUMER_GROUP: "websub-events-receiver-hub-1"
# Update following enviornment variable to set the client truststore name
Expand All @@ -50,11 +59,14 @@ services:
timeout: 10s
start_period: 30s
retries: 10
network_mode: "host"
networks:
- hub_network

hub-2:
image: 'ayeshalmeida/kafkahub:7.0.0'
container_name: hub-2
ports:
- '9001:9001'
depends_on:
consolidator:
condition: service_healthy
Expand All @@ -66,6 +78,12 @@ services:
SERVER_ID: "hub-2"
# Update following enviornment variable to point to the relevant kafka-cluster
KAFKA_BOOTSTRAP_NODE: "localhost:9094"
# Update following enviornment variable to point to the consolidator state-snapshot endpoint
STATE_SNAPSHOT_ENDPOINT: "http://consolidator:10001"
# Update following enviornment variable to point to the IdP token endpoint
IDP_TOKEN_ENDPOINT: "https://idp:9443/oauth2/token"
# Update following enviornment variable to point to the IdP JWKS endpoint
IDP_JWKS_ENDPOINT: "https://idp:9443/oauth2/jwks"
# Consumer group name uses for `websub-events` consumer
WEBSUB_EVENTS_CONSUMER_GROUP: "websub-events-receiver-hub-2"
# Update following enviornment variable to set the client truststore name
Expand All @@ -87,7 +105,8 @@ services:
timeout: 10s
start_period: 30s
retries: 10
network_mode: "host"
networks:
- hub_network

consolidator:
image: 'ayeshalmeida/consolidator:6.0.0'
Expand Down Expand Up @@ -123,14 +142,16 @@ services:
timeout: 10s
start_period: 30s
retries: 10
network_mode: "host"
networks:
- hub_network

idp:
image: 'ayeshalmeida/wso2-is:5.11.0.update'
container_name: idp
ports:
- '9443:9443'
network_mode: "host"
networks:
- hub_network

zookeeper:
image: 'confluentinc/cp-zookeeper:7.5.0'
Expand Down Expand Up @@ -167,3 +188,6 @@ services:
KAFKA_SSL_KEY_CREDENTIALS: broker_sslkey_creds
KAFKA_SSL_TRUSTSTORE_FILENAME: kafka.broker.truststore.jks
KAFKA_SSL_TRUSTSTORE_CREDENTIALS: broker_truststore_creds

networks:
hub_network:
2 changes: 1 addition & 1 deletion examples/kafka-hub/hub/hub_state_update.bal
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import kafkaHub.connections as conn;
import ballerinax/kafka;

function initializeHubState() returns error? {
http:Client stateSnapshotClient = check new (config:STATE_SNAPSHOT_ENDPOINT);
http:Client stateSnapshotClient = check new (config:STATE_SNAPSHOT_ENDPOINT_URL);
do {
types:SystemStateSnapshot systemStateSnapshot = check stateSnapshotClient->/consolidator/state\-snapshot;
check processWebsubTopicsSnapshotState(systemStateSnapshot.topics);
Expand Down
2 changes: 2 additions & 0 deletions examples/kafka-hub/hub/modules/config/configurations.bal
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public configurable string WEBSUB_EVENTS_TOPIC = "websub-events";
# Consolidator HTTP endpoint to be used to retrieve current state-snapshot
public configurable string STATE_SNAPSHOT_ENDPOINT = "http://localhost:10001";

public final string STATE_SNAPSHOT_ENDPOINT_URL = os:getEnv("STATE_SNAPSHOT_ENDPOINT") == "" ? STATE_SNAPSHOT_ENDPOINT : os:getEnv("STATE_SNAPSHOT_ENDPOINT");

# The interval in which Kafka consumers wait for new messages
public configurable decimal POLLING_INTERVAL = 10;

Expand Down
10 changes: 8 additions & 2 deletions examples/kafka-hub/hub/modules/security/security.bal
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ import ballerina/log;
import ballerina/http;
import kafkaHub.config;
import ballerina/jwt;
import ballerina/os;

final http:ListenerJwtAuthHandler handler = new({
issuer: config:OAUTH2_CONFIG.issuer,
issuer: getIdpUrlConfig("IDP_TOKEN_ENDPOINT", config:OAUTH2_CONFIG.issuer),
audience: config:OAUTH2_CONFIG.audience,
signatureConfig: {
jwksConfig: {
url: config:OAUTH2_CONFIG.jwksUrl,
url: getIdpUrlConfig("IDP_JWKS_ENDPOINT", config:OAUTH2_CONFIG.jwksUrl),
clientConfig: {
secureSocket: {
disable: true,
cert: {
path: config:OAUTH2_CONFIG.trustStore,
password: config:OAUTH2_CONFIG.trustStorePassword
Expand All @@ -38,6 +40,10 @@ final http:ListenerJwtAuthHandler handler = new({
scopeKey: "scope"
});

isolated function getIdpUrlConfig(string envVariableName, string defaultValue) returns string {
return os:getEnv(envVariableName) == "" ? defaultValue : os:getEnv(envVariableName);
}

# Checks for authorization for the current request.
#
# + headers - `http:Headers` for the current request
Expand Down

0 comments on commit 95f856d

Please sign in to comment.