mirror of
https://github.com/ruuda/rcl.git
synced 2025-10-07 15:40:49 +00:00
21 lines
817 B
Text
21 lines
817 B
Text
// Suppose you manage a fleet of servers that have various services running
|
|
// on them, and you want to statically allocate a user id for a system user
|
|
// for each of these services. We could define a mapping of service name to
|
|
// uid like so:
|
|
let uids = {
|
|
goat-teleporter = 10_000,
|
|
logs-archiver = 10_001,
|
|
device-monitor = 10_002,
|
|
prometheus-node-exporter = 10_003,
|
|
|
|
// Uncomment the following line to trigger the problem explained below.
|
|
// prometheus-smartctl-exporter = 10_003,
|
|
};
|
|
|
|
// However, in this configuration it is easy to accidentally use the same uid
|
|
// twice, which would be disastrous. We can prevent this statically by inverting
|
|
// the mapping, and using `key_by`.
|
|
let all_users = [for name, uid in uids: { name = name, uid = uid }];
|
|
let users_by_uid = all_users.key_by(u => u.uid);
|
|
|
|
uids
|