Compare commits
4 Commits
3eac53346f
...
6c424c6135
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c424c6135 | |||
| 1b8eb4abd4 | |||
| 4d530a5a65 | |||
| ac21ad39b1 |
@@ -50,7 +50,7 @@ If you run the tool for the first time, it will prompt you to use `skywipe confi
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
handle: your_handle
|
handle: your_handle
|
||||||
password: your_password_encrypted
|
password: your_password
|
||||||
batch_size: 10
|
batch_size: 10
|
||||||
delay: 1
|
delay: 1
|
||||||
verbose: true
|
verbose: true
|
||||||
|
|||||||
@@ -7,5 +7,4 @@ requires-python = ">=3.13"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"atproto>=0.0.65",
|
"atproto>=0.0.65",
|
||||||
"pyyaml>=6.0",
|
"pyyaml>=6.0",
|
||||||
"cryptography>=42.0.0",
|
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,48 +1,17 @@
|
|||||||
"""Core configuration handling class and related logic."""
|
"""Core configuration handling class and related logic."""
|
||||||
|
|
||||||
import os
|
|
||||||
import getpass
|
import getpass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import yaml
|
import yaml
|
||||||
from cryptography.fernet import Fernet
|
|
||||||
|
|
||||||
|
|
||||||
class Configuration:
|
class Configuration:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config_file = Path.home() / ".config" / "skywipe" / "config.yml"
|
self.config_file = Path.home() / ".config" / "skywipe" / "config.yml"
|
||||||
self.key_file = Path.home() / ".config" / "skywipe" / ".key"
|
|
||||||
self._fernet = None
|
|
||||||
|
|
||||||
def exists(self) -> bool:
|
def exists(self) -> bool:
|
||||||
return self.config_file.exists()
|
return self.config_file.exists()
|
||||||
|
|
||||||
def _get_or_create_key(self) -> bytes:
|
|
||||||
if self.key_file.exists():
|
|
||||||
return self.key_file.read_bytes()
|
|
||||||
|
|
||||||
key = Fernet.generate_key()
|
|
||||||
config_dir = self.key_file.parent
|
|
||||||
config_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
self.key_file.write_bytes(key)
|
|
||||||
os.chmod(self.key_file, 0o600)
|
|
||||||
return key
|
|
||||||
|
|
||||||
def _get_fernet(self) -> Fernet:
|
|
||||||
if self._fernet is None:
|
|
||||||
key = self._get_or_create_key()
|
|
||||||
self._fernet = Fernet(key)
|
|
||||||
return self._fernet
|
|
||||||
|
|
||||||
def encrypt_password(self, password: str) -> str:
|
|
||||||
fernet = self._get_fernet()
|
|
||||||
encrypted = fernet.encrypt(password.encode())
|
|
||||||
return encrypted.decode()
|
|
||||||
|
|
||||||
def decrypt_password(self, encrypted_password: str) -> str:
|
|
||||||
fernet = self._get_fernet()
|
|
||||||
decrypted = fernet.decrypt(encrypted_password.encode())
|
|
||||||
return decrypted.decode()
|
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
if self.exists():
|
if self.exists():
|
||||||
overwrite = input(
|
overwrite = input(
|
||||||
@@ -71,11 +40,9 @@ class Configuration:
|
|||||||
print("Error: batch_size and delay must be integers")
|
print("Error: batch_size and delay must be integers")
|
||||||
return
|
return
|
||||||
|
|
||||||
encrypted_password = self.encrypt_password(password)
|
|
||||||
|
|
||||||
config_data = {
|
config_data = {
|
||||||
"handle": handle,
|
"handle": handle,
|
||||||
"password": encrypted_password,
|
"password": password,
|
||||||
"batch_size": batch_size,
|
"batch_size": batch_size,
|
||||||
"delay": delay,
|
"delay": delay,
|
||||||
"verbose": verbose
|
"verbose": verbose
|
||||||
|
|||||||
2
uv.lock
generated
2
uv.lock
generated
@@ -381,14 +381,12 @@ version = "0.1.0"
|
|||||||
source = { virtual = "." }
|
source = { virtual = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "atproto" },
|
{ name = "atproto" },
|
||||||
{ name = "cryptography" },
|
|
||||||
{ name = "pyyaml" },
|
{ name = "pyyaml" },
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata]
|
[package.metadata]
|
||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "atproto", specifier = ">=0.0.65" },
|
{ name = "atproto", specifier = ">=0.0.65" },
|
||||||
{ name = "cryptography", specifier = ">=42.0.0" },
|
|
||||||
{ name = "pyyaml", specifier = ">=6.0" },
|
{ name = "pyyaml", specifier = ">=6.0" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user