Line data Source code
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(); 67 : 68 : static VSIAzureBlobHandleHelper * 69 : BuildFromURI(const char *pszURI, const char *pszFSPrefix, 70 : const char *pszURIForPathSpecificOption = nullptr, 71 : CSLConstList papszOptions = nullptr); 72 : 73 8 : void SetIncludeMSVersion(bool bInclude) 74 : { 75 8 : m_bIncludeMSVersion = bInclude; 76 8 : } 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 : bool CanRestartOnError(const char *, const char *pszHeaders, 85 : bool bSetError) override; 86 : 87 602 : const std::string &GetURL() const override 88 : { 89 602 : return m_osURL; 90 : } 91 : 92 : std::string GetSignedURL(CSLConstList papszOptions); 93 : 94 : static void ClearCache(); 95 : 96 : std::string GetSASQueryString() const; 97 : 98 6 : const std::string &GetStorageAccount() const 99 : { 100 6 : return m_osStorageAccount; 101 : } 102 : 103 6 : const std::string &GetBucket() const 104 : { 105 6 : return m_osBucket; 106 : } 107 : }; 108 : 109 : namespace cpl 110 : { 111 : int GetAzureAppendBufferSize(); 112 : } 113 : 114 : #endif /* HAVE_CURL */ 115 : 116 : #endif /* #ifndef DOXYGEN_SKIP */ 117 : 118 : #endif /* CPL_AZURE_INCLUDED_H */