Skip to content

Commit

Permalink
Merge pull request #34 from port-labs/PORT-10511-use-kafka-brokers-fr…
Browse files Browse the repository at this point in the history
…om-admin-api

Use brokers received from admin api
  • Loading branch information
omby8888 authored Sep 17, 2024
2 parents 85d6c7e + 856b046 commit cb45e13
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/consumers/kafka_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def __init__(
self.consumer = consumer
else:
conf = {
"bootstrap.servers": settings.KAFKA_CONSUMER_BROKERS,
"client.id": consts.KAFKA_CONSUMER_CLIENT_ID,
"security.protocol": settings.KAFKA_CONSUMER_SECURITY_PROTOCOL,
"sasl.mechanism": settings.KAFKA_CONSUMER_AUTHENTICATION_MECHANISM,
Expand All @@ -37,9 +36,10 @@ def __init__(
}
if not settings.USING_LOCAL_PORT_INSTANCE:
logger.info("Getting Kafka credentials")
username, password = get_kafka_credentials()
brokers, username, password = get_kafka_credentials()
conf["sasl.username"] = username
conf["sasl.password"] = password
conf["bootstrap.servers"] = ','.join(brokers)

self.consumer = Consumer(conf)

Expand Down
1 change: 0 additions & 1 deletion app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Settings(BaseSettings):
PORT_API_BASE_URL: AnyHttpUrl = parse_obj_as(AnyHttpUrl, "https://api.getport.io")
PORT_CLIENT_ID: str
PORT_CLIENT_SECRET: str
KAFKA_CONSUMER_BROKERS: str = "localhost:9092"
KAFKA_CONSUMER_SECURITY_PROTOCOL: str = "plaintext"
KAFKA_CONSUMER_AUTHENTICATION_MECHANISM: str = "none"
KAFKA_CONSUMER_SESSION_TIMEOUT_MS: int = 45000
Expand Down
4 changes: 2 additions & 2 deletions app/port_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def report_run_response(run_id: str, response: dict | str | None) -> Response:
return res


def get_kafka_credentials() -> tuple[str, str]:
def get_kafka_credentials() -> tuple[list[str], str, str]:
headers = get_port_api_headers()
res = requests.get(
f"{settings.PORT_API_BASE_URL}/v1/kafka-credentials", headers=headers
)
res.raise_for_status()
data = res.json()["credentials"]
return data["username"], data["password"]
return data['brokers'], data["username"], data["password"]

0 comments on commit cb45e13

Please sign in to comment.