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
40class 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 CPLString m_osAccessToken;
50 bool m_bFromManagedIdentities;
51
52 enum class Service
53 {
54 SERVICE_BLOB,
55 SERVICE_ADLS,
56 };
57
58 static bool GetConfiguration(const std::string &osPathForOption,
59 CSLConstList papszOptions, Service eService,
60 bool &bUseHTTPS, CPLString &osEndpoint,
61 CPLString &osStorageAccount,
62 CPLString &osStorageKey, CPLString &osSAS,
63 CPLString &osAccessToken,
64 bool &bFromManagedIdentities);
65
66 static CPLString BuildURL(const CPLString &osEndpoint,
67 const CPLString &osBucket,
68 const CPLString &osObjectKey,
69 const CPLString &osSAS);
70
71 void RebuildURL() override;
72
73 public:
74 VSIAzureBlobHandleHelper(
75 const CPLString &osEndpoint, const CPLString &osBucket,
76 const CPLString &osObjectKey, const CPLString &osStorageAccount,
77 const CPLString &osStorageKey, const CPLString &osSAS,
78 const CPLString &osAccessToken, bool bFromManagedIdentities);
79 ~VSIAzureBlobHandleHelper();
80
81 static VSIAzureBlobHandleHelper *
82 BuildFromURI(const char *pszURI, const char *pszFSPrefix,
83 CSLConstList papszOptions = nullptr);
84
85 struct curl_slist *
86 GetCurlHeaders(const CPLString &osVerbosVerb,
87 const struct curl_slist *psExistingHeaders,
88 const void *pabyDataContent = nullptr,
89 size_t nBytesContent = 0) const override;
90
91 const CPLString &GetURL() const override
92 {
93 return m_osURL;
94 }
95
96 CPLString GetSignedURL(CSLConstList papszOptions);
97
98 static void ClearCache();
99
100 std::string GetSASQueryString() const;
101};
102
103namespace cpl
104{
105int GetAzureBufferSize();
106}
107
108#endif /* HAVE_CURL */
109
110#endif /* #ifndef DOXYGEN_SKIP */
111
112#endif /* CPL_AZURE_INCLUDED_H */
Convenient string class based on std::string.
Definition cpl_string.h:312
Interface for downloading HTTP, FTP documents.
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1190