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 * SPDX-License-Identifier: MIT
10 ****************************************************************************/
11
12#ifndef CPL_GOOGLE_CLOUD_INCLUDED_H
13#define CPL_GOOGLE_CLOUD_INCLUDED_H
14
15#ifndef DOXYGEN_SKIP
16
17#include <cstddef>
18
19#include "cpl_string.h"
20
21#ifdef HAVE_CURL
22
23#include <curl/curl.h>
24#include "cpl_http.h"
25#include "cpl_aws.h"
26#include <map>
27
28class VSIGSHandleHelper final : public IVSIS3LikeHandleHelper
29{
30 CPL_DISALLOW_COPY_ASSIGN(VSIGSHandleHelper)
31
32 std::string m_osURL;
33 std::string m_osEndpoint;
34 std::string m_osBucketObjectKey;
35 std::string m_osSecretAccessKey;
36 std::string m_osAccessKeyId;
37 bool m_bUseAuthenticationHeader;
38 GOA2Manager m_oManager;
39 std::string m_osUserProject{};
40
41 static bool GetConfiguration(const std::string &osPathForOption,
42 CSLConstList papszOptions,
43 std::string &osSecretAccessKey,
44 std::string &osAccessKeyId,
45 bool &bUseAuthenticationHeader,
46 GOA2Manager &oManager);
47
48 static bool GetConfigurationFromConfigFile(
49 std::string &osSecretAccessKey, std::string &osAccessKeyId,
50 std::string &osOAuth2RefreshToken, std::string &osOAuth2ClientId,
51 std::string &osOAuth2ClientSecret, std::string &osCredentials);
52
53 void RebuildURL() override;
54
55 public:
56 VSIGSHandleHelper(const std::string &osEndpoint,
57 const std::string &osBucketObjectKey,
58 const std::string &osSecretAccessKey,
59 const std::string &osAccessKeyId, bool bUseHeaderFile,
60 const GOA2Manager &oManager,
61 const std::string &osUserProject);
62 ~VSIGSHandleHelper() override;
63
64 static VSIGSHandleHelper *
65 BuildFromURI(const char *pszURI, const char *pszFSPrefix,
66 const char *pszURIForPathSpecificOption = nullptr,
67 CSLConstList papszOptions = nullptr);
68
69 bool UsesHMACKey() const;
70
71 struct curl_slist *GetCurlHeaders(const std::string &osVerbosVerb,
72 struct curl_slist *psHeaders,
73 const void *pabyDataContent = nullptr,
74 size_t nBytesContent = 0) const override;
75
76 const std::string &GetURL() const override
77 {
78 return m_osURL;
79 }
80
81 std::string GetCopySourceHeader() const override
82 {
83 return "x-goog-copy-source";
84 }
85
86 const char *GetMetadataDirectiveREPLACE() const override
87 {
88 return "x-goog-metadata-directive: REPLACE";
89 }
90
91 std::string GetSignedURL(CSLConstList papszOptions);
92
93 static void ClearCache();
94};
95
96#endif /* HAVE_CURL */
97
98#endif /* #ifndef DOXYGEN_SKIP */
99
100#endif /* CPL_GOOGLE_CLOUD_INCLUDED_H */
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:936
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087
Various convenience functions for working with strings and string lists.