MiKTeX 26.5-next
A scalable TeX distribution
Loading...
Searching...
No Matches
RestRemoteService.h
1/* RestRemoteService.h: -*- C++ -*-
2
3 Copyright (C) 2001-2019 Christian Schenk
4
5 This file is part of MiKTeX Package Manager.
6
7 MiKTeX Package Manager is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2, or
10 (at your option) any later version.
11
12 MiKTeX Package Manager is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with MiKTeX Package Manager; if not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22#if !defined(A965AF9537944AFEA8EE4AB0D04F55B5)
23#define A965AF9537944AFEA8EE4AB0D04F55B5
24
25#include <chrono>
26#include <string>
27
28#include <miktex/Core/Session>
29
30#include <miktex/PackageManager/PackageManager>
31
32#include "RemoteService.h"
33#include "WebSession.h"
34
35MPM_INTERNAL_BEGIN_NAMESPACE;
36
37class RestRemoteService :
38 public RemoteService
39{
40public:
41 RestRemoteService(const std::string& endpoint, const MiKTeX::Packages::ProxySettings& proxySettings) :
42 endpointBaseUrl(endpoint),
43 proxySettings(proxySettings),
44 session(MIKTEX_SESSION()),
45 webSession(WebSession::Create(nullptr))
46 {
47 Initialize();
48 }
49
50public:
51 std::vector<MiKTeX::Packages::RepositoryInfo> GetRepositories(MiKTeX::Packages::RepositoryReleaseState repositoryReleaseState) override;
52
53public:
54 std::string PickRepositoryUrl(MiKTeX::Packages::RepositoryReleaseState repositoryReleaseState) override;
55
56public:
57 std::pair<bool, MiKTeX::Packages::RepositoryInfo> TryGetRepositoryInfo(const std::string& repositoryUrl) override;
58
59public:
60 MiKTeX::Packages::RepositoryInfo Verify(const std::string& url) override;
61
62private:
63 void Initialize();
64
65private:
66 void SetAuthHeader(const std::string& token)
67 {
68 webSession->SetCustomHeaders({ {"Authorization", "Bearer " + token} });
69 }
70
71private:
72 std::string MakeUrl(const std::string& path, const std::initializer_list<std::string>& query)
73 {
74 std::string url = endpointBaseUrl + path;
75 if (query.size() > 0)
76 {
77 url += "?";
78 for (const std::string& q : query)
79 {
80 url += "&" + q;
81 }
82 }
83 return url;
84 }
85
86private:
87 void SayHello();
88
89private:
90 std::string endpointBaseUrl;
91
92private:
94
95private:
96 std::shared_ptr<MiKTeX::Core::Session> session;
97
98private:
99 std::shared_ptr<WebSession> webSession;
100
101private:
102 std::string token;
103
104private:
105 std::chrono::time_point<std::chrono::system_clock> tokenNotValidAfter;
106};
107
108MPM_INTERNAL_END_NAMESPACE;
109
110#endif
Definition RemoteService.h:35
RepositoryReleaseState
Repository release state.
Definition RepositoryInfo.h:174
Definition PackageManager.h:53
Package repository info struct.
Definition RepositoryInfo.h:204