You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pulsar.apache.org by gi...@git.apache.org on 2017/07/20 18:59:03 UTC

[GitHub] rdhabalia commented on a change in pull request #586: Add athenz authentication plugin for C++ client

rdhabalia commented on a change in pull request #586: Add athenz authentication plugin for C++ client
URL: https://github.com/apache/incubator-pulsar/pull/586#discussion_r128594384
 
 

 ##########
 File path: pulsar-client-cpp/lib/ZTSClient.cc
 ##########
 @@ -0,0 +1,288 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "ZTSClient.h"
+#include <sstream>
+
+#include <unistd.h>
+#include <string.h>
+#include <time.h>
+
+#include <openssl/sha.h>
+#include <openssl/rsa.h>
+#include <openssl/ec.h>
+#include <openssl/pem.h>
+
+#include <curl/curl.h>
+
+#include <json/value.h>
+#include <json/reader.h>
+
+#include <boost/lexical_cast.hpp>
+#include <boost/xpressive/xpressive.hpp>
+#include <boost/archive/iterators/base64_from_binary.hpp>
+#include <boost/archive/iterators/transform_width.hpp>
+
+
+DECLARE_LOG_OBJECT()
+
+namespace pulsar {
+    
+    const static std::string DEFAULT_PRINCIPAL_HEADER = "Athenz-Principal-Auth";
+    const static std::string DEFAULT_ROLE_HEADER = "Athenz-Role-Auth";
+    const static int REQUEST_TIMEOUT = 10000;
+    const static int DEFAULT_TOKEN_EXPIRATION_TIME = 3600;
+    const static int MIN_TOKEN_EXPIRATION_TIME = 900;
+    const static int MAX_HTTP_REDIRECTS = 20;
+    const static long long FETCH_EPSILON = 60; // if cache expires in 60 seconds, get it from ZTS
+    const static std::string requiredParams[] = {"tenantDomain", "tenantService", "providerDomain", "privateKeyPath", "ztsUrl"};
+    
+    std::map<std::string, RoleToken> ZTSClient::roleTokenCache_;
+    
+    ZTSClient::ZTSClient (std::map<std::string, std::string>& params) {
+        // required parameter check
+        bool valid = true;
+        for (int i = 0; i < sizeof(requiredParams) / sizeof(std::string) ; i++) {
+            if (params.find(requiredParams[i]) == params.end()) {
+                valid = false;
+                LOG_ERROR(requiredParams[i] << " parameter is required");
+            }
+        }
+        if (!valid) {
+            LOG_ERROR("Some parameters are missing")
+            return;
+        }
+        
+        // set required value
+        tenantDomain_ = params["tenantDomain"];
 
 Review comment:
   should we do `requiredParams[0]` in order to avoid any typo ?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services