Skip to content

Commit

Permalink
fix: remove forbidden characters & add encoding reversal scripts for …
Browse files Browse the repository at this point in the history
…htcondor and slurm
  • Loading branch information
raghuvar-vijay committed Dec 15, 2024
1 parent a04358a commit 7efd5a9
Show file tree
Hide file tree
Showing 20 changed files with 2,489 additions and 168 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Breaking changes
- AUDITOR: Remove forbidden characters ([@raghuvar-vijay](https://github.com/raghuvar-vijay))
- pyauditor + Apel plugin + HTCondor collector: drop support for Python 3.8 ([@dirksammel](https://github.com/dirksammel))

### Security
- [RUSTSEC-2024-0421]: Update idna from 0.5.0 to 1.0.3 ([@raghuvar-vijay](https://github.com/raghuvar-vijay))
- [RUSTSEC-2024-0363]: Update sqlx from 0.7.4 to 0.8.2 (missed some occurrences) ([@dirksammel](https://github.com/dirksammel))
- [RUSTSEC-2024-0399]: Update rustls from 0.23.16 to 0.23.19 ([@dirksammel](https://github.com/dirksammel))
- [RUSTSEC-2024-0402]: Update hashbrown from 0.15.0 to 0.15.2 ([@dirksammel](https://github.com/dirksammel))
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ members = [
"plugins/priority",
]

exclude = [
"auditor/scripts/slurm_revert_encoding",
]

[workspace.dependencies]
actix-web = "4.8.0"
actix-web-opentelemetry = { version = "0.17", features = ["metrics", "metrics-prometheus"] }
Expand Down
6 changes: 6 additions & 0 deletions auditor/scripts/htcondor_revert_encoding/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DB_NAME=auditor
DB_USER=postgres
DB_PASSWORD=securepassword
DB_HOST=localhost
DB_PORT=5432

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import json
import os
from urllib.parse import unquote

import psycopg2
from dotenv import load_dotenv

load_dotenv(dotenv_path="auditor/scripts/htcondor_revert_encodings")


DB_CONFIG = {
"dbname": os.getenv("DB_NAME", "auditor"),
"user": os.getenv("DB_USER", "postgres"),
"password": os.getenv("DB_PASSWORD", "password"),
"host": os.getenv("DB_HOST", "localhost"),
"port": os.getenv("DB_PORT", "5432"),
}


def decode_record(record_id, meta):
"""
Decode the record_id and meta values.
"""
decoded_record_id = unquote(record_id)

try:
decoded_meta = {
key: [unquote(value) for value in values] for key, values in meta.items()
}
except json.JSONDecodeError:
decoded_meta = {} # If JSON decoding fails, return an empty dict
return decoded_record_id, json.dumps(decoded_meta)


def main():
BATCH_SIZE = 1000
offset = 0

try:
conn = psycopg2.connect(**DB_CONFIG)
while True:
cursor = conn.cursor()

fetch_query = f"SELECT id, record_id, meta FROM auditor_accounting ORDER BY id LIMIT {BATCH_SIZE} OFFSET {offset};"
cursor.execute(fetch_query)
rows = cursor.fetchall()

if not rows:
break

for row in rows:
record_id, meta = row[1], row[2]
decoded_record_id, decoded_meta = decode_record(record_id, meta)

update_query = """
UPDATE auditor_accounting
SET record_id = %s, meta = %s
WHERE id = %s;
"""
cursor.execute(update_query, (decoded_record_id, decoded_meta, row[0]))

conn.commit()
offset += BATCH_SIZE

print("Database updated successfully!")

except Exception as e:
print(f"Error: {e}")
if conn:
conn.rollback() # Rollback on error

finally:
if cursor:
cursor.close()
if conn:
conn.close()


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions auditor/scripts/htcondor_revert_encoding/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
psycopg2==2.9.10
python-dotenv==1.0.1
1 change: 1 addition & 0 deletions auditor/scripts/slurm_revert_encoding/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=postgres://postgres:password@localhost:5432/auditor
Loading

0 comments on commit 7efd5a9

Please sign in to comment.