in configTools/src/main/scala/com/gu/janus/config/Loader.scala [94:131]
private[config] def loadAccess(
config: Config,
permissions: Set[Permission]
): Either[String, ACL] = {
for {
configuredAccess <- config
.as[ConfiguredAccess]("janus.access")
.left
.map(err =>
s"Failed to load access from path `janus.access`: ${err.getMessage}"
)
defaultAccess <- configuredAccess.defaultPermissions.traverse {
configuredAclEntry =>
permissions
.find(p =>
configuredAclEntry.account == p.account.authConfigKey && configuredAclEntry.label == p.label
)
.toRight(
s"The 'default permissions' section of the access definition includes a permission that doesn't appear to be defined.\nIt has label `${configuredAclEntry.label}` and refers to the account with key ${configuredAclEntry.account}"
)
}
acl <- configuredAccess.acl.toList.traverse {
case (username, configuredAclEntries) =>
for {
userPermissions <- configuredAclEntries.traverse {
configuredAclEntry =>
permissions
.find(p =>
configuredAclEntry.account == p.account.authConfigKey && configuredAclEntry.label == p.label
)
.toRight(
s"The access configuration for `$username` includes a permission that doesn't appear to be defined.\nIt has label `${configuredAclEntry.label}` and refers to the account with key ${configuredAclEntry.account}"
)
}
} yield username -> userPermissions.toSet
}
} yield ACL(acl.toMap, defaultAccess.toSet)
}