bes  Updated for version 3.20.6
CredentialsManager.h
1 // -*- mode: c++; c-basic-offset:4 -*-
2 
3 // This file is part of the BES
4 
5 // Copyright (c) 2020 OPeNDAP, Inc.
6 // Author: Nathan Potter<ndp@opendap.org>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 //
22 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
23 // Created by ndp on 12/11/19.
24 //
25 
26 #ifndef HYRAX_CREDENTIALSMANAGER_H
27 #define HYRAX_CREDENTIALSMANAGER_H
28 
29 #include <string>
30 #include <vector>
31 
32 
33 // These are the names of the bes keys used to configure the handler.
34 #define CATALOG_MANAGER_CREDENTIALS "CredentialsManager.config"
35 
37 public:
38  // These are the string keys used to express the normative key names
39  // for the credentials components.
40  static const std::string ID_KEY;
41  static const std::string KEY_KEY;
42  static const std::string REGION_KEY;
43  static const std::string BUCKET_KEY;
44  static const std::string URL_KEY;
45 private:
46  std::map<std::string, std::string> kvp;
47  bool s3_tested, is_s3;
48  std::string d_config_name;
49 public:
50  AccessCredentials()= default;
51  AccessCredentials(std::string config_name){ d_config_name = config_name;}
52  AccessCredentials(const AccessCredentials &ac) = default;
53 
54  std::string get(const std::string &key);
55  void add(const std::string &key, const std::string &value);
56  bool isS3Cred();
57  std::string to_json();
58  std::string name(){ return d_config_name; }
59 };
60 
61 
62 
64 public:
65  static const std::string ENV_ID_KEY;
66  static const std::string ENV_ACCESS_KEY;
67  static const std::string ENV_REGION_KEY;
68  static const std::string ENV_BUCKET_KEY;
69  static const std::string ENV_URL_KEY;
70  static const std::string ENV_CREDS_KEY_VALUE;
71 
72 private:
73  std::map<std::string, AccessCredentials* > creds;
75  static void initialize_instance();
76  static void delete_instance();
77 
78  static AccessCredentials *load_credentials_from_env( );
79 
80 public:
82 
84 
85  static CredentialsManager *theCM(){
86  if (theMngr == 0) initialize_instance();
87  return theMngr;
88  }
89 
90  void add(const std::string &url, AccessCredentials *ac);
91  static void load_credentials();
92  static void clear(){ delete_instance(); }
93 
94  AccessCredentials *get(const std::string &url);
95 
96 
97  unsigned int size(){
98  return creds.size();
99  }
100 
101 };
102 
103 
104 
105 
106 
107 #endif //HYRAX_CREDENTIALSMANAGER_H
CredentialsManager
Definition: CredentialsManager.h:63
AccessCredentials::get
std::string get(const std::string &key)
Definition: CredentialsManager.cc:418
CredentialsManager::add
void add(const std::string &url, AccessCredentials *ac)
Definition: CredentialsManager.cc:154
AccessCredentials::add
void add(const std::string &key, const std::string &value)
Definition: CredentialsManager.cc:433
CredentialsManager::load_credentials
static void load_credentials()
Definition: CredentialsManager.cc:269
CredentialsManager::get
AccessCredentials * get(const std::string &url)
Definition: CredentialsManager.cc:166
AccessCredentials
Definition: CredentialsManager.h:36
CredentialsManager::~CredentialsManager
~CredentialsManager()
Definition: CredentialsManager.cc:114
AccessCredentials::isS3Cred
bool isS3Cred()
Definition: CredentialsManager.cc:443
CredentialsManager::theMngr
static CredentialsManager * theMngr
Definition: CredentialsManager.h:81