Logo ROOT  
Reference Guide
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)
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 *************************************************************************/
13#ifndef ROOT_TS3WebFile
14#define ROOT_TS3WebFile
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 //
59#include "TWebFile.h"
61#include "TUrl.h"
63#include "TString.h"
65#include "TS3HTTPRequest.h"
68class TS3WebFile: public TWebFile {
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);
77 // Super-class methods extended by this class
78 virtual Int_t GetHead();
79 virtual void SetMsgReadBuffer10(const char* redirectLocation = 0, Bool_t tempRedirect = kFALSE);
80 virtual void ProcessHttpHeader(const TString& headerLine);
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); }
86 // Data members
87 TS3HTTPRequest fS3Request; // S3 HTTP request
88 Bool_t fUseMultiRange; // Is the S3 server capable of serving multirange requests?
91 // Constructors & Destructor
92 TS3WebFile(const char* url, Option_t* options="");
93 virtual ~TS3WebFile() {}
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; }
102 // Modifiers
103 virtual Bool_t ReadBuffers(char* buf, Long64_t* pos, Int_t* len, Int_t nbuf);
105 ClassDef(TS3WebFile, 0) // Read a ROOT file from a S3 server
108#endif // ROOT_TS3WebFile
int Int_t
Definition: CPyCppyy.h:43
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
const char Option_t
Definition: RtypesCore.h:66
#define ClassDef(name, id)
Definition: Rtypes.h:325
TUrl fUrl
!URL of file
Definition: TFile.h:111
const TString & GetSecretKey() const
TS3HTTPRequest & SetSecretKey(const TString &secretKey)
const TString & GetAccessKey() const
TS3HTTPRequest & SetAccessKey(const TString &accessKey)
const TString & GetObjectKey() const
const TString & GetBucket() const
TS3HTTPRequest fS3Request
Definition: TS3WebFile.h:87
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.
Definition: TS3WebFile.cxx:245
const TString & GetSecretKey() const
Definition: TS3WebFile.h:97
virtual Int_t GetHead()
Overwrites TWebFile::GetHead() for retrieving the HTTP headers of this file.
Definition: TS3WebFile.cxx:277
const TString & GetAccessKey() const
Definition: TS3WebFile.h:96
const TUrl & GetUrl() const
Definition: TS3WebFile.h:100
const TString & GetObjectKey() const
Definition: TS3WebFile.h:99
virtual void ProcessHttpHeader(const TString &headerLine)
This method is called by the super-class TWebFile when a HTTP header for this file is retrieved.
Definition: TS3WebFile.cxx:336
const TString & GetBucket() const
Definition: TS3WebFile.h:98
virtual void SetMsgReadBuffer10(const char *redirectLocation=0, Bool_t tempRedirect=kFALSE)
Overwrites TWebFile::SetMsgReadBuffer10() for setting the HTTP GET request compliant to the authentic...
Definition: TS3WebFile.cxx:291
Bool_t fUseMultiRange
Definition: TS3WebFile.h:88
virtual ~TS3WebFile()
Definition: TS3WebFile.h:93
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.
Definition: TS3WebFile.cxx:356
void SetSecretKey(const TString &secretKey)
Definition: TS3WebFile.h:84
void SetAccessKey(const TString &accessKey)
Definition: TS3WebFile.h:83
virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read specified byte ranges from remote file via HTTP daemon.
Definition: TS3WebFile.cxx:301
Basic string class.
Definition: TString.h:136
This class represents a WWW compatible URL.
Definition: TUrl.h:33
long long Long64_t
Definition: cpp_cppyy.h:13