Use collection initializers

This commit is contained in:
anomny
2025-10-04 15:11:08 +02:00
parent ef3be7cb41
commit 285a0968ec
3 changed files with 46 additions and 44 deletions

View File

@@ -36,30 +36,28 @@ public class AssetsController : Controller
{
var ownerDn = $"uid={assetModel.Owner},ou=people,dc=example,dc=com";
var attributeSet = new LdapAttributeSet();
attributeSet.Add(new LdapAttribute("objectClass", new[] {
"top",
"device",
"extensibleObject"
}));
attributeSet.Add(new LdapAttribute("cn", assetModel.Cn));
attributeSet.Add(new LdapAttribute("serialNumber", assetModel.SerialNumber));
attributeSet.Add(new LdapAttribute("l", assetModel.Location));
attributeSet.Add(new LdapAttribute("owner", ownerDn));
attributeSet.Add(new LdapAttribute("name", assetModel.Name));
attributeSet.Add(new LdapAttribute(
"description",
JsonSerializer.Serialize(new AssetDescription()
{
Type = assetModel.Description.Type,
Purchase = new AssetPurchase
LdapAttributeSet attributeSet =
[
new LdapAttribute("objectClass", new[] {"top", "device", "extensibleObject"}),
new LdapAttribute("cn", assetModel.Cn),
new LdapAttribute("serialNumber", assetModel.SerialNumber),
new LdapAttribute("l", assetModel.Location),
new LdapAttribute("owner", ownerDn),
new LdapAttribute("name", assetModel.Name),
new LdapAttribute(
"description",
JsonSerializer.Serialize(new AssetDescription()
{
PurchasedAt = assetModel.Description.Purchase.PurchasedAt,
PurchaseDate = assetModel.Description.Purchase.PurchaseDate,
PurchaseValue = assetModel.Description.Purchase.PurchaseValue
}
})
));
Type = assetModel.Description!.Type,
Purchase = new AssetPurchase
{
PurchasedAt = assetModel.Description.Purchase!.PurchasedAt,
PurchaseDate = assetModel.Description.Purchase.PurchaseDate,
PurchaseValue = assetModel.Description.Purchase.PurchaseValue
}
})
)
];
await _ldap.CreateAsset(attributeSet);

View File

@@ -65,19 +65,21 @@ public class GroupsController : Controller
try
{
description ??= JsonSerializer.Serialize(new GroupPermissions() {Permissions = []});
var attributeSet = new LdapAttributeSet();
attributeSet.Add(new LdapAttribute("objectClass", "posixGroup"));
attributeSet.Add(new LdapAttribute("objectClass", "top"));
attributeSet.Add(new LdapAttribute("cn", cn));
attributeSet.Add(new LdapAttribute("gidNumber", gidNumber));
attributeSet.Add(new LdapAttribute(
"description",
JsonSerializer.Serialize(new GroupPermissions()
{
Permissions = [.. permissions]
})));
LdapAttributeSet attributeSet =
[
new LdapAttribute("objectClass", "posixGroup"),
new LdapAttribute("objectClass", "top"),
new LdapAttribute("cn", cn),
new LdapAttribute("gidNumber", gidNumber),
new LdapAttribute(
"description",
JsonSerializer.Serialize(new GroupPermissions()
{
Permissions = [.. permissions]
}))
];
await _ldap.CreateGroup(cn, attributeSet);
return true;
}

View File

@@ -75,15 +75,17 @@ public class UsersController : Controller
userPassword = "{SHA256}" + Convert.ToBase64String(hashedPassword);
}
LdapAttributeSet attributeSet = new LdapAttributeSet();
attributeSet.Add(new LdapAttribute("objectClass", "inetOrgPerson"));
attributeSet.Add(new LdapAttribute("cn", cn));
attributeSet.Add(new LdapAttribute("sn", sn));
attributeSet.Add(new LdapAttribute("title", title));
attributeSet.Add(new LdapAttribute("uid", uid));
attributeSet.Add(new LdapAttribute("jpegPhoto", jpegPhoto));
attributeSet.Add(new LdapAttribute("description", description));
attributeSet.Add(new LdapAttribute("userPassword", userPassword));
LdapAttributeSet attributeSet =
[
new LdapAttribute("objectClass", "inetOrgPerson"),
new LdapAttribute("cn", cn),
new LdapAttribute("sn", sn),
new LdapAttribute("title", title),
new LdapAttribute("uid", uid),
new LdapAttribute("jpegPhoto", jpegPhoto),
new LdapAttribute("description", description),
new LdapAttribute("userPassword", userPassword),
];
await _ldap.CreateUser(uid, attributeSet);
return true;
}