forked from ssiar-fastly/edge_deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade-vcl-version.py
48 lines (40 loc) · 1.48 KB
/
upgrade-vcl-version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import csv
import requests
import json
# Load environment variables
ngwaf_user_email = os.getenv('NGWAF_USER_EMAIL')
ngwaf_token = os.getenv('NGWAF_TOKEN')
fastly_token = os.getenv('FASTLY_TOKEN')
corp_name = os.getenv('CORP_NAME')
# Constants
BASE_URL = "https://dashboard.signalsciences.net/api/v0"
def get_headers():
return {
"Content-Type": "application/json",
"x-api-user": ngwaf_user_email,
"x-api-token": ngwaf_token,
"Fastly-Key": fastly_token
}
def send_put_request(site_name, service_id):
url = f"{BASE_URL}/corps/{corp_name}/sites/{site_name}/deliveryIntegration/{service_id}"
payload = {
"activateVersion": True,
"percentEnabled": 100
}
response = requests.put(url, headers=get_headers(), data=json.dumps(payload))
if response.status_code == 200:
print(f"Successfully updated site: {site_name} with service ID: {service_id}")
else:
print(f"Failed to update site: {site_name} with service ID: {service_id}. Status Code: {response.status_code} - Details: {response.text}")
def process_csv_file(csv_file_path):
with open(csv_file_path, mode='r') as file:
reader = csv.reader(file)
for row in reader:
if len(row) < 2:
continue
site_name, service_id = row[0], row[1]
send_put_request(site_name, service_id)
if __name__ == "__main__":
# Replace 'file.csv' with the path to your CSV file
process_csv_file('file.csv')