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();
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 *
72 GetCurlHeaders(const std::string &osVerbosVerb,
73 const struct curl_slist *psExistingHeaders,
74 const void *pabyDataContent = nullptr,
75 size_t nBytesContent = 0) const override;
76
77 const std::string &GetURL() const override
78 {
79 return m_osURL;
80 }
81
82 std::string GetCopySourceHeader() const override
83 {
84 return "x-goog-copy-source";
85 }
86
87 const char *GetMetadataDirectiveREPLACE() const override
88 {
89 return "x-goog-metadata-directive: REPLACE";
90 }
91
92 std::string GetSignedURL(CSLConstList papszOptions);
93
94 static void ClearCache();
95};
96
97#endif /* HAVE_CURL */
98
99#endif /* #ifndef DOXYGEN_SKIP */
100
101#endif /* CPL_GOOGLE_CLOUD_INCLUDED_H */
Manager of Google OAuth2 authentication.
Definition: cpl_http.h:220
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:1030
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1179
Various convenience functions for working with strings and string lists.