Path: blob/master/src/applications/almanac/util/AlmanacKeys.php
12256 views
<?php12final class AlmanacKeys extends Phobject {34public static function getKeyPath($key_name) {5$root = dirname(phutil_get_library_root('phabricator'));6$keys = $root.'/conf/keys/';78return $keys.ltrim($key_name, '/');9}1011public static function getDeviceID() {12// While running unit tests, ignore any configured device identity.13try {14PhabricatorTestCase::assertExecutingUnitTests();15return null;16} catch (Exception $ex) {17// Continue normally.18}1920$device_id_path = self::getKeyPath('device.id');2122if (Filesystem::pathExists($device_id_path)) {23return trim(Filesystem::readFile($device_id_path));24}2526return null;27}2829public static function getLiveDevice() {30$device_id = self::getDeviceID();31if (!$device_id) {32return null;33}3435$cache = PhabricatorCaches::getRequestCache();36$cache_key = 'almanac.device.self';3738$device = $cache->getKey($cache_key);39if (!$device) {40$viewer = PhabricatorUser::getOmnipotentUser();41$device = id(new AlmanacDeviceQuery())42->setViewer($viewer)43->withNames(array($device_id))44->executeOne();45if (!$device) {46throw new Exception(47pht(48'This host has device ID "%s", but there is no corresponding '.49'device record in Almanac.',50$device_id));51}52$cache->setKey($cache_key, $device);53}5455return $device;56}5758public static function getClusterSSHUser() {59$username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user');60if ($username !== null && strlen($username)) {61return $username;62}6364return null;65}6667}686970