Logo ROOT   6.08/07
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 #ifndef ROOT_TWebFile
60 #include "TWebFile.h"
61 #endif
62 
63 #ifndef ROOT_TUrl
64 #include "TUrl.h"
65 #endif
66 
67 #ifndef ROOT_TString
68 #include "TString.h"
69 #endif
70 
71 #ifndef ROOT_TS3HTTPRequest
72 #include "TS3HTTPRequest.h"
73 #endif
74 
75 
76 class TS3WebFile: public TWebFile {
77 
78 private:
79  TS3WebFile();
80  Bool_t ParseOptions(Option_t* options, TString& accessKey, TString& secretKey, TString& token);
81  Bool_t GetCredentialsFromEnv(const char* accessKeyEnv, const char* secretKeyEnv, const char* tokenEnv,
82  TString& outAccessKey, TString& outSecretKey, TString& outToken);
83 
84 protected:
85  // Super-class methods extended by this class
86  virtual Int_t GetHead();
87  virtual void SetMsgReadBuffer10(const char* redirectLocation = 0, Bool_t tempRedirect = kFALSE);
88  virtual void ProcessHttpHeader(const TString& headerLine);
89 
90  // Modifiers of data members (to be used mainly by subclasses)
91  void SetAccessKey(const TString& accessKey) { fS3Request.SetAccessKey(accessKey); }
92  void SetSecretKey(const TString& secretKey) { fS3Request.SetSecretKey(secretKey); }
93 
94  // Data members
95  TS3HTTPRequest fS3Request; // S3 HTTP request
96  Bool_t fUseMultiRange; // Is the S3 server capable of serving multirange requests?
97 
98 public:
99  // Constructors & Destructor
100  TS3WebFile(const char* url, Option_t* options="");
101  virtual ~TS3WebFile() {}
102 
103  // Selectors
104  const TString& GetAccessKey() const { return fS3Request.GetAccessKey(); }
105  const TString& GetSecretKey() const { return fS3Request.GetSecretKey(); }
106  const TString& GetBucket() const { return fS3Request.GetBucket(); }
107  const TString& GetObjectKey() const { return fS3Request.GetObjectKey(); }
108  const TUrl& GetUrl() const { return fUrl; }
109 
110  // Modifiers
111  virtual Bool_t ReadBuffers(char* buf, Long64_t* pos, Int_t* len, Int_t nbuf);
112 
113  ClassDef(TS3WebFile, 0) // Read a ROOT file from a S3 server
114 };
115 
116 #endif // ROOT_TS3WebFile
virtual Int_t GetHead()
Overwrites TWebFile::GetHead() for retrieving the HTTP headers of this file.
Definition: TS3WebFile.cxx:277
TS3HTTPRequest fS3Request
Definition: TS3WebFile.h:95
long long Long64_t
Definition: RtypesCore.h:69
const char Option_t
Definition: RtypesCore.h:62
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 TUrl & GetUrl() const
Definition: TS3WebFile.h:108
This class represents a WWW compatible URL.
Definition: TUrl.h:41
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
virtual ~TS3WebFile()
Definition: TS3WebFile.h:101
const TString & GetSecretKey() const
TS3HTTPRequest & SetSecretKey(const TString &secretKey)
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
const TString & GetObjectKey() const
Definition: TS3WebFile.h:107
const TString & GetObjectKey() const
TUrl fUrl
!URL of file
Definition: TFile.h:102
#define ClassDef(name, id)
Definition: Rtypes.h:254
void SetAccessKey(const TString &accessKey)
Definition: TS3WebFile.h:91
void SetSecretKey(const TString &secretKey)
Definition: TS3WebFile.h:92
const TString & GetSecretKey() const
Definition: TS3WebFile.h:105
Bool_t fUseMultiRange
Definition: TS3WebFile.h:96
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 & SetAccessKey(const TString &accessKey)
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 & GetAccessKey() const
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
const TString & GetBucket() const
Definition: TS3WebFile.h:106
const TString & GetBucket() const
const TString & GetAccessKey() const
Definition: TS3WebFile.h:104