This topic provides step-by-step instructions for configuring network rules, external access integration, and a user-defined function (UDF) to enable secure access to the Precisely Gateway API from Snowflake Pipeline Engines.
Prerequisites
You must have account administrator privileges in Snowflake to perform the setup steps described in this guide.
Step 1: Create or Replace Network Rule
Run the following statements to create or replace the network rule:
MODE = EGRESS
TYPE = HOST_PORT
VALUE_LIST = ('api-dev.cloud.precisely.services'); Step 2: Create or Replace External Access Integration
Run the following statements to create or replace the external access integration:
PRECISELY_API_INTEGRATION
ALLOWED_NETWORK_RULES = (PRECISELY_NETWORK_RULE)
ENABLED=TRUE; Step 3: Create or Replace UDF PRECISELY_API_CALL
Create or replace the function PRECISELY_API_CALL(API_CONTEXT VARIANT,
API_TOKEN VARCHAR) with the following function definition:
RETURNS VARIANT
LANGUAGE PYTHON
RUNTIME_VERSION = 3.12
HANDLER = 'get_precisely_api_response'
EXTERNAL_ACCESS_INTEGRATIONS = (PRECISELY_API_INTEGRATION)
PACKAGES = ('requests')
AS
$$
import requests
def get_precisely_api_response(api_call_context: dict, api_token) -> dict:
try:
url = api_call_context.get('baseUrl') + api_call_context.get('endpoint')
data = api_call_context.get('body', None)
http_method = api_call_context.get('method', 'POST').upper()
headers = api_call_context.get('headers', {})
auth_type = api_call_context.get('authType', 'none').lower()
# Set Authorization header based on authType
if auth_type == 'bearer':
headers['Authorization'] = f"Bearer {api_token}"
elif auth_type == 'apikey':
headers['Authorization'] = f"Apikey {api_token}"
# For 'none' or any other type, no Authorization header is added
with requests.Session() as session:
response = session.request(
method=http_method,
url=url,
json=data,
headers=headers
)
response.raise_for_status()
return response.json()
except Exception as e:
return {"error": str(e)}
$$; Post-Configuration
After completing these steps, your Snowflake account will be configured to securely access the Precisely Gateway API using the provided UDF. Ensure that only authorized users and roles have access to the UDF and external access integration for security purposes.