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 * 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_AZURE_INCLUDED_H
29 #define CPL_AZURE_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 <map>
39
40 class VSIAzureBlobHandleHelper final: public IVSIS3LikeHandleHelper
41 {
42 CPLString m_osURL;
43 CPLString m_osEndpoint;
44 CPLString m_osBucket;
45 CPLString m_osObjectKey;
46 CPLString m_osStorageAccount;
47 CPLString m_osStorageKey;
48 CPLString m_osSAS;
49 bool m_bUseHTTPS;
50 bool m_bFromManagedIdendities;
51
52 enum class Service
53 {
54 BLOB,
55 ADLS,
56 };
57
58 static bool GetConfiguration(CSLConstList papszOptions,
59 Service eService,
60 bool& bUseHTTPS,
61 CPLString& osEndpoint,
62 CPLString& osStorageAccount,
63 CPLString& osStorageKey,
64 CPLString& osSAS,
65 bool& bFromManagedIdentities);
66
67 static bool GetConfigurationFromManagedIdentities(
68 CPLString& osAccessToken);
69
70 static CPLString BuildURL(const CPLString& osEndpoint,
71 const CPLString& osStorageAccount,
72 const CPLString& osBucket,
73 const CPLString& osObjectKey,
74 const CPLString& osSAS,
75 bool bUseHTTPS);
76
77 void RebuildURL() override;
78
79 public:
80 VSIAzureBlobHandleHelper(const CPLString& osEndpoint,
81 const CPLString& osBucket,
82 const CPLString& osObjectKey,
83 const CPLString& osStorageAccount,
84 const CPLString& osStorageKey,
85 const CPLString& osSAS,
86 bool bUseHTTPS,
87 bool bFromManagedIdentities);
88 ~VSIAzureBlobHandleHelper();
89
90 static VSIAzureBlobHandleHelper* BuildFromURI(const char* pszURI,
91 const char* pszFSPrefix,
92 CSLConstList papszOptions = nullptr);
93
94 struct curl_slist* GetCurlHeaders(const CPLString& osVerbosVerb,
95 const struct curl_slist* psExistingHeaders,
96 const void *pabyDataContent = nullptr,
97 size_t nBytesContent = 0) const override;
98
99 const CPLString& GetURL() const override { return m_osURL; }
100
101 CPLString GetSignedURL(CSLConstList papszOptions);
102
103 static void ClearCache();
104
105 std::string GetSASQueryString() const;
106 };
107
108 namespace cpl
109 {
110 int GetAzureBufferSize();
111 }
112
113 #endif /* HAVE_CURL */
114
115 #endif /* #ifndef DOXYGEN_SKIP */
116
117 #endif /* CPL_AZURE_INCLUDED_H */
CPLString
Convenient string class based on std::string.
Definition: cpl_string.h:333
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:1216