Skip to content

chore: clean up code #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2025
Merged
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
10 changes: 0 additions & 10 deletions src/phase/utils/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,15 @@
from typing import Tuple
import string
from nacl.secret import SecretBox
from typing import List
from nacl.encoding import RawEncoder
import functools
import nacl.bindings
from nacl.encoding import HexEncoder
from nacl.public import PrivateKey
from nacl.bindings import (
crypto_kx_keypair,
crypto_aead_xchacha20poly1305_ietf_encrypt,
crypto_aead_xchacha20poly1305_ietf_decrypt,
randombytes,
crypto_secretbox_NONCEBYTES,
crypto_kx_server_session_keys,
crypto_kx_client_session_keys,
crypto_kx_seed_keypair,
)
from nacl.hash import blake2b
from nacl.utils import random
from base64 import b64encode, b64decode
from .const import __ph_version__


Expand Down
40 changes: 1 addition & 39 deletions src/phase/utils/misc.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
import os
import platform
import subprocess
import webbrowser
import getpass
import json
from .exceptions import EnvironmentNotFoundException
from urllib.parse import urlparse
from typing import Union, List
from .const import __version__, PHASE_CLOUD_API_HOST, cross_env_pattern, local_ref_pattern


def get_default_user_token() -> str:
"""
Fetch the default user's personal access token from the config file in PHASE_SECRETS_DIR.

Returns:
- str: The default user's personal access token.

Raises:
- ValueError: If the config file is not found, the default user's ID is missing, or the token is not set.
"""
config_file_path = os.path.join(PHASE_SECRETS_DIR, 'config.json')

if not os.path.exists(config_file_path):
raise ValueError("Config file not found. Please login with phase auth or supply a PHASE_SERVICE_TOKEN as an environment variable.")

with open(config_file_path, 'r') as f:
config_data = json.load(f)

default_user_id = config_data.get("default-user")
if not default_user_id:
raise ValueError("Default user ID is missing in the config file.")

for user in config_data.get("phase-users", []):
if user['id'] == default_user_id:
token = user.get("token")
if not token:
raise ValueError(f"Token for the default user (ID: {default_user_id}) is not found in the config file.")
return token

raise ValueError("Default user not found in the config file.")
from .const import __version__


def phase_get_context(user_data, app_name=None, env_name=None, app_id=None):
Expand Down