bes  Updated for version 3.20.8
NgapS3Credentials.h
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 #ifndef HYRAX_GIT_S3CREDENTIALS_H
25 #define HYRAX_GIT_S3CREDENTIALS_H
26 
27 #include "AccessCredentials.h"
28 #include <string>
29 
31 public:
32  // These are the string keys used to express the normative key names
33  // for the credentials components.
34  static const std::string AWS_SESSION_TOKEN;
35  static const std::string AWS_TOKEN_EXPIRATION;
36  static const std::string BES_CONF_S3_ENDPOINT_KEY;
37  static const std::string BES_CONF_REFRESH_KEY;
38  static const std::string BES_CONF_URL_BASE;
39 
40 private:
41  time_t d_expiration_time;
42  long refresh_margin;
43  std::string distribution_api_endpoint;
44 
45 public:
47  d_expiration_time(0), refresh_margin(600), distribution_api_endpoint("") {}
48 
49  NgapS3Credentials(const std::string &credentials_endpoint, long refresh_margin) :
50  d_expiration_time(0), refresh_margin(refresh_margin), distribution_api_endpoint(credentials_endpoint) {}
51 
53 
54  time_t expires() const {
55  return d_expiration_time;
56  }
57 
58  bool needs_refresh() const {
59  return (d_expiration_time - time(0)) < refresh_margin;
60  }
61 
62  virtual bool is_s3_cred();
63 
64  std::string get(const std::string &key);
65 
66 };
67 
68 
69 #endif //HYRAX_GIT_S3CREDENTIALS_H
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?