bes Updated for version 3.20.13
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#include <string>
26#include <sstream>
27
28#include "AccessCredentials.h"
29
30using std::string;
31using std::map;
32using std::pair;
33using std::stringstream;
34using std::endl;
35
36const char *AccessCredentials::ID_KEY = "id";
37const char *AccessCredentials::KEY_KEY = "key";
38const char *AccessCredentials::REGION_KEY = "region";
39const char *AccessCredentials::URL_KEY = "url";
40
46string
47AccessCredentials::get(const string &key) {
48 map<string, string>::iterator it;
49 string value={""};
50 it = kvp.find(key);
51 if (it != kvp.end())
52 value = it->second;
53 return value;
54}
55
61void
62AccessCredentials::add(const string &key, const string &value) {
63 kvp.insert(pair<string, string>(key, value));
64}
65
71 if (!d_s3_tested) {
72 d_is_s3 = get(URL_KEY).length() > 0 &&
73 get(ID_KEY).length() > 0 &&
74 get(KEY_KEY).length() > 0 &&
75 get(REGION_KEY).length() > 0; //&&
76 //get(BUCKET_KEY).length()>0;
77 d_s3_tested = true;
78 }
79 return d_is_s3;
80}
81
82string AccessCredentials::to_json() {
83 stringstream ss;
84 ss << "{" << endl << " \"AccessCredentials\": { " << endl;
85 ss << " \"name\": \"" << d_config_name << "\"," << endl;
86 for (map<string, string>::iterator it = kvp.begin(); it != kvp.end(); ++it) {
87 string key = it->first;
88 string value = it->second;
89
90 if (it != kvp.begin())
91 ss << ", " << endl;
92
93 ss << " \"" << it->first << "\": \"" << it->second << "\"";
94 }
95 ss << endl << " }" << endl << "}" << endl;
96 return ss.str();
97}
void add(const std::string &key, const std::string &value)
Add the key and value pair.
virtual std::string get(const std::string &key)
virtual bool is_s3_cred()
Do the URL, ID, Key amd Region items make up an S3 Credential?