Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:24

0001 // @(#)root/net:$Id$
0002 // Author: Fabio Hernandez 30/01/2013
0003 //         based on an initial version by Marcelo Sousa (class THTTPMessage)
0004 
0005 /*************************************************************************
0006  * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers.               *
0007  * All rights reserved.                                                  *
0008  *                                                                       *
0009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0011  *************************************************************************/
0012 
0013 #ifndef ROOT_TS3HTTPRequest
0014 #define ROOT_TS3HTTPRequest
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TS3HTTPRequest                                                       //
0019 //                                                                      //
0020 // An object of this class represents an HTTP request extended to be    //
0021 // compatible with Amazon's S3 protocol.                                //
0022 // Specifically, such a request contains an 'Authorization' header with //
0023 // information used by the S3 server for authenticating this request.   //
0024 // The authentication information is computed based on a pair of access //
0025 // key and secret key which are both provided to the user by the S3     //
0026 // service provider (e.g. Amazon, Google, etc.).                        //
0027 // The secret key is used to compute a signature of selected fields in  //
0028 // the request. The algorithm for computing the signature is documented //
0029 // in:                                                                  //
0030 //                                                                      //
0031 // Google storage:                                                      //
0032 // http://code.google.com/apis/storage/docs/reference/v1/developer-guidev1.html#authentication
0033 //                                                                      //
0034 // Amazon:                                                              //
0035 // http://docs.aws.amazon.com/AmazonS3/latest/dev/S3_Authentication2.html
0036 //                                                                      //
0037 //////////////////////////////////////////////////////////////////////////
0038 
0039 #include "TObject.h"
0040 
0041 #include "TString.h"
0042 
0043 
0044 
0045 class TS3HTTPRequest : public TObject {
0046 
0047 public:
0048 
0049    enum EHTTPVerb { kGET, kPOST, kPUT, kDELETE, kHEAD, kCOPY };
0050    enum EAuthType { kNoAuth, kAmazon, kGoogle };
0051 
0052 private:
0053    EHTTPVerb fVerb;        // HTTP Verb
0054    EAuthType fAuthType;    // Authentication type
0055    TString   fHost;        // Host name
0056    TString   fBucket;      // Bucket name
0057    TString   fObjectKey;   // Object key
0058    TString   fTimeStamp;   // Request time stamp
0059    TString   fAccessKey;   // Access key (for authentication)
0060    TString   fSecretKey;   // Secret key (for authentication)
0061    TString   fSessionToken; // Session token (for authentication)
0062 
0063 
0064 protected:
0065    TString HTTPVerbToTString(EHTTPVerb httpVerb) const;
0066    TString MakeRequestLine(TS3HTTPRequest::EHTTPVerb httpVerb) const;
0067    TString MakeAuthHeader(TS3HTTPRequest::EHTTPVerb httpVerb) const;
0068    TString ComputeSignature(TS3HTTPRequest::EHTTPVerb httpVerb) const;
0069    TString MakeAuthPrefix() const;
0070    TString MakeHostHeader() const;
0071    TString MakeDateHeader() const;
0072    TString MakeTokenHeader() const;
0073    TS3HTTPRequest& SetTimeStamp();
0074 
0075 public:
0076 
0077    TS3HTTPRequest();
0078    TS3HTTPRequest(EHTTPVerb httpVerb, const TString& host,
0079                 const TString& bucket, const TString& objectKey,
0080                 EAuthType authType, const TString& accessKey,
0081                 const TString& secretKey);
0082    TS3HTTPRequest(const TS3HTTPRequest& m);
0083    virtual ~TS3HTTPRequest() {}
0084 
0085    EHTTPVerb       GetHTTPVerb() const { return fVerb; }
0086    const TString&  GetHost() const { return fHost; }
0087    const TString&  GetBucket() const { return fBucket; }
0088    const TString&  GetObjectKey() const { return fObjectKey; }
0089    const TString&  GetTimeStamp() const { return fTimeStamp; }
0090    const TString&  GetAccessKey() const { return fAccessKey; }
0091    const TString&  GetSecretKey() const { return fSecretKey; }
0092    TString         GetAuthType() const { return fAuthType; }
0093    TString         GetRequest(TS3HTTPRequest::EHTTPVerb httpVerb, Bool_t appendCRLF=kTRUE);
0094 
0095    TS3HTTPRequest& SetHost(const TString& host);
0096    TS3HTTPRequest& SetBucket(const TString& bucket);
0097    TS3HTTPRequest& SetObjectKey(const TString& objectKey);
0098    TS3HTTPRequest& SetAccessKey(const TString& accessKey);
0099    TS3HTTPRequest& SetSecretKey(const TString& secretKey);
0100    TS3HTTPRequest& SetAuthKeys(const TString& accessKey, const TString& secretKey);
0101    TS3HTTPRequest& SetAuthType(TS3HTTPRequest::EAuthType authType);
0102    TS3HTTPRequest& SetSessionToken(const TString& token);
0103 
0104    ClassDefOverride(TS3HTTPRequest, 0)  // Create generic HTTP request for Amazon S3 and Google Storage services
0105 };
0106 
0107 
0108 //////////////////////////////////////////////////////////////////////////
0109 //                                                                      //
0110 //  Inlines                                                             //
0111 //                                                                      //
0112 //////////////////////////////////////////////////////////////////////////
0113 
0114 inline TS3HTTPRequest& TS3HTTPRequest::SetHost(const TString& host)
0115 {
0116    fHost = host;
0117    return *this;
0118 }
0119 
0120 inline TS3HTTPRequest& TS3HTTPRequest::SetBucket(const TString& bucket)
0121 {
0122    fBucket = bucket;
0123    return *this;
0124 }
0125 
0126 inline TS3HTTPRequest& TS3HTTPRequest::SetObjectKey(const TString& objectKey)
0127 {
0128    fObjectKey = objectKey;
0129    return *this;
0130 }
0131 
0132 inline TS3HTTPRequest& TS3HTTPRequest::SetAuthKeys(const TString& accessKey, const TString& secretKey)
0133 {
0134    fAccessKey = accessKey;
0135    fSecretKey = secretKey;
0136    return *this;
0137 }
0138 
0139 inline TS3HTTPRequest& TS3HTTPRequest::SetAuthType(TS3HTTPRequest::EAuthType authType)
0140 {
0141    fAuthType = authType;
0142    return *this;
0143 }
0144 
0145 inline TS3HTTPRequest& TS3HTTPRequest::SetAccessKey(const TString& accessKey)
0146 {
0147    fAccessKey = accessKey;
0148    return *this;
0149 }
0150 
0151 inline TS3HTTPRequest& TS3HTTPRequest::SetSecretKey(const TString& secretKey)
0152 {
0153    fSecretKey = secretKey;
0154    return *this;
0155 }
0156 
0157 inline TS3HTTPRequest& TS3HTTPRequest::SetSessionToken(const TString& token)
0158 {
0159    fSessionToken = token;
0160    return *this;
0161 }
0162 
0163 #endif