import json import requests import streamlit as st from snowflake.snowpark.context import get_active_session from config import auth0_url, aws_delete_product_gateway_id, \ aws_delete_product_url def get_env(): session = get_active_session() current_schema_result = session.sql("SELECT CURRENT_SCHEMA()").collect() current_schema = current_schema_result[0][0] return current_schema.lower() def get_jwt_token(): auth_secret = json.loads(st.secrets["ouath_secret"]) headers = {'content-type': "application/x-www-form-urlencoded"} data = {'grant_type': 'client_credentials', 'client_id': auth_secret['client_id'], 'client_secret': auth_secret['client_secret'], 'audience': auth_secret['audience'], } response = requests.post(auth0_url[st.session_state.env], headers=headers, data=data).json() return response['access_token'] def _get_delete_gateway_url(): gateway_id = aws_delete_product_gateway_id[st.session_state.env] return aws_delete_product_url.format(gateway_id=gateway_id, env=st.session_state.env) def delete_product_by_upc(upc): headers = { "Authorization": f"Bearer {st.session_state.jwt}", "Content-Type": "application/json" # Example of another header } delete_response = requests.post(_get_delete_gateway_url(), headers=headers, data='{"upc": "' + str(upc) + '"}') return delete_response