You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/03/26 10:36:20 UTC

[GitHub] [pulsar] 0x5e commented on issue #2499: Support for passing basic auth credentials from Python client

0x5e commented on issue #2499:
URL: https://github.com/apache/pulsar/issues/2499#issuecomment-1079658759


   AuthCustom.h
   ```c++
   #pragma once
   
   #include <string>
   #include <map>
   
   #if __has_include(<pulsar/Authentication.h>)
       #include <pulsar/Authentication.h>
   #else
   namespace pulsar {
   
       class AuthenticationDataProvider;
       class Authentication;
   
       typedef std::shared_ptr<AuthenticationDataProvider> AuthenticationDataPtr;
       typedef std::shared_ptr<Authentication> AuthenticationPtr;
       typedef std::map<std::string, std::string> ParamMap;
   
       enum Result
       {
           ResultOk,  /// Operation successful
       };
   
       class AuthenticationDataProvider {
           public:
               virtual ~AuthenticationDataProvider();
               virtual bool hasDataForTls();
               virtual std::string getTlsCertificates();
               virtual std::string getTlsPrivateKey();
               virtual bool hasDataForHttp();
               virtual std::string getHttpAuthType();
               virtual std::string getHttpHeaders();
               virtual bool hasDataFromCommand();
               virtual std::string getCommandData();
   
           protected:
               AuthenticationDataProvider();
       };
   
       class Authentication {
           public:
               virtual ~Authentication();
               virtual const std::string getAuthMethodName() const = 0;
               virtual Result getAuthData(AuthenticationDataPtr& authDataContent) {
                   authDataContent = authData_;
                   return ResultOk;
               }
               static ParamMap parseDefaultFormatAuthParams(const std::string& authParamsString);
   
           protected:
               Authentication();
               AuthenticationDataPtr authData_;
               friend class ClientConfiguration;
       };
   
   }
   #endif
   
   
   namespace pulsar {
   
       AuthenticationDataProvider::AuthenticationDataProvider() {}
   
       AuthenticationDataProvider::~AuthenticationDataProvider() {}
   
       bool AuthenticationDataProvider::hasDataForTls() { return false; }
   
       std::string AuthenticationDataProvider::getTlsCertificates() { return "none"; }
   
       std::string AuthenticationDataProvider::getTlsPrivateKey() { return "none"; }
   
       bool AuthenticationDataProvider::hasDataForHttp() { return false; }
   
       std::string AuthenticationDataProvider::getHttpAuthType() { return "none"; }
   
       std::string AuthenticationDataProvider::getHttpHeaders() { return "none"; }
   
       bool AuthenticationDataProvider::hasDataFromCommand() { return false; }
   
       std::string AuthenticationDataProvider::getCommandData() { return "none"; }
   
       Authentication::Authentication() {}
   
       Authentication::~Authentication() {}
   
   // https://github.com/apache/pulsar/blob/master/pulsar-client-cpp/lib/auth/AuthToken.h
   class AuthDataCustom : public AuthenticationDataProvider {
       public:
           AuthDataCustom(const std::string &commandData);
           ~AuthDataCustom();
   
           bool hasDataForHttp();
           // std::string getHttpHeaders();
           bool hasDataFromCommand();
           std::string getCommandData();
   
       private:
           const std::string commandData_;
   };
   
   // https://github.com/apache/pulsar/blob/master/pulsar-client-cpp/include/pulsar/Authentication.h
   class AuthCustom : public Authentication  {
       public:
           AuthCustom(AuthenticationDataPtr&);
           ~AuthCustom();
   
           static AuthenticationPtr create(const std::string& authParamsString);
   
           const std::string getAuthMethodName() const;
           Result getAuthData(AuthenticationDataPtr& authDataToken);
   
       private:
           AuthenticationDataPtr AuthDataCustom_;
   };
   
   }  // namespace pulsar
   
   ```
   
   AuthCustom.cc
   ```c++
   #include "AuthCustom.h"
   
   namespace pulsar {
   
   // AuthDataCustom
   
   // https://github.com/apache/pulsar/blob/master/pulsar-client-cpp/lib/auth/AuthToken.cc
   AuthDataCustom::AuthDataCustom(const std::string &commandData) : commandData_(commandData) {}
   
   AuthDataCustom::~AuthDataCustom() {}
   
   bool AuthDataCustom::hasDataForHttp() { return false; }
   
   bool AuthDataCustom::hasDataFromCommand() { return true; }
   
   std::string AuthDataCustom::getCommandData() { return commandData_; }
   
   // AuthCustom
   
   AuthCustom::AuthCustom(AuthenticationDataPtr &AuthDataCustom) : AuthDataCustom_(AuthDataCustom) {}
   
   AuthCustom::~AuthCustom() {}
   
   AuthenticationPtr AuthCustom::create(const std::string &commandData) {
       AuthenticationDataPtr AuthDataCustom = AuthenticationDataPtr(new AuthDataCustom(commandData));
       return AuthenticationPtr(new AuthCustom(AuthDataCustom));
   }
   
   const std::string AuthCustom::getAuthMethodName() const { return "auth1"; }
   
   Result AuthCustom::getAuthData(AuthenticationDataPtr &authDataContent) {
       authDataContent = AuthDataCustom_;
       return ResultOk;
   }
   
   
   extern "C" Authentication* create(const std::string &commandData) {
       AuthenticationDataPtr AuthDataCustom = AuthenticationDataPtr(new AuthDataCustom(commandData));
       return (new AuthCustom(AuthDataCustom));
   }
   
   }  // namespace pulsar
   
   ```
   
   
   @HenriqueFSilva this is the code. I forget the detail and not work in that company now. Hope it can help you:)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org