-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Open SNOW ticket API
- Loading branch information
Showing
21 changed files
with
241 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .support import router as support_router | ||
from .incidents import router as incidents_router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from typing import List | ||
import logging | ||
import json | ||
from fastapi import APIRouter, HTTPException, Depends | ||
from fastapi.responses import JSONResponse | ||
from schemas import SupportCreate, SupportResponse | ||
import aiohttp | ||
import asyncio | ||
import os | ||
|
||
logger = logging.getLogger('babylon-api') | ||
|
||
tags = ["support"] | ||
|
||
router = APIRouter(tags=tags) | ||
|
||
# Service Now params: | ||
SERVICENOW_AUTH_SECRET = os.getenv('SERVICENOW_AUTH_SECRET') | ||
SERVICENOW_FORM_ID = os.getenv('SERVICENOW_FORM_ID') | ||
# WORKSHOP_FORM_URL = f"https://redhat.service-now.com/api/sn_sc/v1/servicecatalog/items/{SERVICENOW_FORM_ID}/order_now" | ||
WORKSHOP_FORM_URL = f"https://redhatqa.service-now.com/api/sn_sc/v1/servicecatalog/items/{SERVICENOW_FORM_ID}/order_now" | ||
SYS_USER_URL = "https://redhatqa.service-now.com/api/now/table/sys_user" | ||
API_HEADERS={"Authorization": f"Basic {SERVICENOW_AUTH_SECRET}"} | ||
|
||
async def create_ticket(support_create): | ||
async with aiohttp.ClientSession(headers=API_HEADERS) as session: | ||
async with session.post(WORKSHOP_FORM_URL, json=support_create) as response: | ||
return await response.json() | ||
|
||
async def get_user_sys_id(email): | ||
async with aiohttp.ClientSession(headers=API_HEADERS) as session: | ||
params = {"email": email} | ||
async with session.get(SYS_USER_URL, params=params) as response: | ||
return await response.json() | ||
|
||
|
||
@router.post("/api/admin/v1/workshop/support", | ||
response_model=SupportResponse, | ||
summary="Create support ticket") | ||
async def create_support_ticket(support_create: SupportCreate): | ||
try: | ||
users_result = await get_user_sys_id(support_create.email) | ||
user_sys_id = users_result["result"][0]["sys_id"] | ||
logger.info(user_sys_id) | ||
support_create = create_support_request_json(support_create, user_sys_id) | ||
ticket = await create_ticket(support_create) | ||
logger.info(ticket) | ||
return { | ||
"sys_id": ticket["result"]["sys_id"], | ||
"request_number": ticket["result"]["request_number"], | ||
"request_id": ticket["result"]["request_id"] | ||
} | ||
except Exception as e: | ||
logger.error(f"Error creating support ticket: {e}", stack_info=True) | ||
raise HTTPException(status_code=500, detail="Error support ticket. Contact the administrator") from e | ||
|
||
|
||
def create_support_request_json(support_create, user_sys_id): | ||
return { | ||
"sysparm_quantity":1, | ||
"variables":{ | ||
"number_of_attendees":f"{support_create.number_of_attendees}", | ||
"provide_additional_details":"Auto-Generated by demo.redhat.com portal", | ||
"workshop_or_demo_name":f"{support_create.name}", | ||
"workshop_or_demo_start_date":f"{support_create.start_time}", | ||
"what_is_the_sfdc_opportunity":f"{support_create.sfdc}", | ||
"general_event_name":f"{support_create.event_name}", | ||
"other_facilitators_e_mail_addresses":f"{support_create.email}", | ||
"universal_watch_list":f"{support_create.email}", | ||
"will_you_be_performing_initial_setup_of_your_environment_or_do_you_require_assistance":"i_will_perform_setup", | ||
"provide_your_guid_or_the_url_from_your_browser_linking_to_your_workshop_service":f"{support_create.url}", | ||
"requested_for_rf":"true", | ||
"workshop_or_demo_end_date_and_time":f"{support_create.end_time}", | ||
"number_of_attendees_demo":f"{support_create.number_of_attendees}", | ||
"what_do_you_need_help_with":"i_need_help_ with_a_future_demo_or_workshop", | ||
"workshop_or_demo_start_date_and_time":f"{support_create.start_time}", | ||
"email":f"{support_create.email}", | ||
"do_you_need_to_remove_auto_stop":"No", | ||
"requested_for": f"{user_sys_id}", | ||
}, | ||
"get_portal_messages":"true", | ||
"sysparm_no_validation":"true" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .incidents import IncidentSchema, StatusParams, IncidentStatus, IncidentCreate | ||
from .support import SupportCreate, SupportResponse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import List, Optional, Literal | ||
import logging | ||
from pydantic import BaseModel | ||
from datetime import datetime | ||
|
||
|
||
logger = logging.getLogger('babylon-api') | ||
|
||
|
||
class SupportCreate(BaseModel): | ||
number_of_attendees: int | ||
sfdc: str | ||
name: str | ||
event_name: str | ||
url: str | ||
start_time: datetime | ||
end_time: datetime | ||
email: str | ||
|
||
class SupportResponse(BaseModel): | ||
sys_id: str | ||
request_number: str | ||
request_id: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{{- if .Values.servicenow.deploy }} | ||
apiVersion: bitwarden-k8s-secrets-manager.demo.redhat.com/v1 | ||
kind: BitwardenSyncSecret | ||
metadata: | ||
name: {{ .Values.servicenow.secretName | default "babylon-admin-servicenow" }} | ||
namespace: {{ include "babylon-admin.namespaceName" . }} | ||
spec: | ||
data: | ||
authKey: | ||
secret: service_now | ||
key: auth_key | ||
workshopFormId: | ||
secret: service_now | ||
key: workshop_form_id | ||
{{- else }} | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: {{ .Values.servicenow.secretName | default "babylon-admin-servicenow" }} | ||
namespace: {{ include "babylon-admin.namespaceName" . }} | ||
labels: | ||
{{- include "babylon-admin.labels" . | nindent 4 }} | ||
data: | ||
authKey: {{ required ".Values.servicenow.authKey is required!" .Values.servicenow.authKey | b64enc }} | ||
workshopFormId: {{ required ".Values.servicenow.workshopFormId is required!" .Values.servicenow.workshopFormId | b64enc }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ kubernetes-asyncio==28.2.0 | |
psycopg2==2.9.9 | ||
pydantic==2.4.2 | ||
uvicorn==0.23.2 | ||
aiohttp==3.9.4 | ||
asyncio==3.4.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.