bes  Updated for version 3.20.10
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 #if 0
26 #include "CredentialsManager.h"
27 #include <BESDebug.h>
28 #include <BESInternalError.h>
29 #include <kvp_utils.h>
30 #include <TheBESKeys.h>
31 #include <AllowedHosts.h>
32 #include <sys/stat.h>
33 #endif
34 #include <string>
35 #include <sstream>
36 #if 0
37 #include <locale>
38 
39 #include <iomanip>
40 #include <cstring>
41 
42 #endif
43 #include "AccessCredentials.h"
44 
45 using std::string;
46 using std::map;
47 using std::pair;
48 using std::stringstream;
49 using std::endl;
50 
51 #if 0
52 // Scope: public members of AccessCredentials
53 const string AccessCredentials::ID_KEY = "id";
54 const string AccessCredentials::KEY_KEY = "key";
55 const string AccessCredentials::REGION_KEY = "region";
56 const string AccessCredentials::URL_KEY = "url";
57 #else
58 const char *AccessCredentials::ID_KEY = "id";
59 const char *AccessCredentials::KEY_KEY = "key";
60 const char *AccessCredentials::REGION_KEY = "region";
61 const char *AccessCredentials::URL_KEY = "url";
62 #endif
63 
69 string
70 AccessCredentials::get(const string &key) {
71  map<string, string>::iterator it;
72  string value={""};
73  it = kvp.find(key);
74  if (it != kvp.end())
75  value = it->second;
76  return value;
77 }
78 
84 void
85 AccessCredentials::add(const string &key, const string &value) {
86  kvp.insert(pair<string, string>(key, value));
87 }
88 
94  if (!d_s3_tested) {
95  d_is_s3 = get(URL_KEY).length() > 0 &&
96  get(ID_KEY).length() > 0 &&
97  get(KEY_KEY).length() > 0 &&
98  get(REGION_KEY).length() > 0; //&&
99  //get(BUCKET_KEY).length()>0;
100  d_s3_tested = true;
101  }
102  return d_is_s3;
103 }
104 
105 string AccessCredentials::to_json() {
106  stringstream ss;
107  ss << "{" << endl << " \"AccessCredentials\": { " << endl;
108  ss << " \"name\": \"" << d_config_name << "\"," << endl;
109  for (map<string, string>::iterator it = kvp.begin(); it != kvp.end(); ++it) {
110  string key = it->first;
111  string value = it->second;
112 
113  if (it != kvp.begin())
114  ss << ", " << endl;
115 
116  ss << " \"" << it->first << "\": \"" << it->second << "\"";
117  }
118  ss << endl << " }" << endl << "}" << endl;
119  return ss.str();
120 }
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?