GDAL
cpl_google_cloud.h
1 /**********************************************************************
2  * Project: CPL - Common Portability Library
3  * Purpose: Google Cloud Storage 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_GOOGLE_CLOUD_INCLUDED_H
29 #define CPL_GOOGLE_CLOUD_INCLUDED_H
30 
31 #ifndef DOXYGEN_SKIP
32 
33 #include <cstddef>
34 
35 #include "cpl_string.h"
36 
37 #ifdef HAVE_CURL
38 
39 #include <curl/curl.h>
40 #include "cpl_http.h"
41 #include "cpl_aws.h"
42 #include <map>
43 
44 class VSIGSHandleHelper final: public IVSIS3LikeHandleHelper
45 {
46  CPL_DISALLOW_COPY_ASSIGN(VSIGSHandleHelper)
47 
48  CPLString m_osURL;
49  CPLString m_osEndpoint;
50  CPLString m_osBucketObjectKey;
51  CPLString m_osSecretAccessKey;
52  CPLString m_osAccessKeyId;
53  bool m_bUseHeaderFile;
54  GOA2Manager m_oManager;
55  std::string m_osUserProject{};
56 
57  static bool GetConfiguration(CSLConstList papszOptions,
58  CPLString& osSecretAccessKey,
59  CPLString& osAccessKeyId,
60  CPLString& osHeaderFile,
61  GOA2Manager& oManager);
62 
63  static bool GetConfigurationFromConfigFile(
64  CPLString& osSecretAccessKey,
65  CPLString& osAccessKeyId,
66  CPLString& osOAuth2RefreshToken,
67  CPLString& osOAuth2ClientId,
68  CPLString& osOAuth2ClientSecret,
69  CPLString& osCredentials);
70 
71  void RebuildURL() override;
72 
73  public:
74  VSIGSHandleHelper(const CPLString& osEndpoint,
75  const CPLString& osBucketObjectKey,
76  const CPLString& osSecretAccessKey,
77  const CPLString& osAccessKeyId,
78  bool bUseHeaderFile,
79  const GOA2Manager& oManager,
80  const std::string& osUserProject);
81  ~VSIGSHandleHelper();
82 
83  static VSIGSHandleHelper* BuildFromURI(const char* pszURI,
84  const char* pszFSPrefix,
85  CSLConstList papszOptions = nullptr);
86 
87  bool UsesHMACKey() const;
88 
89  struct curl_slist* GetCurlHeaders(
90  const CPLString& osVerbosVerb,
91  const struct curl_slist* psExistingHeaders,
92  const void *pabyDataContent = nullptr,
93  size_t nBytesContent = 0) const override;
94 
95  const CPLString& GetURL() const override { return m_osURL; }
96 
97  CPLString GetCopySourceHeader() const override { return "x-goog-copy-source"; }
98  const char* GetMetadataDirectiveREPLACE() const override { return "x-goog-metadata-directive: REPLACE"; }
99 
100  CPLString GetSignedURL(CSLConstList papszOptions);
101 
102  static void CleanMutex();
103  static void ClearCache();
104 };
105 
106 #endif /* HAVE_CURL */
107 
108 #endif /* #ifndef DOXYGEN_SKIP */
109 
110 #endif /* CPL_GOOGLE_CLOUD_INCLUDED_H */
Convenient string class based on std::string.
Definition: cpl_string.h:333
Manager of Google OAuth2 authentication.
Definition: cpl_http.h:197
Interface for downloading HTTP, FTP documents.
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:955
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1169
Various convenience functions for working with strings and string lists.