-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWacsdkUserDeleteCommand.cs
More file actions
64 lines (52 loc) · 2.43 KB
/
WacsdkUserDeleteCommand.cs
File metadata and controls
64 lines (52 loc) · 2.43 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
using OwlCore.Diagnostics;
using OwlCore.Storage;
using System.CommandLine;
using WindowsAppCommunity.Sdk.Nomad;
namespace WindowsAppCommunity.CommandLine.User
{
/// <summary>
/// Command to delete an existing user.
/// </summary>
public class WacsdkUserDeleteCommand : Command
{
/// <summary>
/// Initializes a new instance of the <see cref="WacsdkUserDeleteCommand"/> class.
/// </summary>
public WacsdkUserDeleteCommand(WacsdkCommandConfig config, Option<string> repoOption)
: base(name: "delete", description: "Deletes a user.")
{
var userIdOption = new Option<string>(
name: "--user-id",
description: "The ID of the user to delete.")
{
IsRequired = true
};
AddOption(repoOption);
AddOption(userIdOption);
this.SetHandler(InvokeAsync, repoOption, userIdOption);
Config = config;
}
/// <summary>
/// Shared command configuration.
/// </summary>
public WacsdkCommandConfig Config { get; }
/// <summary>
/// Handles the command.
/// </summary>
public async Task InvokeAsync(string repoId, string userId)
{
var thisRepoStorage = (IModifiableFolder)await Config.RepositoryStorage.CreateFolderAsync(repoId, overwrite: false);
Logger.LogInformation($"Getting repo store with ID {repoId} at {thisRepoStorage.GetType().Name} {thisRepoStorage.Id}");
var repoSettings = new WacsdkNomadSettings(thisRepoStorage);
await repoSettings.LoadAsync(Config.CancellationToken);
var repositoryContainer = new RepositoryContainer(Config.KuboOptions, Config.Client, repoSettings.ManagedKeys, repoSettings.ManagedUserConfigs, repoSettings.ManagedProjectConfigs, repoSettings.ManagedPublisherConfigs);
Logger.LogInformation($"Getting user {userId}");
var user = (ModifiableUser)await repositoryContainer.UserRepository.GetAsync(userId, Config.CancellationToken);
Logger.LogInformation($"Deleting user {userId}");
await repositoryContainer.UserRepository.DeleteAsync(user, Config.CancellationToken);
Logger.LogInformation($"Saving repository changes");
await repoSettings.SaveAsync(Config.CancellationToken);
Logger.LogInformation($"Deleted user {userId}");
}
}
}