public IPage <Vault> ListBySubscription(int?top = null) { TestPage <Vault> ret = new TestPage <Vault>(); var vaults = KeyVaults.ToLookup(v => v.SubscriptionId)[TestKVMClient.subid]; foreach (KeyVaultProperties kv in vaults) { var aps = new List <AccessPolicyEntry>(); foreach (PrincipalPermissions pp in kv.AccessPolicies) { var objectId = ""; if (pp.Type.ToLower() == "user") { if (pp.DisplayName.ToLower().Contains('a')) { objectId = "ua"; } else if (pp.DisplayName.ToLower().Contains('b')) { objectId = "ub"; } else if (pp.DisplayName.ToLower().Contains('c')) { objectId = "uc"; } } else { objectId = pp.DisplayName; } aps.Add(new AccessPolicyEntry { ObjectId = objectId, TenantId = new Guid("00000000-0000-0000-0000-000000000000"), Permissions = new Permissions { Certificates = pp.PermissionsToCertificates, Secrets = pp.PermissionsToSecrets, Keys = pp.PermissionsToKeys, } }); } var properties = new VaultProperties { AccessPolicies = aps, TenantId = new Guid("00000000-0000-0000-0000-000000000000"), }; ret.Add(new Vault(properties, $"subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/{kv.ResourceGroupName}", kv.VaultName, null, "eastus", null)); } return(ret); }
public Vault Get(string resourceGroupName, string vaultName) { var vault = KeyVaults.ToLookup(kv => kv.VaultName)[vaultName].First(); var aps = new List <AccessPolicyEntry>(); foreach (PrincipalPermissions pp in vault.AccessPolicies) { var objectId = ""; if (pp.Type.ToLower() == "user") { if (pp.DisplayName.ToLower().Contains('a')) { objectId = "ua"; } else if (pp.DisplayName.ToLower().Contains('b')) { objectId = "ub"; } else if (pp.DisplayName.ToLower().Contains('c')) { objectId = "uc"; } } else { objectId = pp.DisplayName; } aps.Add(new AccessPolicyEntry { ObjectId = objectId, TenantId = new Guid("00000000-0000-0000-0000-000000000000"), Permissions = new Permissions { Certificates = pp.PermissionsToCertificates, Secrets = pp.PermissionsToSecrets, Keys = pp.PermissionsToKeys, } }); } var properties = new VaultProperties { AccessPolicies = aps, TenantId = new Guid("00000000-0000-0000-0000-000000000000"), }; var ret = new Vault(properties, $"subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/{resourceGroupName}", vault.VaultName, null, "eastus", null); return(ret); }