bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
NgapOwnedContainer.h
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of ngap_module, A C++ module that can be loaded in to
4// the OPeNDAP Back-End Server (BES) and is able to handle remote requests.
5
6// Copyright (c) 2020, 2024 OPeNDAP, Inc.
7// Author: Nathan Potter <ndp@opendap.org>,
8// James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26
27#ifndef NgapOwnedContainer_h_
28#define NgapOwnedContainer_h_ 1
29
30#include <string>
31#include <map>
32#include <memory>
33
34#include "BESContainer.h"
35
36namespace http {
37class RemoteResource;
38}
39
40namespace ngap {
41
61class NgapOwnedContainer: public BESContainer {
62
63 std::string d_ngap_path; // The (in)famous REST path
64 static std::string d_data_source_location;
65 static bool d_use_opendap_bucket;
66 static bool d_inject_data_url;
67
68 bool get_dmrpp_from_cache_or_remote_source(std::string &dmrpp_string) const;
69
70 // I made these static so that they will be in the class' namespace but still
71 // be easy to test in the unit tests. jhrg 4/29/24
72 static bool file_to_string(int fd, std::string &content);
73
74 static bool get_daac_content_filters(const std::string &data_url, std::map<std::string, std::string, std::less<>> &content_filters);
75 static bool get_opendap_content_filters(std::map<std::string, std::string, std::less<>> &content_filters);
76 static void filter_response(const std::map<std::string, std::string, std::less<>> &content_filters, std::string &content);
77
78 static std::string build_dmrpp_url_to_owned_bucket(const std::string &rest_path, const std::string &data_source);
79 static std::string build_data_url_to_daac_bucket(const std::string &rest_path);
80
81 bool dmrpp_read_from_opendap_bucket(std::string &dmrpp_string) const;
82 void dmrpp_read_from_daac_bucket(std::string &dmrpp_string) const;
83
84 bool get_item_from_dmrpp_cache(std::string &dmrpp_string) const;
85 bool put_item_in_dmrpp_cache(const std::string &dmrpp_string) const;
86
87 friend class NgapOwnedContainerTest;
88
89protected:
90 void _duplicate(NgapOwnedContainer &copy_to) {
91 copy_to.d_ngap_path = d_ngap_path;
93 }
94
95public:
96 NgapOwnedContainer() = default;
97 NgapOwnedContainer(const NgapOwnedContainer &copy_from) = delete;
98 NgapOwnedContainer(NgapOwnedContainer &&move_from) = delete;
99 NgapOwnedContainer &operator=(const NgapOwnedContainer &rhs) = delete;
100 NgapOwnedContainer &operator=(NgapOwnedContainer &&rhs) = delete;
101 ~NgapOwnedContainer() override = default;
102
103 NgapOwnedContainer(const std::string &sym_name, const std::string &real_name, const std::string &);
104
105 BESContainer *ptr_duplicate() override {
106 auto container = std::make_unique<NgapOwnedContainer>();
107 _duplicate(*container);
108 return container.release();
109 }
110
111 void set_ngap_path(const std::string &ngap_path) { d_ngap_path = ngap_path; }
112 std::string get_ngap_path() const { return d_ngap_path; }
113
115 static void set_data_source_location(const std::string &data_source_location) {
116 d_data_source_location = data_source_location;
117 }
118 static std::string get_data_source_location() { return d_data_source_location; }
119
120 std::string access() override;
121
122 bool release() override {
123 return true;
124 }
125
126 void dump(std::ostream &strm) const override;
127};
128
129} // namespace ngap
130
131#endif // NgapOwnedContainer_h_
void _duplicate(BESContainer &copy_to)
duplicate this instance into the passed container
void dump(std::ostream &strm) const override
dumps information about this object
static void set_data_source_location(const std::string &data_source_location)
Set the S3 bucket used for 'owned' DMR++ documents.
BESContainer * ptr_duplicate() override
pure abstract method to duplicate this instances of BESContainer
std::string access() override
Get the DMR++ from a remote source or a local cache.
utility class for the HTTP catalog module
Definition TheBESKeys.h:51