Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Commit

Permalink
fix #16
Browse files Browse the repository at this point in the history
  • Loading branch information
agccie committed May 9, 2018
1 parent f30b586 commit 5eabadc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions aci_app_store/Service/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ setup_environment() {
echo "LOG_ROTATE=0" >> $CONFIG_FILE
echo "LOGIN_ENABLED=0" >> $CONFIG_FILE
echo "ACI_APP_MODE=1" >> $CONFIG_FILE
echo "PROXY_URL=\"http://127.0.0.1:80/\"" >> $CONFIG_FILE
# update iv and ev against seed
echo "" > $PRIVATE_CONFIG
if [ -s "$CRED_DIR/plugin.key" ] && [ -s "$CRED_DIR/plugin.crt" ] ; then
Expand Down
32 changes: 26 additions & 6 deletions app/tasks/ept/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,16 +869,36 @@ def rest_fabric_action(fabric, action, reason):
app = get_app()
headers = {"content-type":"application/json"}
s = requests.Session()
base_url = app.config.get("PROXY_URL", "http://localhost")
if "http" not in base_url: base_url = "http://%s" % base_url
base_url = app.config.get("PROXY_URL", "https://localhost")
if "http" not in base_url: base_url = "https://%s" % base_url

# login as local user and then perform post
url = "%s/api/login" % base_url
data = {"username":"local", "password":lpass}
r = s.post(url, verify=False, data=json.dumps(data), headers=headers)
if r.status_code != 200:
logger.error("failed local login: %s" % r.text)
return False
logger.debug("attempting login local POST %s" % url)
try:
r = s.post(url, verify=False, data=json.dumps(data), headers=headers,
allow_redirects=False)
except Exception as e:
logger.error("failed to perform local login: %s" % e)
r = None
if r is None or r.status_code != 200:
# for 302 redirect or simply timeout, retry on http as default attempt
# is on https
base_url = re.sub("^https","http", base_url, count=0)
base_url = re.sub(":443", ":80", base_url, count=0)
url = "%s/api/login" % base_url
logger.debug("attempting second login local POST %s" % url)
try:
r = s.post(url,verify=False,data=json.dumps(data),headers=headers,
allow_redirects=False)
if r.status_code != 200:
logger.error("failed local login: %s" % r.text)
return False
except Exception as e:
logger.error("faied to perform local login: %s" % e)
return False
logger.debug("local login success")

# send fabric action post
url = "%s/api/ept/%s/%s" % (base_url, action, fabric)
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
LOGIN_ENABLED = bool(int(os.environ.get("LOGIN_ENABLED",1)))

# url for proxy function
PROXY_URL = os.environ.get("PROXY_URL", "http://127.0.0.1:80/")
PROXY_URL = os.environ.get("PROXY_URL", "https://127.0.0.1:443/")

# simulate apic connection and callbacks
SIMULATION_MODE = bool(int(os.environ.get("SIMULATION_MODE",0)))
Expand Down

0 comments on commit 5eabadc

Please sign in to comment.