-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
90 lines (77 loc) · 2.98 KB
/
Copy pathProgram.cs
File metadata and controls
90 lines (77 loc) · 2.98 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System.Reflection;
using Azure.Identity;
using ciam_cli_tools.Models;
using ciam_cli_tools.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Graph;
// Build a config object, using env vars and JSON providers.
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.Build();
// Get values from the config given their key and their target type.
AppSettings settings = config.GetRequiredSection("AppSettings").Get<AppSettings>();
// Initialize the client credential auth provider
var scopes = new[] { "https://graph.microsoft.com/.default" };
var clientSecretCredential = new ClientSecretCredential(settings.TenantName, settings.AppId, settings.ClientSecret);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
await UserService.DeleteAllTestUsers(graphClient);
return;
PrintCommands();
try
{
while (true)
{
Console.Write("Enter command, then press ENTER: ");
string decision = Console.ReadLine()!;
switch (decision.ToLower())
{
case "1":
await UserService.ListUsers(graphClient);
break;
case "2":
await UserService.CreateTestUsers(graphClient, settings, false);
break;
case "3":
await UserService.CreateTestUsers(graphClient, settings, true);
break;
case "4":
await UserService.AddTestUsersToSecurityGroups(graphClient);
break;
case "5":
await UserService.DeleteAllTestUsers(graphClient);
break;
case "help":
PrintCommands();
break;
case "exit":
return;
default:
Console.WriteLine("Invalid command. Enter 'help' to show a list of commands.");
break;
}
Console.ResetColor();
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex}");
}
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
static void PrintCommands()
{
string Version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
Console.WriteLine($"App version: {Version}");
Console.WriteLine();
Console.WriteLine("Command Description");
Console.WriteLine("====================");
Console.WriteLine("[1] Get all users");
Console.WriteLine("[2] Create test users");
Console.WriteLine("[3] Add missing test users");
Console.WriteLine("[4] Add users to security groups");
Console.WriteLine("[5] Delete all test users");
Console.WriteLine("[help] Show available commands");
Console.WriteLine("[exit] Exit the program");
Console.WriteLine("-------------------------");
}