|
import os |
|
from typing import Dict |
|
import json |
|
from prettytable import PrettyTable |
|
|
|
class ConfigManager: |
|
def __init__(self, firebase_api_key: str, firebase_url: str): |
|
"""Khởi tạo với 2 biến secret""" |
|
self.config = { |
|
"FIREBASE_API_KEY": firebase_api_key, |
|
"FIREBASE_URL": firebase_url |
|
} |
|
|
|
def read_config(self) -> Dict: |
|
"""Đọc các biến hiện tại""" |
|
return self.config |
|
|
|
def update_config(self, key: str, value: str) -> bool: |
|
"""Cập nhật giá trị của biến""" |
|
if key in self.config: |
|
self.config[key] = value |
|
return True |
|
return False |
|
|
|
def display_config(self): |
|
"""Hiển thị các biến một cách đẹp mắt""" |
|
table = PrettyTable() |
|
table.field_names = ["Variable", "Value"] |
|
table.align["Variable"] = "l" |
|
table.align["Value"] = "l" |
|
|
|
for key, value in self.config.items(): |
|
table.add_row([key, value]) |
|
|
|
print("\nCurrent Configuration:") |
|
print(table) |
|
|
|
def main(): |
|
|
|
api_key = os.environ.get("FIREBASE_API_KEY", "your_default_api_key") |
|
url = os.environ.get("FIREBASE_URL", "your_default_url") |
|
|
|
|
|
config = ConfigManager(api_key, url) |
|
|
|
|
|
config.display_config() |
|
|
|
|
|
print("\nUpdating values...") |
|
config.update_config("FIREBASE_API_KEY", "new_api_key_123") |
|
config.update_config("FIREBASE_URL", "https://new-firebase-url.com") |
|
|
|
|
|
config.display_config() |
|
|
|
if __name__ == "__main__": |
|
main() |