GDAL

cpl_swift.h
1/**********************************************************************
2 * Project: CPL - Common Portability Library
3 * Purpose: OpenStack Swift Object Storage routines
4 * Author: Even Rouault <even.rouault at spatialys.com>
5 *
6 **********************************************************************
7 * Copyright (c) 2018, Even Rouault <even.rouault at spatialys.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 ****************************************************************************/
27
28#ifndef CPL_SWIFT_INCLUDED_H
29#define CPL_SWIFT_INCLUDED_H
30
31#ifndef DOXYGEN_SKIP
32
33#ifdef HAVE_CURL
34
35#include <curl/curl.h>
36#include "cpl_http.h"
37#include "cpl_aws.h"
38#include "cpl_json.h"
39#include <map>
40
41 class VSISwiftHandleHelper final : public IVSIS3LikeHandleHelper
42{
43 std::string m_osURL;
44 std::string m_osStorageURL;
45 std::string m_osAuthToken;
46 std::string m_osBucket;
47 std::string m_osObjectKey;
48
49 static bool GetConfiguration(const std::string &osPathForOption,
50 std::string &osStorageURL,
51 std::string &osAuthToken);
52
53 static bool GetCached(const std::string &osPathForOption,
54 const char *pszURLKey, const char *pszUserKey,
55 const char *pszPasswordKey, std::string &osStorageURL,
56 std::string &osAuthToken);
57
58 static std::string BuildURL(const std::string &osStorageURL,
59 const std::string &osBucket,
60 const std::string &osObjectKey);
61
62 void RebuildURL() override;
63
64 // V1 Authentication
65 static bool CheckCredentialsV1(const std::string &osPathForOption);
66 static bool AuthV1(const std::string &osPathForOption,
67 std::string &osStorageURL, std::string &osAuthToken);
68
69 // V3 Authentication
70 static bool CheckCredentialsV3(const std::string &osPathForOption,
71 const std::string &osAuthType);
72 static bool AuthV3(const std::string &osPathForOption,
73 const std::string &osAuthType, std::string &osStorageURL,
74 std::string &osAuthToken);
75 static CPLJSONObject
76 CreateAuthV3RequestObject(const std::string &osPathForOption,
77 const std::string &osAuthType);
78 static bool GetAuthV3StorageURL(const std::string &osPathForOption,
79 const CPLHTTPResult *psResult,
80 std::string &storageURL);
81
82 public:
83 VSISwiftHandleHelper(const std::string &osStorageURL,
84 const std::string &osAuthToken,
85 const std::string &osBucket,
86 const std::string &osObjectKey);
87 ~VSISwiftHandleHelper();
88
89 bool Authenticate(const std::string &osPathForOption);
90
91 static VSISwiftHandleHelper *BuildFromURI(const char *pszURI,
92 const char *pszFSPrefix);
93
94 struct curl_slist *
95 GetCurlHeaders(const std::string &osVerbosVerb,
96 const struct curl_slist *psExistingHeaders,
97 const void *pabyDataContent = nullptr,
98 size_t nBytesContent = 0) const override;
99
100 const std::string &GetURL() const override
101 {
102 return m_osURL;
103 }
104
105 static void CleanMutex();
106 static void ClearCache();
107};
108
109#endif /* HAVE_CURL */
110
111#endif /* #ifndef DOXYGEN_SKIP */
112
113#endif /* CPL_SWIFT_INCLUDED_H */
CPLJSONObject
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition cpl_json.h:57
cpl_http.h
Interface for downloading HTTP, FTP documents.
cpl_json.h
Interface for read and write JSON documents.
CPLHTTPResult
Definition cpl_http.h:68