ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oleew...@apache.org
Subject [2/2] ambari git commit: AMBARI-19665. Add basic auth support for Log Search Swagger UI (oleewere)
Date Mon, 23 Jan 2017 12:39:16 GMT
AMBARI-19665. Add basic auth support for Log Search Swagger UI (oleewere)

Change-Id: I369d3e994e178a98a1a925bb32fdb400232f71d4


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a47cc0a7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a47cc0a7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a47cc0a7

Branch: refs/heads/branch-2.5
Commit: a47cc0a79945a268f0a0f6010bd400b60b1ee23c
Parents: cbbe4f8
Author: oleewere <oleewere@gmail.com>
Authored: Mon Jan 23 11:32:08 2017 +0100
Committer: oleewere <oleewere@gmail.com>
Committed: Mon Jan 23 13:38:58 2017 +0100

----------------------------------------------------------------------
 .../ambari/logsearch/conf/ApiDocConfig.java     |  1 -
 .../src/main/resources/swagger/swagger.html     | 26 +++++++++-----------
 2 files changed, 11 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a47cc0a7/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
index 0ddad65..86c1edd 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java
@@ -45,7 +45,6 @@ public class ApiDocConfig {
   public BeanConfig swaggerConfig() throws UnknownHostException {
     BeanConfig beanConfig = new BeanConfig();
     beanConfig.setSchemes(new String[]{"http", "https"});
-    beanConfig.setHost(InetAddress.getLocalHost().getHostAddress() + ":61888"); // TODO:
port from property
     beanConfig.setBasePath("/api/v1");
     beanConfig.setTitle("Log Search REST API");
     beanConfig.setDescription("Log aggregation, analysis, and visualization.");

http://git-wip-us.apache.org/repos/asf/ambari/blob/a47cc0a7/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
b/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
index e1b052a..33346d3 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
@@ -17,7 +17,7 @@
 -->
 <html>
 <head>
-    <title>Swagger UI</title>
+    <title>Log Search REST API</title>
     <link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
     <link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
     <link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
@@ -43,7 +43,7 @@
             if (url && url.length > 1) {
                 url = decodeURIComponent(url[1]);
             } else {
-                var urlPrefix = location.protocol+'//'+location.hostname+(location.port ?
':'+location.port: '');
+                var urlPrefix = location.protocol +'//'+ location.hostname+(location.port
? ':'+location.port: '');
                 url = urlPrefix + "/api/v1/swagger.yaml";
             }
             window.swaggerUi = new SwaggerUi({
@@ -74,21 +74,16 @@
             });
 
             function addApiKeyAuthorization(){
-                var key = encodeURIComponent($('#input_apiKey')[0].value);
-                if(key && key.trim() != "") {
-                    var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key,
"query");
-                    window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
-                    log("added key " + key);
+                var username = encodeURIComponent($('#input_username')[0].value);
+                var password = encodeURIComponent($('#input_password')[0].value);
+                if (username && username.trim() != "" && password &&
password != "") {
+                    var apiKeyAuth = new SwaggerClient.PasswordAuthorization("Authorization",
username, password);
+                    window.swaggerUi.api.clientAuthorizations.add("key", apiKeyAuth);
+                    log("added authorization header: " + 'Basic ' + btoa(username + ':' +
password));
                 }
             }
 
-            $('#input_apiKey').change(addApiKeyAuthorization);
-
-            // if you have an apiKey you would like to pre-populate on the page for demonstration
purposes...
-            /*
-             var apiKey = "myApiKeyXXXX123456789";
-             $('#input_apiKey').val(apiKey);
-             */
+            $('#input_username, #input_password').change(addApiKeyAuthorization);
 
             window.swaggerUi.load();
 
@@ -107,7 +102,8 @@
         <a id="logo" href="http://swagger.io">swagger</a>
         <form id='api_selector'>
             <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl"
name="baseUrl" type="text"/></div>
-            <div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey"
type="text"/></div>
+            <div class="input"><input placeholder="username" id="input_username"
name="username" type="text" size="10"></div>
+            <div class="input"><input placeholder="password" id="input_password"
name="password" type="password" size="10"></div>
             <div class='input'><a id="explore" href="#">Explore</a></div>
         </form>
     </div>


Mime
View raw message