Logo ROOT  
Reference Guide
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 
68 class TS3WebFile: public TWebFile {
69 
70 private:
71  TS3WebFile();
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 
76 protected:
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);
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 
90 public:
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  virtual Bool_t ReadBuffers(char* buf, Long64_t* pos, Int_t* len, Int_t nbuf);
104 
105  ClassDef(TS3WebFile, 0) // Read a ROOT file from a S3 server
106 };
107 
108 #endif // ROOT_TS3WebFile
TS3WebFile::SetSecretKey
void SetSecretKey(const TString &secretKey)
Definition: TS3WebFile.h:90
TS3HTTPRequest
Definition: TS3HTTPRequest.h:45
TS3WebFile::fUseMultiRange
Bool_t fUseMultiRange
Definition: TS3WebFile.h:94
TS3HTTPRequest::GetSecretKey
const TString & GetSecretKey() const
Definition: TS3HTTPRequest.h:97
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TS3WebFile
Definition: TS3WebFile.h:68
TS3WebFile::SetMsgReadBuffer10
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
TS3HTTPRequest::GetObjectKey
const TString & GetObjectKey() const
Definition: TS3HTTPRequest.h:94
TS3HTTPRequest::SetSecretKey
TS3HTTPRequest & SetSecretKey(const TString &secretKey)
Definition: TS3HTTPRequest.h:151
TString
Definition: TString.h:136
TS3WebFile::GetBucket
const TString & GetBucket() const
Definition: TS3WebFile.h:104
TS3WebFile::ProcessHttpHeader
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
TString.h
bool
TS3WebFile::GetHead
virtual Int_t GetHead()
Overwrites TWebFile::GetHead() for retrieving the HTTP headers of this file.
Definition: TS3WebFile.cxx:277
TFile::fUrl
TUrl fUrl
!URL of file
Definition: TFile.h:111
TS3WebFile::ReadBuffers
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
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TS3WebFile::GetAccessKey
const TString & GetAccessKey() const
Definition: TS3WebFile.h:102
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TWebFile.h
TUrl
Definition: TUrl.h:33
TS3WebFile::ParseOptions
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
TS3WebFile::GetUrl
const TUrl & GetUrl() const
Definition: TS3WebFile.h:106
TS3WebFile::fS3Request
TS3HTTPRequest fS3Request
Definition: TS3WebFile.h:93
TS3WebFile::~TS3WebFile
virtual ~TS3WebFile()
Definition: TS3WebFile.h:99
TS3HTTPRequest::GetAccessKey
const TString & GetAccessKey() const
Definition: TS3HTTPRequest.h:96
TS3HTTPRequest::SetAccessKey
TS3HTTPRequest & SetAccessKey(const TString &accessKey)
Definition: TS3HTTPRequest.h:145
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TS3WebFile::GetSecretKey
const TString & GetSecretKey() const
Definition: TS3WebFile.h:103
TS3WebFile::GetCredentialsFromEnv
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
TS3WebFile::GetObjectKey
const TString & GetObjectKey() const
Definition: TS3WebFile.h:105
TWebFile
Definition: TWebFile.h:33
TS3WebFile::SetAccessKey
void SetAccessKey(const TString &accessKey)
Definition: TS3WebFile.h:89
TS3WebFile::TS3WebFile
TS3WebFile()
TS3HTTPRequest.h
TUrl.h
TS3HTTPRequest::GetBucket
const TString & GetBucket() const
Definition: TS3HTTPRequest.h:93
int