Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TS3WebFile.h
Go to the documentation of this file.
1// @(#)root/net:$Id: TS3WebFile.h$
2// Author: Fabio Hernandez 22/01/2013
3// extending an initial version by Marcelo Sousa (class TAS3File)
4
5/*************************************************************************
6 * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT_TS3WebFile
14#define ROOT_TS3WebFile
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TS3WebFile //
19// //
20// A TS3WebFile is a TWebFile which retrieves the file contents from a //
21// web server implementing the REST API of the Amazon S3 protocol. This //
22// class is meant to be as generic as possible to be used with files //
23// hosted not only by Amazon S3 servers but also by other providers //
24// implementing the core of the S3 protocol. //
25// //
26// The S3 protocol works on top of HTTPS (and HTTP) and imposes that //
27// each HTTP request be signed using a specific convention: the request //
28// must include an 'Authorization' header which contains the signature //
29// of a concatenation of selected request fields. For signing the //
30// request, an 'Access Key Id' and a 'Secret Access Key' need to be //
31// known. These keys are used by the S3 servers to identify the client //
32// and to authenticate the request as genuine. //
33// //
34// As an end user, you must know the Access Key and Secret Access Key //
35// in order to access each S3 file. They are provided to you by your S3 //
36// service provider. Those two keys can be provided to ROOT when //
37// initializing an object of this class by two means: //
38// a) by using the environmental variables S3_ACCESS_KEY and //
39// S3_SECRET_KEY, or //
40// b) by specifying them as an argument when opening each file. //
41// //
42// The first method is convenient if all the S3 files you want to //
43// access are hosted by a single provider. The second one is more //
44// flexible as it allows you to specify which credentials to use //
45// on a per-file basis. See the documentation of the constructor of //
46// this class for details on the syntax. //
47// //
48// For generating and signing the HTTP request, this class uses //
49// TS3HTTPRequest. //
50// //
51// For more information on the details of S3 protocol please refer to: //
52// "Amazon Simple Storage Service Developer Guide": //
53// http://docs.amazonwebservices.com/AmazonS3/latest/dev/Welcome.html //
54// //
55// "Amazon Simple Storage Service REST API Reference" //
56// http://docs.amazonwebservices.com/AmazonS3/latest/API/APIRest.html //
57//////////////////////////////////////////////////////////////////////////
58
59#include "TWebFile.h"
60
61#include "TUrl.h"
62
63#include "TString.h"
64
65#include "TS3HTTPRequest.h"
66
67
68class TS3WebFile: public TWebFile {
69
70private:
72 Bool_t ParseOptions(Option_t* options, TString& accessKey, TString& secretKey, TString& token);
73 Bool_t GetCredentialsFromEnv(const char* accessKeyEnv, const char* secretKeyEnv, const char* tokenEnv,
74 TString& outAccessKey, TString& outSecretKey, TString& outToken);
75
76protected:
77 // Super-class methods extended by this class
78 Int_t GetHead() override;
79 void SetMsgReadBuffer10(const char* redirectLocation = nullptr, Bool_t tempRedirect = kFALSE) override;
80 void ProcessHttpHeader(const TString& headerLine) override;
81
82 // Modifiers of data members (to be used mainly by subclasses)
83 void SetAccessKey(const TString& accessKey) { fS3Request.SetAccessKey(accessKey); }
84 void SetSecretKey(const TString& secretKey) { fS3Request.SetSecretKey(secretKey); }
85
86 // Data members
87 TS3HTTPRequest fS3Request; // S3 HTTP request
88 Bool_t fUseMultiRange; // Is the S3 server capable of serving multirange requests?
89
90public:
91 // Constructors & Destructor
92 TS3WebFile(const char* url, Option_t* options="");
93 virtual ~TS3WebFile() {}
94
95 // Selectors
96 const TString& GetAccessKey() const { return fS3Request.GetAccessKey(); }
97 const TString& GetSecretKey() const { return fS3Request.GetSecretKey(); }
98 const TString& GetBucket() const { return fS3Request.GetBucket(); }
99 const TString& GetObjectKey() const { return fS3Request.GetObjectKey(); }
100 const TUrl& GetUrl() const { return fUrl; }
101
102 // Modifiers
103 Bool_t ReadBuffers(char* buf, Long64_t* pos, Int_t* len, Int_t nbuf) override;
104
105 ClassDefOverride(TS3WebFile, 0) // Read a ROOT file from a S3 server
106};
107
108#endif // ROOT_TS3WebFile
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
long long Long64_t
Definition RtypesCore.h:80
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
TUrl fUrl
!URL of file
Definition TFile.h:110
const TString & GetObjectKey() const
const TString & GetSecretKey() const
const TString & GetBucket() const
TS3HTTPRequest & SetSecretKey(const TString &secretKey)
const TString & GetAccessKey() const
TS3HTTPRequest & SetAccessKey(const TString &accessKey)
A TS3WebFile is a TWebFile which retrieves the file contents from a web server implementing the REST ...
Definition TS3WebFile.h:68
TS3HTTPRequest fS3Request
Definition TS3WebFile.h:87
Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override
Read the nbuf blocks described in arrays pos and len.
const TString & GetBucket() const
Definition TS3WebFile.h:98
Bool_t ParseOptions(Option_t *options, TString &accessKey, TString &secretKey, TString &token)
Extracts the S3 authentication key pair (access key and secret key) from the options.
void SetMsgReadBuffer10(const char *redirectLocation=nullptr, Bool_t tempRedirect=kFALSE) override
Overwrites TWebFile::SetMsgReadBuffer10() for setting the HTTP GET request compliant to the authentic...
const TString & GetSecretKey() const
Definition TS3WebFile.h:97
Int_t GetHead() override
Overwrites TWebFile::GetHead() for retrieving the HTTP headers of this file.
const TUrl & GetUrl() const
Definition TS3WebFile.h:100
Bool_t fUseMultiRange
Definition TS3WebFile.h:88
const TString & GetObjectKey() const
Definition TS3WebFile.h:99
virtual ~TS3WebFile()
Definition TS3WebFile.h:93
void ProcessHttpHeader(const TString &headerLine) override
This method is called by the super-class TWebFile when a HTTP header for this file is retrieved.
Bool_t GetCredentialsFromEnv(const char *accessKeyEnv, const char *secretKeyEnv, const char *tokenEnv, TString &outAccessKey, TString &outSecretKey, TString &outToken)
Sets the access and secret keys from the environmental variables, if they are both set.
void SetSecretKey(const TString &secretKey)
Definition TS3WebFile.h:84
void SetAccessKey(const TString &accessKey)
Definition TS3WebFile.h:83
const TString & GetAccessKey() const
Definition TS3WebFile.h:96
Basic string class.
Definition TString.h:139
This class represents a WWW compatible URL.
Definition TUrl.h:33