-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatalogCreateIfNotExist.cs
More file actions
74 lines (65 loc) · 2.74 KB
/
CatalogCreateIfNotExist.cs
File metadata and controls
74 lines (65 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Microsoft.Graph;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ap_cli
{
internal partial class Program
{
static async Task<AccessPackageCatalog> CatalogCreateIfNotExists(GraphServiceClient graphServiceClient, string spokeCatalogDisplayName)
{
var catalogList = await GetCatalogList(graphServiceClient);
AccessPackageCatalog spokeAccessPackageCatalog = catalogList.FirstOrDefault<AccessPackageCatalog>(x => x.DisplayName == spokeCatalogDisplayName);
if (spokeAccessPackageCatalog is null)
{
spokeAccessPackageCatalog = await CreateCatalog(graphServiceClient, spokeCatalogDisplayName);
Console.WriteLine(string.Format("{0} catalog created.", spokeCatalogDisplayName));
}
else
{
Console.WriteLine(string.Format("{0} catalog already exists.", spokeCatalogDisplayName));
}
return spokeAccessPackageCatalog;
}
private static async Task<IEntitlementManagementCatalogsCollectionPage> GetCatalogList(GraphServiceClient graphServiceClient)
{
try
{
var catalogs = await graphServiceClient.IdentityGovernance.EntitlementManagement.Catalogs
.Request()
.GetAsync();
Console.WriteLine($"Found {catalogs.Count()} catalogs in the tenant");
return catalogs;
}
catch (ServiceException e)
{
Console.WriteLine("We could not retrieve the App Catalog's list: " + $"{e}");
}
return null;
}
private static async Task<AccessPackageCatalog> CreateCatalog(GraphServiceClient graphServiceClient, string spokeCatalogDisplayName)
{
try
{
var accessPackageCatalog = new AccessPackageCatalog
{
DisplayName = spokeCatalogDisplayName,
Description = spokeCatalogDisplayName,
IsExternallyVisible = true,
//Type note supported CatalogType = AccessPackageCatalogType.ServiceManaged,
};
var createdAccessPackageCatalog = await graphServiceClient.IdentityGovernance.EntitlementManagement.Catalogs
.Request()
.AddAsync(accessPackageCatalog);
return createdAccessPackageCatalog;
}
catch (ServiceException e)
{
Console.WriteLine("We could not create the Spoke Specific App Catalog: " + $"{e}");
return null;
}
}
}
}