bes  Updated for version 3.20.8
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 #include "AccessCredentials.h"
32 
33 
34 // These are the names of the bes keys used to configure the handler.
35 #define CATALOG_MANAGER_CREDENTIALS "CredentialsManager.config"
36 
38 public:
39  static const std::string ENV_ID_KEY;
40  static const std::string ENV_ACCESS_KEY;
41  static const std::string ENV_REGION_KEY;
42  //static const std::string ENV_BUCKET_KEY;
43  static const std::string ENV_URL_KEY;
44  static const std::string ENV_CREDS_KEY_VALUE;
45 
46 private:
48 
49  std::map<std::string, AccessCredentials* > creds;
50  static void initialize_instance();
51  static void delete_instance();
52  bool ngaps3CredentialsLoaded;
53 
54  AccessCredentials *load_credentials_from_env( );
55  void load_ngap_s3_credentials( );
56 
57  std::string d_netrc_filename;
58 
59 public:
61 
63 
64  static CredentialsManager *theCM(){
65  if (theMngr == 0) initialize_instance();
66  return theMngr;
67  }
68 
69  void add(const std::string &url, AccessCredentials *ac);
70  void load_credentials();
71  void clear(){ delete_instance(); }
72 
73  AccessCredentials *get(const std::string &url);
74 
75  unsigned int size(){
76  return creds.size();
77  }
78 
79  bool hasNgapS3Credentials(){
80  return ngaps3CredentialsLoaded;
81  }
82 };
83 
84 
85 
86 
87 
88 #endif //HYRAX_CREDENTIALSMANAGER_H
void add(const std::string &url, AccessCredentials *ac)
static CredentialsManager * theMngr
AccessCredentials * get(const std::string &url)