master
cpp 67 lines 1.91 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 RegistryTasks.cpp
8
9 Abstract:
10
11 Implementation of registry command related execution logic.
12
13 --*/
14 #include "Argument.h"
15 #include "ArgumentConvertedTypes.h"
16 #include "CLIExecutionContext.h"
17 #include "RegistryService.h"
18 #include "RegistryTasks.h"
19 #include "Task.h"
20
21 using namespace wsl::shared;
22 using namespace wsl::windows::common::string;
23 using namespace wsl::windows::common::wslutil;
24 using namespace wsl::windows::wslc::execution;
25 using namespace wsl::windows::wslc::services;
26
27 namespace wsl::windows::wslc::task {
28
29 void Login(CLIExecutionContext& context)
30 {
31 WI_ASSERT(context.Data.Contains(Data::Session));
32 WI_ASSERT(context.Args.Contains(ArgType::Username));
33 WI_ASSERT(context.Args.Contains(ArgType::Password));
34
35 auto& session = context.Data.Get<Data::Session>();
36
37 auto username = WideToMultiByte(context.Args.GetValue<ArgType::Username>());
38 auto password = WideToMultiByte(context.Args.GetValue<ArgType::Password>());
39
40 auto serverAddress = std::string(RegistryService::DefaultServer);
41
42 if (context.Args.Contains(ArgType::Server))
43 {
44 serverAddress = WideToMultiByte(context.Args.GetValue<ArgType::Server>());
45 }
46
47 auto [credUsername, credSecret] = RegistryService::Authenticate(session, serverAddress, username, password);
48 RegistryService::Store(serverAddress, credUsername, credSecret);
49
50 context.Terminal.Output(L"{}\n", Localization::WSLCCLI_LoginSucceeded());
51 }
52
53 void Logout(CLIExecutionContext& context)
54 {
55 auto serverAddress = std::string(RegistryService::DefaultServer);
56
57 if (context.Args.Contains(ArgType::Server))
58 {
59 serverAddress = WideToMultiByte(context.Args.GetValue<ArgType::Server>());
60 }
61
62 RegistryService::Erase(serverAddress);
63
64 context.Terminal.Output(L"{}\n", Localization::WSLCCLI_LogoutSucceeded(MultiByteToWide(serverAddress)));
65 }
66
67 } // namespace wsl::windows::wslc::task