bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
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
34#include "url_impl.h"
35#include "AccessCredentials.h"
36
37// These are the names of the bes keys used to configure the handler.
38#define CATALOG_MANAGER_CREDENTIALS "CredentialsManager.config"
39
40namespace http {
41
42class CredentialsManager {
43public:
44 static const char *ENV_ID_KEY;
45 static const char *ENV_ACCESS_KEY;
46 static const char *ENV_REGION_KEY;
47 static const char *ENV_URL_KEY;
48 static const char *USE_ENV_CREDS_KEY_VALUE;
49
50private:
51 std::recursive_mutex d_lock_mutex{};
52
53 bool ngaps3CredentialsLoaded = false;
54 std::map<std::string, AccessCredentials *> creds;
55
56 CredentialsManager() = default; // only called here to build the singleton
57
58 // These are static because they must use C-linkage.
59 static void initialize_instance();
60 static void delete_instance();
61
62 void load_credentials();
63 AccessCredentials *load_credentials_from_env();
64
65 friend class CredentialsManagerTest;
66 friend class CurlUtilsTest;
67
68public:
69 static CredentialsManager *theMngr;
70
71 ~CredentialsManager();
72
73 static CredentialsManager *theCM();
74
75 void add(const std::string &url, AccessCredentials *ac);
76
77 void clear() {
78 creds.clear();
79 ngaps3CredentialsLoaded = false;
80 }
81
82 AccessCredentials *get(const std::shared_ptr<http::url> &url);
83 AccessCredentials *get(const std::string &url);
84
85 size_t size() const {
86 return creds.size();
87 }
88
89 bool hasNgapS3Credentials() const {
90 return ngaps3CredentialsLoaded;
91 }
92};
93
94} // namespace http
95
96#endif //HYRAX_CREDENTIALSMANAGER_H
static CredentialsManager * theCM()
Returns the singleton instance of the CredentialsManager.
AccessCredentials * get(const std::shared_ptr< http::url > &url)
void add(const std::string &url, AccessCredentials *ac)
static CredentialsManager * theMngr
Our singleton instance.
Parse a URL into the protocol, host, path and query parts.
Definition url_impl.h:44
utility class for the HTTP catalog module
Definition TheBESKeys.h:51