bes  Updated for version 3.20.10
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 <memory>
30 #include <string>
31 #include <vector>
32 #include <mutex>
33 #include "url_impl.h"
34 #include "AccessCredentials.h"
35 
36 
37 // These are the names of the bes keys used to configure the handler.
38 #define CATALOG_MANAGER_CREDENTIALS "CredentialsManager.config"
39 
41 public:
42  static const char* ENV_ID_KEY;
43  static const char* ENV_ACCESS_KEY;
44  static const char* ENV_REGION_KEY;
45  static const char* ENV_BUCKET_KEY;
46  static const char* ENV_URL_KEY;
47  static const char* USE_ENV_CREDS_KEY_VALUE;
48 
49 private:
50  std::recursive_mutex d_lock_mutex{};
51  // std::string d_netrc_filename;
52  bool ngaps3CredentialsLoaded;
53 
54  std::map<std::string, AccessCredentials* > creds;
55 
57 
58  static void initialize_instance();
59  static void delete_instance();
60  AccessCredentials *load_credentials_from_env( );
61  void load_ngap_s3_credentials( );
62 
63 
64 public:
66 
68  static CredentialsManager *theCM();
69 
70  void add(const std::string &url, AccessCredentials *ac);
71  void load_credentials();
72 
73  void clear(){
74  creds.clear();
75  ngaps3CredentialsLoaded = false;
76  }
77 
78  AccessCredentials *get(std::shared_ptr<http::url> &url);
79 
80  unsigned int size(){
81  return creds.size();
82  }
83 
84  bool hasNgapS3Credentials(){
85  return ngaps3CredentialsLoaded;
86  }
87 };
88 
89 
90 
91 
92 
93 #endif //HYRAX_CREDENTIALSMANAGER_H
void add(const std::string &url, AccessCredentials *ac)
static CredentialsManager * theMngr
AccessCredentials * get(std::shared_ptr< http::url > &url)
static CredentialsManager * theCM()
Returns the singleton instance of the CrednetialsManager.