Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/util/AlmanacKeys.php
12256 views
1
<?php
2
3
final class AlmanacKeys extends Phobject {
4
5
public static function getKeyPath($key_name) {
6
$root = dirname(phutil_get_library_root('phabricator'));
7
$keys = $root.'/conf/keys/';
8
9
return $keys.ltrim($key_name, '/');
10
}
11
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.
19
}
20
21
$device_id_path = self::getKeyPath('device.id');
22
23
if (Filesystem::pathExists($device_id_path)) {
24
return trim(Filesystem::readFile($device_id_path));
25
}
26
27
return null;
28
}
29
30
public static function getLiveDevice() {
31
$device_id = self::getDeviceID();
32
if (!$device_id) {
33
return null;
34
}
35
36
$cache = PhabricatorCaches::getRequestCache();
37
$cache_key = 'almanac.device.self';
38
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));
52
}
53
$cache->setKey($cache_key, $device);
54
}
55
56
return $device;
57
}
58
59
public static function getClusterSSHUser() {
60
$username = PhabricatorEnv::getEnvConfig('diffusion.ssh-user');
61
if ($username !== null && strlen($username)) {
62
return $username;
63
}
64
65
return null;
66
}
67
68
}
69
70