Logo ROOT   6.08/07
Reference Guide
TS3HTTPRequest.h
Go to the documentation of this file.
1 // @(#)root/net:$Id$
2 // Author: Fabio Hernandez 30/01/2013
3 // based on an initial version by Marcelo Sousa (class THTTPMessage)
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_TS3HTTPRequest
14 #define ROOT_TS3HTTPRequest
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TS3HTTPRequest //
19 // //
20 // An object of this class represents an HTTP request extended to be //
21 // compatible with Amazon's S3 protocol. //
22 // Specifically, such a request contains an 'Authorization' header with //
23 // information used by the S3 server for authenticating this request. //
24 // The authentication information is computed based on a pair of access //
25 // key and secret key which are both provided to the user by the S3 //
26 // service provider (e.g. Amazon, Google, etc.). //
27 // The secret key is used to compute a signature of selected fields in //
28 // the request. The algorithm for computing the signature is documented //
29 // in: //
30 // //
31 // Google storage: //
32 // http://code.google.com/apis/storage/docs/reference/v1/developer-guidev1.html#authentication
33 // //
34 // Amazon: //
35 // http://docs.aws.amazon.com/AmazonS3/latest/dev/S3_Authentication2.html
36 // //
37 //////////////////////////////////////////////////////////////////////////
38 
39 #ifndef ROOT_TObject
40 #include "TObject.h"
41 #endif
42 
43 #ifndef ROOT_TString
44 #include "TString.h"
45 #endif
46 
47 
48 
49 class TS3HTTPRequest : public TObject {
50 
51 public:
52 
55 
56 private:
57  EHTTPVerb fVerb; // HTTP Verb
58  EAuthType fAuthType; // Authentication type
59  TString fHost; // Host name
60  TString fBucket; // Bucket name
61  TString fObjectKey; // Object key
62  TString fTimeStamp; // Request time stamp
63  TString fAccessKey; // Access key (for authentication)
64  TString fSecretKey; // Secret key (for authentication)
65  TString fSessionToken; // Session token (for authentication)
66 
67 
68 protected:
69  TString HTTPVerbToTString(EHTTPVerb httpVerb) const;
73  TString MakeAuthPrefix() const;
74  TString MakeHostHeader() const;
75  TString MakeDateHeader() const;
76  TString MakeTokenHeader() const;
78 
79 public:
80 
82  TS3HTTPRequest(EHTTPVerb httpVerb, const TString& host,
83  const TString& bucket, const TString& objectKey,
84  EAuthType authType, const TString& accessKey,
85  const TString& secretKey);
87  virtual ~TS3HTTPRequest() { }
88 
89  EHTTPVerb GetHTTPVerb() const { return fVerb; }
90  const TString& GetHost() const { return fHost; }
91  const TString& GetBucket() const { return fBucket; }
92  const TString& GetObjectKey() const { return fObjectKey; }
93  const TString& GetTimeStamp() const { return fTimeStamp; }
94  const TString& GetAccessKey() const { return fAccessKey; }
95  const TString& GetSecretKey() const { return fSecretKey; }
96  TString GetAuthType() const { return fAuthType; }
98 
99  TS3HTTPRequest& SetHost(const TString& host);
100  TS3HTTPRequest& SetBucket(const TString& bucket);
101  TS3HTTPRequest& SetObjectKey(const TString& objectKey);
102  TS3HTTPRequest& SetAccessKey(const TString& accessKey);
103  TS3HTTPRequest& SetSecretKey(const TString& secretKey);
104  TS3HTTPRequest& SetAuthKeys(const TString& accessKey, const TString& secretKey);
106  TS3HTTPRequest& SetSessionToken(const TString& token);
107 
108  ClassDef(TS3HTTPRequest, 0) // Create generic HTTP request for Amazon S3 and Google Storage services
109 };
110 
111 
112 //////////////////////////////////////////////////////////////////////////
113 // //
114 // Inlines //
115 // //
116 //////////////////////////////////////////////////////////////////////////
117 
119 {
120  fHost = host;
121  return *this;
122 }
123 
125 {
126  fBucket = bucket;
127  return *this;
128 }
129 
131 {
132  fObjectKey = objectKey;
133  return *this;
134 }
135 
136 inline TS3HTTPRequest& TS3HTTPRequest::SetAuthKeys(const TString& accessKey, const TString& secretKey)
137 {
138  fAccessKey = accessKey;
139  fSecretKey = secretKey;
140  return *this;
141 }
142 
144 {
145  fAuthType = authType;
146  return *this;
147 }
148 
150 {
151  fAccessKey = accessKey;
152  return *this;
153 }
154 
156 {
157  fSecretKey = secretKey;
158  return *this;
159 }
160 
162 {
163  fSessionToken = token;
164  return *this;
165 }
166 
167 #endif
TS3HTTPRequest & SetTimeStamp()
Sets this request's time stamp according to: http://code.google.com/apis/storage/docs/reference-heade...
const TString & GetTimeStamp() const
TString fTimeStamp
virtual ~TS3HTTPRequest()
TString MakeTokenHeader() const
Returns the session security token header for this HTTP request.
const TString & GetHost() const
const TString & GetSecretKey() const
TS3HTTPRequest & SetObjectKey(const TString &objectKey)
TString HTTPVerbToTString(EHTTPVerb httpVerb) const
TString MakeAuthPrefix() const
Returns the authentication prefix.
TS3HTTPRequest & SetSecretKey(const TString &secretKey)
Basic string class.
Definition: TString.h:137
bool Bool_t
Definition: RtypesCore.h:59
EAuthType fAuthType
const TString & GetObjectKey() const
TString fObjectKey
TS3HTTPRequest & SetHost(const TString &host)
#define ClassDef(name, id)
Definition: Rtypes.h:254
TString fSecretKey
TString ComputeSignature(TS3HTTPRequest::EHTTPVerb httpVerb) const
Returns this request's signature.
EHTTPVerb GetHTTPVerb() const
TString fAccessKey
TString GetRequest(TS3HTTPRequest::EHTTPVerb httpVerb, Bool_t appendCRLF=kTRUE)
Returns the HTTP request ready to be sent to the server.
TString fSessionToken
TMarker * m
Definition: textangle.C:8
TString GetAuthType() const
TS3HTTPRequest & SetAccessKey(const TString &accessKey)
TString MakeDateHeader() const
Returns the date header for this HTTP request.
TS3HTTPRequest & SetAuthType(TS3HTTPRequest::EAuthType authType)
Mother of all ROOT objects.
Definition: TObject.h:37
TS3HTTPRequest & SetAuthKeys(const TString &accessKey, const TString &secretKey)
const TString & GetAccessKey() const
TString MakeRequestLine(TS3HTTPRequest::EHTTPVerb httpVerb) const
Returns the first line of a HTTP request for this object.
TS3HTTPRequest & SetBucket(const TString &bucket)
TS3HTTPRequest & SetSessionToken(const TString &token)
const Bool_t kTRUE
Definition: Rtypes.h:91
TString MakeAuthHeader(TS3HTTPRequest::EHTTPVerb httpVerb) const
Returns the authentication header for this HTTP request.
TString MakeHostHeader() const
Returns the 'Host' header to include in the HTTP request.
const TString & GetBucket() const
EHTTPVerb fVerb