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
24class 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();
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 *
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 std::string GetSignedURL(CSLConstList papszOptions);
90
91 static void ClearCache();
92
93 std::string GetSASQueryString() const;
94
95 const std::string &GetStorageAccount() const
96 {
97 return m_osStorageAccount;
98 }
99
100 const std::string &GetBucket() const
101 {
102 return m_osBucket;
103 }
104};
105
106namespace cpl
107{
108int GetAzureAppendBufferSize();
109}
110
111#endif /* HAVE_CURL */
112
113#endif /* #ifndef DOXYGEN_SKIP */
114
115#endif /* CPL_AZURE_INCLUDED_H */
Interface for downloading HTTP, FTP documents.
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1179