Skip to content

Commit

Permalink
make dhcp hook try using OAUTH_CLIENT_ID etc if JWT_AUTH_TOKEN is not…
Browse files Browse the repository at this point in the history
… set
  • Loading branch information
indy-independence committed Feb 28, 2024
1 parent 8f00d01 commit 4380f16
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/cnaas_nms/tools/dhcp_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,23 @@ def get_apidata(configfile="/etc/cnaas-nms/apiclient.yml"):
def get_jwt_token():
try:
token = os.environ["JWT_AUTH_TOKEN"]
except Exception:
raise ValueError("Could not find JWT token")
except KeyError:
try:
auth_data = {
"grant_type": "client_credentials",
"client_id": os.environ["OAUTH_CLIENT_ID"],
"client_secret": os.environ["OAUTH_CLIENT_SECRET"],
}
auth_response = requests.post(
os.environ["OAUTH_TOKEN_ENDPOINT"],
data=auth_data,
headers={"Content-Type": "application/x-www-form-urlencoded"},
timeout=5,
)
auth_response.raise_for_status()
token = auth_response.json()["access_token"]
except Exception as e:
raise ValueError("Could not find JWT token: {}".format(e))
return token


Expand Down

0 comments on commit 4380f16

Please sign in to comment.