GDAL

cpl_azure.h
1/**********************************************************************
2 * Project: CPL - Common Portability Library
3 * Purpose: Microsoft Azure Storage Blob routines
4 * Author: Even Rouault <even.rouault at spatialys.com>
5 *
6 **********************************************************************
7 * Copyright (c) 2017, Even Rouault <even.rouault at spatialys.com>
8 *
9 * SPDX-License-Identifier: MIT
10 ****************************************************************************/
11
12#ifndef CPL_AZURE_INCLUDED_H
13#define CPL_AZURE_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 <map>
23
24 class VSIAzureBlobHandleHelper final : public IVSIS3LikeHandleHelper
25{
26 std::string m_osPathForOption;
27 std::string m_osURL;
28 std::string m_osEndpoint;
29 std::string m_osBucket;
30 std::string m_osObjectKey;
31 std::string m_osStorageAccount;
32 std::string m_osStorageKey;
33 std::string m_osSAS;
34 std::string m_osAccessToken;
35 bool m_bFromManagedIdentities;
36 bool m_bIncludeMSVersion = true;
37
38 enum class Service
39 {
40 SERVICE_BLOB,
41 SERVICE_ADLS,
42 };
43
44 static bool GetConfiguration(const std::string &osPathForOption,
45 CSLConstList papszOptions, Service eService,
46 bool &bUseHTTPS, std::string &osEndpoint,
47 std::string &osStorageAccount,
48 std::string &osStorageKey, std::string &osSAS,
49 std::string &osAccessToken,
50 bool &bFromManagedIdentities);
51
52 static std::string BuildURL(const std::string &osEndpoint,
53 const std::string &osBucket,
54 const std::string &osObjectKey,
55 const std::string &osSAS);
56
57 void RebuildURL() override;
58
59 public:
60 VSIAzureBlobHandleHelper(
61 const std::string &osPathForOption, const std::string &osEndpoint,
62 const std::string &osBucket, const std::string &osObjectKey,
63 const std::string &osStorageAccount, const std::string &osStorageKey,
64 const std::string &osSAS, const std::string &osAccessToken,
65 bool bFromManagedIdentities);
66 ~VSIAzureBlobHandleHelper() override;
67
68 static VSIAzureBlobHandleHelper *
69 BuildFromURI(const char *pszURI, const char *pszFSPrefix,
70 const char *pszURIForPathSpecificOption = nullptr,
71 CSLConstList papszOptions = nullptr);
72
73 void SetIncludeMSVersion(bool bInclude)
74 {
75 m_bIncludeMSVersion = bInclude;
76 }
77
78 struct curl_slist *GetCurlHeaders(const std::string &osVerbosVerb,
79 struct curl_slist *psHeaders,
80 const void *pabyDataContent = nullptr,
81 size_t nBytesContent = 0) const override;
82
83 bool CanRestartOnError(const char *, const char *pszHeaders,
84 bool bSetError) override;
85
86 const std::string &GetURL() const override
87 {
88 return m_osURL;
89 }
90
91 std::string GetSignedURL(CSLConstList papszOptions);
92
93 static void ClearCache();
94
95 std::string GetSASQueryString() const;
96
97 const std::string &GetStorageAccount() const
98 {
99 return m_osStorageAccount;
100 }
101
102 const std::string &GetBucket() const
103 {
104 return m_osBucket;
105 }
106
107 static std::string GetSAS(const char *pszFilename);
108
109 static bool IsNoSignRequest(const char *pszFilename);
110};
111
112 namespace cpl
113{
114 int GetAzureAppendBufferSize();
115}
116
117#endif /* HAVE_CURL */
118
119#endif /* #ifndef DOXYGEN_SKIP */
120
121#endif /* CPL_AZURE_INCLUDED_H */
cpl_http.h
Interface for downloading HTTP, FTP documents.
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087