I am trying to deploy an Azure Function App, but whenever I try to do so, I keep getting an error when it tries to sync triggers
If I deploy through the Azure Functions extension in VS Code, it works, but when I go to the Activity Logs tab in the Function App, the Sync Triggers fail.
I’m using Python 3.11 Linux Consumption Function App
I’m not using any external packages besides azure functions.
The connected storage account is open to all IP addresses (not what I want in the end, but I also tried limiting it to the IPs).
import azure.functions as func
import logging
from base64 import b64encode
import csv
import json
import os
import requests
import sys
from datetime import datetime as dt
app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
api_token = os.getenv('RANDORI_API_KEY')
if not api_token:
print('Missing RANDORI_API_KEY environment variable')
sys.exit(1)
RANDORI_PLATFORM_URL = 'https://app.randori.io'
api_path = 'recon/api/v1'
headers = {'Authorization': api_token,
"Content-Type": "application/json"}
def get_json(endpoint):
all_entities = []
url = f'{RANDORI_PLATFORM_URL}/{api_path}/{endpoint}'
limit = 2000
offset = 0
params = {
'limit' : limit,
'offset' : offset
}
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
return response.json()
def parse_targets(result):
total_records = result['total']
json_data = []
for record in result['data']:
priorityScore = round(record['priority_score'], 1)
hostname = record.get('detection_criteria', {}).get('http', {}).get('host', '')
ip = record['detection_criteria']['ip']['address']
vendor = record['vendor']
version = record['version']
targetService = f'{vendor}, {record["name"]}, {version}'
temptationScore = record['target_temptation']
lastSeen = record['last_seen']
timeGenerated = dt.now().isoformat()
temptation = "Critical" if temptationScore >= 40 else "High" if temptationScore >= 30 else "Medium" if temptationScore >= 15 else "Low"
priority = "High" if priorityScore > 29.98 else "Medium" if priorityScore > 20 else "Low"
data = {
'Priority': priority,
'Hostname': hostname,
'IP': ip,
'Vendor': vendor,
'Version': version,
'TargetService': targetService,
'Temptation': temptation,
'LastSeen': lastSeen,
'TimeGenerated': timeGenerated
}
json_data.append(data)
return json_data
#write to json file
def write_json(data, filename):
with open(filename, 'w') as f:
json.dump(data, f, indent=4)
print(f"JSON file written to {filename}")
@app.route(route="test")
def test(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
data = get_json('target')
json_data = parse_targets(data)
write_json(json_data, 'targets.json')
return func.HttpResponse('here', status_code=200)```
1