jasonpet closed pull request #268: allow for configuring whisk apihost via optional environment variable URL: https://github.com/apache/incubator-openwhisk-package-kafka/pull/268
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/provider/consumer.py b/provider/consumer.py index f9aaef2..3819072 100644 --- a/provider/consumer.py +++ b/provider/consumer.py @@ -31,6 +31,7 @@ from datetime import datetime from datetimeutils import secondsSince from multiprocessing import Process, Manager +from urlparse import urlparse local_dev = os.getenv('LOCAL_DEV', 'False') payload_limit = int(os.getenv('PAYLOAD_LIMIT', 900000)) @@ -127,7 +128,7 @@ def __init__(self, trigger, params, sharedDictionary): self.trigger = trigger self.isMessageHub = params["isMessageHub"] - self.triggerURL = params["triggerURL"] + self.triggerURL = self.__triggerURL(params["triggerURL"]) self.brokers = params["brokers"] self.topic = params["topic"] @@ -203,6 +204,20 @@ def updateLastPoll(self): def secondsSinceLastPoll(self): return secondsSince(self.lastPoll()) + def __triggerURL(self, originalURL): + apiHost = os.getenv('API_HOST') + + if apiHost is not None: + logging.info('[{}] Environment variable defined for API_HOST. Overriding host value defined for trigger in DB with {}'.format(self.trigger, apiHost)) + parsed = urlparse(originalURL) + parts = parsed.netloc.split('@') + auth = parts[0] + newURL = parsed._replace(netloc='{}@{}'.format(auth, apiHost)) + + return newURL.geturl() + else: + return originalURL + def run(self): try: self.consumer = self.__createConsumer() ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services