Skip to content

Commit

Permalink
Feedback API Code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dheepak-aot committed Mar 12, 2021
1 parent c73f8b4 commit 2705ca4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
39 changes: 31 additions & 8 deletions feedback-api/src/api/services/feedback/feedback_camunda_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,35 @@ def submit(self, payload):
auth_payload = {"grant_type":"client_credentials",
"client_id":keycloak_client_id,
"client_secret":keycloak_client_secret}
auth_response = requests.post(keycloak_endpoint,data=auth_payload)
access_token = auth_response.json()['access_token']
headers = {'Content-Type': 'application/json', 'Authorization': f'Bearer {access_token}'}
feedback_response = requests.post(camunda_service_endpoint,
headers=headers,
data=json.dumps(payload))
print(feedback_response.json())
return feedback_response.status_code
try:
auth_response = requests.post(keycloak_endpoint,data=auth_payload)
access_token = auth_response.json()['access_token']
headers = {'Content-Type': 'application/json', 'Authorization': f'Bearer {access_token}'}
feedback_response = requests.post(camunda_service_endpoint,
headers=headers,
data=json.dumps(payload), timeout=5.0)
return feedback_response.status_code
except Exception as e:
application_auth_url = os.getenv('APP_AUTH_URL')
application_client_id = os.getenv('APP_AUTH_CLIENT_ID')
application_client_secret = os.getenv('APP_AUTH_CLIENT_SECRET')
notification_email_url = os.getenv('NOTIFICATION_EMAIL_URL')
email_to = (os.getenv('NOTIFICATION_EMAIL_TO')).split(",")
app_auth_payload = {"grant_type":"client_credentials",
"client_id":application_client_id,
"client_secret":application_client_secret}
email_payload = {
'bodyType': 'text',
'body': json.dumps(payload),
'subject': 'Citizen Feedback - Camunda API failure',
'to': email_to
}
app_auth_response = requests.post(application_auth_url,data=app_auth_payload)
app_access_token = app_auth_response.json()['access_token']
email_headers = {'Content-Type': 'application/json', 'Authorization': f'Bearer {app_access_token}'}
email_response = requests.post(notification_email_url,
headers=email_headers,
data=json.dumps(email_payload))
print(email_response)
print(e) # log and continue

25 changes: 25 additions & 0 deletions openshift/templates/feedback-api-dc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ objects:
value: "${FEEDBACK_AUTH_CLIENT_SECRET}"
- name: CORS_ALLOWED_ORIGINS
value: "${CORS_ALLOWED_ORIGINS}"
- name: APP_AUTH_URL
value: "${APP_AUTH_URL}"
- name: APP_AUTH_CLIENT_ID
value: "${APP_AUTH_CLIENT_ID}"
- name: APP_AUTH_CLIENT_SECRET
value: "${APP_AUTH_CLIENT_SECRET}"
- name: NOTIFICATION_EMAIL_URL
value: "${NOTIFICATION_EMAIL_URL}"
- name: NOTIFICATION_EMAIL_TO
value: "${NOTIFICATION_EMAIL_TO}"
- name: PRINT_ENABLE
value: "false"
- name: LOG_BASIC
Expand Down Expand Up @@ -192,6 +202,21 @@ parameters:
- name: CORS_ALLOWED_ORIGINS
description: "CORS allowed origins"
required: true
- name: APP_AUTH_URL
description: "Application auth URL"
required: true
- name: APP_AUTH_CLIENT_ID
description: "Application auth client id"
required: true
- name: APP_AUTH_CLIENT_SECRET
description: "Application auth client secret"
required: true
- name: NOTIFICATION_EMAIL_URL
description: "Notification email endpoint"
required: true
- name: NOTIFICATION_EMAIL_TO
description: "Email receipient to receive Camunda payload on failover"
required: true
- name: FEEDBACK_AUTH_CLIENT_SECRET
description: "Keycloak client secret"
required: true

0 comments on commit 2705ca4

Please sign in to comment.