// Copyright Epic Games, Inc. All Rights Reserved.
using EpicGames.Horde.Acls;
using HordeServer.Acls;
namespace HordeServer.Utilities
{
///
/// Utility class for allowing plugins to modify the default ACL used by the server
///
public class DefaultAclBuilder
{
readonly List _roles = new List();
readonly HashSet _readActions = new HashSet();
readonly HashSet _writeActions = new HashSet();
///
/// Adds a custom role with a certain set of entitlements
///
/// Claim to identify users that should be granted the entitlements
/// Actions to allow the user to perform
public void AddCustomRole(AclClaimConfig claim, AclAction[] actions)
=> _roles.Add(new AclEntryConfig(claim, actions));
///
/// Adds a default read operation that users can perform
///
public void AddDefaultReadAction(AclAction action)
=> _readActions.Add(action);
///
/// Adds a default write operation that users can perform
///
public void AddDefaultWriteAction(AclAction action)
=> _writeActions.Add(action);
///
/// Create the new acl config
///
public AclConfig Build()
{
AclConfig config = new AclConfig();
config.Entries = _roles.ToList();
config.Profiles = new List();
config.Profiles.Add(new AclProfileConfig
{
Id = new AclProfileId("default-read"),
Actions = _readActions.ToList()
});
config.Profiles.Add(new AclProfileConfig
{
Id = new AclProfileId("default-run"),
Extends = new List
{
new AclProfileId("default-read")
},
Actions = _writeActions.ToList()
});
return config;
}
}
}