bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
AccessCredentials.cc
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of the Hyrax data server.
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
24#include "config.h"
25
26#include <string>
27#include <sstream>
28
29#include "AccessCredentials.h"
30
31using std::string;
32using std::map;
33using std::pair;
34using std::stringstream;
35using std::endl;
36
37namespace http {
38
39const char *AccessCredentials::ID_KEY = "id";
40const char *AccessCredentials::KEY_KEY = "key";
41const char *AccessCredentials::REGION_KEY = "region";
42const char *AccessCredentials::URL_KEY = "url";
43
49string
50AccessCredentials::get(const string &key) {
52 string value;
53 it = d_kvp.find(key);
54 if (it != d_kvp.end())
55 value = it->second;
56 return value;
57}
58
64void
65AccessCredentials::add(const string &key, const string &value) {
66 d_kvp.insert(pair<string, string>(key, value));
67}
68
74 if (!d_s3_tested) {
75 d_is_s3 = !(get(URL_KEY).empty() || get(ID_KEY).empty() || get(KEY_KEY).empty() || get(REGION_KEY).empty());
76 d_s3_tested = true;
77 }
78 return d_is_s3;
79}
80
81string AccessCredentials::to_json() const {
82 stringstream ss;
83 ss << "{" << endl << R"( "AccessCredentials": { )" << endl;
84 ss << R"( "name": ")" << d_config_name << R"(",)" << endl;
85 bool first = true;
86 for (const auto &item: d_kvp) {
87 string key = item.first;
88 string value = item.second;
89
90 if (first) {
91 first = false;
92 ss << ", " << endl;
93 }
94
95 ss << R"( ")" << item.first << R"(": ")" << item.second << R"(")";
96 }
97 ss << endl << " }" << endl << "}" << endl;
98 return ss.str();
99}
100
101} // namespace http
virtual bool is_s3_cred()
Do the URL, ID, Key amd Region items make up an S3 Credential?
virtual std::string get(const std::string &key)
virtual void add(const std::string &key, const std::string &value)
Add the key and value pair.
STL iterator class.
utility class for the HTTP catalog module
Definition TheBESKeys.h:51