LCOV - code coverage report
Current view: top level - port - cpl_azure.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 9 9 100.0 %
Date: 2024-04-28 18:08:58 Functions: 4 4 100.0 %

          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             :  * 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             :     std::string m_osPathForOption;
      43             :     std::string m_osURL;
      44             :     std::string m_osEndpoint;
      45             :     std::string m_osBucket;
      46             :     std::string m_osObjectKey;
      47             :     std::string m_osStorageAccount;
      48             :     std::string m_osStorageKey;
      49             :     std::string m_osSAS;
      50             :     std::string m_osAccessToken;
      51             :     bool m_bFromManagedIdentities;
      52             :     bool m_bIncludeMSVersion = true;
      53             : 
      54             :     enum class Service
      55             :     {
      56             :         SERVICE_BLOB,
      57             :         SERVICE_ADLS,
      58             :     };
      59             : 
      60             :     static bool GetConfiguration(const std::string &osPathForOption,
      61             :                                  CSLConstList papszOptions, Service eService,
      62             :                                  bool &bUseHTTPS, std::string &osEndpoint,
      63             :                                  std::string &osStorageAccount,
      64             :                                  std::string &osStorageKey, std::string &osSAS,
      65             :                                  std::string &osAccessToken,
      66             :                                  bool &bFromManagedIdentities);
      67             : 
      68             :     static std::string BuildURL(const std::string &osEndpoint,
      69             :                                 const std::string &osBucket,
      70             :                                 const std::string &osObjectKey,
      71             :                                 const std::string &osSAS);
      72             : 
      73             :     void RebuildURL() override;
      74             : 
      75             :   public:
      76             :     VSIAzureBlobHandleHelper(
      77             :         const std::string &osPathForOption, const std::string &osEndpoint,
      78             :         const std::string &osBucket, const std::string &osObjectKey,
      79             :         const std::string &osStorageAccount, const std::string &osStorageKey,
      80             :         const std::string &osSAS, const std::string &osAccessToken,
      81             :         bool bFromManagedIdentities);
      82             :     ~VSIAzureBlobHandleHelper();
      83             : 
      84             :     static VSIAzureBlobHandleHelper *
      85             :     BuildFromURI(const char *pszURI, const char *pszFSPrefix,
      86             :                  CSLConstList papszOptions = nullptr);
      87             : 
      88           7 :     void SetIncludeMSVersion(bool bInclude)
      89             :     {
      90           7 :         m_bIncludeMSVersion = bInclude;
      91           7 :     }
      92             : 
      93             :     struct curl_slist *
      94             :     GetCurlHeaders(const std::string &osVerbosVerb,
      95             :                    const struct curl_slist *psExistingHeaders,
      96             :                    const void *pabyDataContent = nullptr,
      97             :                    size_t nBytesContent = 0) const override;
      98             : 
      99         568 :     const std::string &GetURL() const override
     100             :     {
     101         568 :         return m_osURL;
     102             :     }
     103             : 
     104             :     std::string GetSignedURL(CSLConstList papszOptions);
     105             : 
     106             :     static void ClearCache();
     107             : 
     108             :     std::string GetSASQueryString() const;
     109             : 
     110           6 :     const std::string &GetStorageAccount() const
     111             :     {
     112           6 :         return m_osStorageAccount;
     113             :     }
     114             : 
     115           6 :     const std::string &GetBucket() const
     116             :     {
     117           6 :         return m_osBucket;
     118             :     }
     119             : };
     120             : 
     121             : namespace cpl
     122             : {
     123             : int GetAzureBufferSize();
     124             : }
     125             : 
     126             : #endif /* HAVE_CURL */
     127             : 
     128             : #endif /* #ifndef DOXYGEN_SKIP */
     129             : 
     130             : #endif /* CPL_AZURE_INCLUDED_H */

Generated by: LCOV version 1.14