Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / util / AlmanacKeys.php
blob6ed0f187c15cd62b8322aa8cd9c924cfd17d8244
1 <?php
3 final class AlmanacKeys extends Phobject {
5 public static function getKeyPath($key_name) {
6 $root = dirname(phutil_get_library_root('phabricator'));
7 $keys = $root.'/conf/keys/';
9 return $keys.ltrim($key_name, '/');
12 public static function getDeviceID() {
13 // While running unit tests, ignore any configured device identity.
14 try {
15 PhabricatorTestCase::assertExecutingUnitTests();
16 return null;
17 } catch (Exception $ex) {
18 // Continue normally.
21 $device_id_path = self::getKeyPath('device.id');
23 if (Filesystem::pathExists($device_id_path)) {
24 return trim(Filesystem::readFile($device_id_path));
27 return null;
30 public static function getLiveDevice() {
31 $device_id = self::getDeviceID();
32 if (!$device_id) {
33 return null;
36 $cache = PhabricatorCaches::getRequestCache();
37 $cache_key = 'almanac.device.self';
39 $device = $cache->getKey($cache_key);
40 if (!$device) {
41 $viewer = PhabricatorUser::getOmnipotentUser();
42 $device = id(new AlmanacDeviceQuery())
43 ->setViewer($viewer)
44 ->withNames(array($device_id))
45 ->executeOne();
46 if (!$device) {
47 throw new Exception(
48 pht(
49 'This host has device ID "%s", but there is no corresponding '.
50 'device record in Almanac.',
51 $device_id));
53 $cache->setKey($cache_key, $device);
56 return $device;
59 public static function getClusterSSHUser() {
60 $username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user');
61 if (strlen($username)) {
62 return $username;
65 return null;