Skip to content
Merged
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
26 changes: 20 additions & 6 deletions gittensor/miner/token_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
import os
import sys
import time
from typing import Optional

import bittensor as bt
import requests

from gittensor.constants import BASE_GITHUB_API_URL


def init():
"""Initialize and check if GitHub token exists in environment"""
def init() -> bool:
"""Initialize and check if GitHub token exists in environment

Returns:
bool: Always returns True if token exists, otherwise exits

Raises:
SystemExit: If GITTENSOR_MINER_PAT environment variable is not set
"""
token = os.getenv('GITTENSOR_MINER_PAT')
if not token:
bt.logging.error('GitHub Token NOT FOUND. Please set GITTENSOR_MINER_PAT environment variable.')
Expand All @@ -21,10 +29,12 @@ def init():
return True


def load_token():
def load_token() -> Optional[str]:
"""
Load GitHub token from environment variable
Returns the GitHub access token string.

Returns:
Optional[str]: The GitHub access token string if valid, None otherwise
"""
bt.logging.info('Loading GitHub token from environment.')

Expand All @@ -43,11 +53,15 @@ def load_token():
return None


def is_token_valid(token) -> bool:
def is_token_valid(token: str) -> bool:
"""
Test if a GitHub token is valid by making a simple API call.

Args:
token (str): GitHub personal access token to validate

Returns:
True if valid token, False otherwise
bool: True if valid token, False otherwise
"""
headers = {'Authorization': f'token {token}', 'Accept': 'application/vnd.github.v3+json'}

Expand Down