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 * SPDX-License-Identifier: MIT
10 ****************************************************************************/
11
12#ifndef CPL_SWIFT_INCLUDED_H
13#define CPL_SWIFT_INCLUDED_H
14
15#ifndef DOXYGEN_SKIP
16
17#ifdef HAVE_CURL
18
19#include <curl/curl.h>
20#include "cpl_http.h"
21#include "cpl_aws.h"
22#include "cpl_json.h"
23#include <map>
24
25class VSISwiftHandleHelper final : public IVSIS3LikeHandleHelper
26{
27 std::string m_osURL;
28 std::string m_osStorageURL;
29 std::string m_osAuthToken;
30 std::string m_osBucket;
31 std::string m_osObjectKey;
32
33 static bool GetConfiguration(const std::string &osPathForOption,
34 std::string &osStorageURL,
35 std::string &osAuthToken);
36
37 static bool GetCached(const std::string &osPathForOption,
38 const char *pszURLKey, const char *pszUserKey,
39 const char *pszPasswordKey, std::string &osStorageURL,
40 std::string &osAuthToken);
41
42 static std::string BuildURL(const std::string &osStorageURL,
43 const std::string &osBucket,
44 const std::string &osObjectKey);
45
46 void RebuildURL() override;
47
48 // V1 Authentication
49 static bool CheckCredentialsV1(const std::string &osPathForOption);
50 static bool AuthV1(const std::string &osPathForOption,
51 std::string &osStorageURL, std::string &osAuthToken);
52
53 // V3 Authentication
54 static bool CheckCredentialsV3(const std::string &osPathForOption,
55 const std::string &osAuthType);
56 static bool AuthV3(const std::string &osPathForOption,
57 const std::string &osAuthType, std::string &osStorageURL,
58 std::string &osAuthToken);
59 static CPLJSONObject
60 CreateAuthV3RequestObject(const std::string &osPathForOption,
61 const std::string &osAuthType);
62 static bool GetAuthV3StorageURL(const std::string &osPathForOption,
63 const CPLHTTPResult *psResult,
64 std::string &storageURL);
65
66 public:
67 VSISwiftHandleHelper(const std::string &osStorageURL,
68 const std::string &osAuthToken,
69 const std::string &osBucket,
70 const std::string &osObjectKey);
71 ~VSISwiftHandleHelper();
72
73 bool Authenticate(const std::string &osPathForOption);
74
75 static VSISwiftHandleHelper *BuildFromURI(const char *pszURI,
76 const char *pszFSPrefix);
77
78 struct curl_slist *
79 GetCurlHeaders(const std::string &osVerbosVerb,
80 const struct curl_slist *psExistingHeaders,
81 const void *pabyDataContent = nullptr,
82 size_t nBytesContent = 0) const override;
83
84 const std::string &GetURL() const override
85 {
86 return m_osURL;
87 }
88
89 static void CleanMutex();
90 static void ClearCache();
91};
92
93#endif /* HAVE_CURL */
94
95#endif /* #ifndef DOXYGEN_SKIP */
96
97#endif /* CPL_SWIFT_INCLUDED_H */
The CPLJSONArray class holds JSON object from CPLJSONDocument.
Definition: cpl_json.h:41
Interface for downloading HTTP, FTP documents.
Interface for read and write JSON documents.
Definition: cpl_http.h:52