Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/revert-update-paev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Revert Pluggable Action Evaluator

on:
workflow_dispatch:
inputs:
network_type:
required: true
default: odin
type: choice
options:
- odin
- heimdall
- thor
description: 'Which mainnet network to revert?'

jobs:
revert-paev:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- uses: actions/[email protected]
with:
python-version: 3.10.13

- name: install dependencies
run: |
python -m pip install -r requirements.txt
flit install
working-directory: ./scripts

- name: Revert Pluggable Action Evaluator
run: |
python cli.py revert-paev ${{ github.event.inputs.network_type }}
working-directory: ./scripts
env:
GITHUB_TOKEN: ${{ secrets.P_GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
68 changes: 68 additions & 0 deletions scripts/app/revert_update_paev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import boto3
import requests
import json
from urllib.parse import urlparse

class PAEVReverter:
def revert_last_pair(
self,
paev_url: str,
bucket_name: str = "9c-cluster-config"
):
"""
1) Download the appsettings.json from paev_url.
2) Remove the LAST pair from the pairs array.
3) Update the (new) LAST pair's 'range.end' to 9223372036854775807.
4) Upload updated JSON back to S3.
"""

data = self.download_json(paev_url)

pairs = data.get("Headless", {}).get("ActionEvaluator", {}).get("pairs", [])
if not pairs:
raise Exception("No pairs found in ActionEvaluator configuration.")

# 1. Remove the last pair
last_pair = pairs.pop()
print(f"Removed pair: {last_pair}")

# 2. If there is still at least one pair left, set its 'end' to a very large number
if not pairs:
# Edge case: If there was only one pair, we removed it, so now zero remain.
# You can decide how to handle that scenario, or raise an exception.
raise Exception("No pairs left after removing the last one. Cannot revert further.")

# 3. Edit the new last pair's end value
pairs[-1]["range"]["end"] = 9223372036854775807

# 4. Upload updated JSON back to S3
self.upload_json(paev_url, data, bucket_name)
print(f"Successfully reverted the last pair in {paev_url}.")

def download_json(self, url: str) -> dict:
def url_exists(u: str) -> bool:
try:
resp = requests.head(u, allow_redirects=True)
return resp.status_code == 200
except requests.exceptions.RequestException:
return False

if not url_exists(url):
raise Exception(f"Cannot access {url}.")

resp = requests.get(url)
if resp.status_code != 200:
raise Exception(f"Failed to download JSON from {url}, status={resp.status_code}")

return resp.json()

def upload_json(self, url: str, data: dict, bucket_name: str):
file_content = json.dumps(data, indent=4)
file_name = urlparse(url).path.lstrip('/')

s3 = boto3.resource('s3')
s3.Object(bucket_name, file_name).put(
Body=file_content,
ContentType='application/json'
)
print(f"Reverted file uploaded back to {bucket_name}/{file_name}")
18 changes: 18 additions & 0 deletions scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,23 @@ def update_paev(
"""
PluggableActionEvaluatorUpdater().prep_update(network_type, new_start_value, new_lib9c_commit)

@k8s_app.command()
def revert_paev(
network_type: str = typer.Argument(..., help="Which mainnet network to revert? e.g. odin, heimdall, thor."),
):
"""
Revert the last pair from both appsettings.json and appsettings-nodeinfra.json,
setting the new last pair's end to 9223372036854775807.
"""
reverter = PAEVReverter()

urls = [
f"https://9c-cluster-config.s3.us-east-2.amazonaws.com/9c-main/{network_type}/appsettings.json",
f"https://9c-cluster-config.s3.us-east-2.amazonaws.com/9c-main/{network_type}/appsettings-nodeinfra.json",
]

for url in urls:
reverter.revert_last_pair(url)

if __name__ == "__main__":
k8s_app()
Loading