getDeviceInfoFromEnv static method

Future<Map<String, String?>> getDeviceInfoFromEnv()

Get device ID and base URL from Linux environment file

Reads from: /etc/haloagent/app.env Returns: Map with 'deviceId' and 'baseUrl'

Implementation

static Future<Map<String, String?>> getDeviceInfoFromEnv() async {
  DebugLogger.log('[LinuxEnvDataSource] === getDeviceInfoFromEnv() called ===');

  try {
    // Validate environment file exists and has required variables
    final isValid = await validateEnvFile();
    if (!isValid) {
      DebugLogger.log('[LinuxEnvDataSource] ❌ Environment file validation failed');
      return {'deviceId': null, 'baseUrl': null};
    }

    // Read environment variables
    final deviceIdFromEnv = await getDeviceId();
    final apiUrlFromEnv = await getApiUrl();

    if (deviceIdFromEnv == null || deviceIdFromEnv.isEmpty) {
      DebugLogger.log('[LinuxEnvDataSource] ❌ Device ID not found in environment file');
      return {'deviceId': null, 'baseUrl': null};
    }

    if (apiUrlFromEnv == null || apiUrlFromEnv.isEmpty) {
      DebugLogger.log('[LinuxEnvDataSource] ⚠️ API_URL not found in environment file');
      return {'deviceId': deviceIdFromEnv, 'baseUrl': null};
    }

    DebugLogger.log('[LinuxEnvDataSource] ✅ Environment variables read successfully');
    DebugLogger.log('[LinuxEnvDataSource]   - DEVICE_ID: $deviceIdFromEnv');
    DebugLogger.log('[LinuxEnvDataSource]   - API_URL: $apiUrlFromEnv');

    return {'deviceId': deviceIdFromEnv, 'baseUrl': apiUrlFromEnv};
  } catch (e) {
    DebugLogger.log('[LinuxEnvDataSource] ❌ Exception in getDeviceInfoFromEnv: $e');
    return {'deviceId': null, 'baseUrl': null};
  }
}