comparison Plugin/GoogleAccount.h @ 0:520cba9a0d42

initial commit
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 13 Jun 2019 14:57:22 +0200
parents
children d9e1b60a9aa6
comparison
equal deleted inserted replaced
-1:000000000000 0:520cba9a0d42
1 /**
2 * Google Cloud Platform credentials for DICOMweb and Orthanc
3 * Copyright (C) 2019 Osimis S.A., Belgium
4 *
5 * This program is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * In addition, as a special exception, the copyright holders of this
11 * program give permission to link the code of its release with the
12 * OpenSSL project's "OpenSSL" library (or with modified versions of it
13 * that use the same license as the "OpenSSL" library), and distribute
14 * the linked executables. You must obey the GNU General Public License
15 * in all respects for all of the code used other than "OpenSSL". If you
16 * modify file(s) with this exception, you may extend this exception to
17 * your version of the file(s), but you are not obligated to do so. If
18 * you do not wish to do so, delete this exception statement from your
19 * version. If you delete this exception statement from all source files
20 * in the program, then also delete it here.
21 *
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 **/
30
31
32 #pragma once
33
34 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h>
35
36 #include <google/cloud/storage/oauth2/authorized_user_credentials.h>
37 #include <google/cloud/storage/oauth2/service_account_credentials.h>
38
39
40 class GoogleAccount : public boost::noncopyable
41 {
42 public:
43 enum Type
44 {
45 Type_AuthorizedUser,
46 Type_ServiceAccount
47 };
48
49 private:
50 Type type_;
51 std::string name_;
52 std::string project_;
53 std::string location_;
54 std::string dataset_;
55 std::string dicomStore_;
56
57 std::unique_ptr<google::cloud::storage::oauth2::AuthorizedUserCredentialsInfo> authorizedUser_;
58 std::unique_ptr<google::cloud::storage::oauth2::ServiceAccountCredentialsInfo> serviceAccount_;
59
60
61 void LoadAuthorizedUser(const std::string& json);
62
63 bool LoadServiceAccount(const OrthancPlugins::OrthancConfiguration& account);
64
65 bool LoadAuthorizedUserFile(const OrthancPlugins::OrthancConfiguration& account);
66
67 bool LoadAuthorizedUserStrings(const OrthancPlugins::OrthancConfiguration& account);
68
69 public:
70 GoogleAccount(const OrthancPlugins::OrthancConfiguration& account,
71 const std::string& name);
72
73 Type GetType() const
74 {
75 return type_;
76 }
77
78 const std::string& GetName() const
79 {
80 return name_;
81 }
82
83 const std::string& GetProject() const
84 {
85 return project_;
86 }
87
88 const std::string& GetLocation() const
89 {
90 return location_;
91 }
92
93 const std::string& GetDataset() const
94 {
95 return dataset_;
96 }
97
98 const std::string& GetDicomStore() const
99 {
100 return dicomStore_;
101 }
102
103 const google::cloud::storage::oauth2::AuthorizedUserCredentialsInfo& GetAuthorizedUser() const;
104
105 google::cloud::storage::oauth2::ServiceAccountCredentialsInfo& GetServiceAccount() const;
106
107 bool UpdateServerDefinition(const std::string& dicomWebPluginRoot,
108 const std::string& baseGoogleUrl,
109 const std::string& token) const;
110 };