KNOX-1194 - Safe loading and dumping of yaml, and filter empty-value properties 
from JSON output.


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

Branch: refs/heads/master
Commit: 92946b8d7b6efaabaa0f1074843a3a9682fa3367
Parents: 7e58855
Author: Phil Zampino <pzamp...@apache.org>
Authored: Fri Feb 23 16:42:37 2018 -0500
Committer: Phil Zampino <pzamp...@apache.org>
Committed: Fri Feb 23 22:37:46 2018 -0500

----------------------------------------------------------------------
 .../provider-config-selector.component.ts       | 16 ++++++++++
 .../resource-detail.component.html              |  4 ++-
 .../resource-detail.component.ts                | 33 +++++++++++++++++---
 .../applications/admin-ui/app/index.html        |  2 +-
 .../app/inline.49eec4a5979db513c1fa.bundle.js   |  1 -
 .../app/inline.49efa231bf249ddc231a.bundle.js   |  1 +
 .../app/main.511817c8d904b468f742.bundle.js     |  1 +
 .../app/main.a4b4cc18906d76011422.bundle.js     |  1 -
 8 files changed, 50 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/92946b8d/gateway-admin-ui/src/app/provider-config-selector/provider-config-selector.component.ts
----------------------------------------------------------------------
diff --git 
a/gateway-admin-ui/src/app/provider-config-selector/provider-config-selector.component.ts
 
b/gateway-admin-ui/src/app/provider-config-selector/provider-config-selector.component.ts
index 08dd587..d3029f0 100644
--- 
a/gateway-admin-ui/src/app/provider-config-selector/provider-config-selector.component.ts
+++ 
b/gateway-admin-ui/src/app/provider-config-selector/provider-config-selector.component.ts
@@ -1,3 +1,19 @@
+/*
+ * 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.
+ */
 import { Component, OnInit, ViewChild } from '@angular/core';
 import { ResourceService } from "../resource/resource.service";
 import { Resource } from "../resource/resource";

http://git-wip-us.apache.org/repos/asf/knox/blob/92946b8d/gateway-admin-ui/src/app/resource-detail/resource-detail.component.html
----------------------------------------------------------------------
diff --git 
a/gateway-admin-ui/src/app/resource-detail/resource-detail.component.html 
b/gateway-admin-ui/src/app/resource-detail/resource-detail.component.html
index a47ac05..fc8d1d7 100644
--- a/gateway-admin-ui/src/app/resource-detail/resource-detail.component.html
+++ b/gateway-admin-ui/src/app/resource-detail/resource-detail.component.html
@@ -192,7 +192,9 @@
             <td>
               <div>
                 <span [class]="!getServiceVersionEditFlag(service) && 
!service.version ? 'inline-editable' : ''"
-                      (click)="setServiceVersionEditFlag(service, 
true)"><strong>{{ service.name }}</strong></span>
+                      (click)="setServiceVersionEditFlag(service, true)"
+                      title="Set version"
+                      data-toggle="tooltip"><strong>{{ service.name 
}}</strong></span>
                 <span *ngIf="!getServiceVersionEditFlag(service) && 
service.version"
                       (click)="setServiceVersionEditFlag(service, true)"
                       [class]="service.version ? 'inline-editable' : 
''">({{service.version}})</span>

http://git-wip-us.apache.org/repos/asf/knox/blob/92946b8d/gateway-admin-ui/src/app/resource-detail/resource-detail.component.ts
----------------------------------------------------------------------
diff --git 
a/gateway-admin-ui/src/app/resource-detail/resource-detail.component.ts 
b/gateway-admin-ui/src/app/resource-detail/resource-detail.component.ts
index e58bfeb..14a5213 100644
--- a/gateway-admin-ui/src/app/resource-detail/resource-detail.component.ts
+++ b/gateway-admin-ui/src/app/resource-detail/resource-detail.component.ts
@@ -117,7 +117,7 @@ export class ResourceDetailComponent implements OnInit {
             } else if (res.name.endsWith('yaml') || res.name.endsWith('yml')) {
                 // Parse the YAML representation
                 let yaml = require('js-yaml');
-                contentObj = yaml.load(this.resourceContent);
+                contentObj = yaml.safeLoad(this.resourceContent);
                 this.providers = contentObj['providers'];
             } else if (res.name.endsWith('xml')) {
                 // Parse the XML representation
@@ -285,25 +285,48 @@ export class ResourceDetailComponent implements OnInit {
       let serialized: string;
 
       let tmp = {};
-      tmp['discovery-address'] = desc.discoveryAddress;
+      if (desc.discoveryAddress) {
+        tmp['discovery-address'] = desc.discoveryAddress;
+      }
       if (desc.discoveryUser) {
         tmp['discovery-user'] = desc.discoveryUser;
       }
       if (desc.discoveryPassAlias) {
         tmp['discovery-pwd-alias'] = desc.discoveryPassAlias;
       }
-      tmp['cluster'] = desc.discoveryCluster;
+      if (desc.discoveryCluster) {
+        tmp['cluster'] = desc.discoveryCluster;
+      }
       tmp['provider-config-ref'] = desc.providerConfig;
       tmp['services'] = desc.services;
 
       switch(format) {
           case 'json': {
-              serialized = JSON.stringify(tmp, null, 2);
+              serialized =
+                  JSON.stringify(tmp,
+                                 (key, value) => {
+                                   let result = value;
+                                   switch(typeof value) {
+                                     case 'string': // Don't serialize empty 
string value properties
+                                       result = (value.length > 0) ? value : 
undefined;
+                                       break;
+                                     case 'object':
+                                       if (Array.isArray(value)) {
+                                         // Don't serialize empty array value 
properties
+                                         result = (value.length) > 0 ? value : 
undefined;
+                                       } else {
+                                         // Don't serialize object value 
properties
+                                         result = 
(Object.getOwnPropertyNames(value).length > 0) ? value : undefined;
+                                       }
+                                       break;
+                                   }
+                                   return result;
+                                 }, 2);
               break;
           }
           case 'yaml': {
               let yaml = require('js-yaml');
-              serialized = '---\n' + yaml.dump(tmp);
+              serialized = '---\n' + yaml.safeDump(tmp);
               break;
           }
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/92946b8d/gateway-applications/src/main/resources/applications/admin-ui/app/index.html
----------------------------------------------------------------------
diff --git 
a/gateway-applications/src/main/resources/applications/admin-ui/app/index.html 
b/gateway-applications/src/main/resources/applications/admin-ui/app/index.html
index 31ae661..6f5a825 100644
--- 
a/gateway-applications/src/main/resources/applications/admin-ui/app/index.html
+++ 
b/gateway-applications/src/main/resources/applications/admin-ui/app/index.html
@@ -11,4 +11,4 @@
   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.
---><!doctype html><html><head><meta charset="utf-8"><title>Apache Knox 
Manager</title><meta name="viewport" 
content="width=device-width,initial-scale=1"><link rel="icon" 
type="image/x-icon" href="favicon.ico"><meta name="viewport" 
content="width=device-width,initial-scale=1"><!-- Latest compiled and minified 
CSS --><link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"; 
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
 crossorigin="anonymous"><!-- Optional theme --><link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css";
 
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
 crossorigin="anonymous"><!-- Custom styles for this template --><link 
href="assets/sticky-footer.css" rel="stylesheet"><script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js";></script><!--
 Latest compiled and minified JavaScript --><scr
 ipt src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"; 
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
 crossorigin="anonymous"></script><script 
src="assets/vkbeautify.js"></script><link 
href="styles.2ee5b7f4cd59a6cf015e.bundle.css" 
rel="stylesheet"/></head><body><div class="navbar-wrapper"><div 
class="container-fluid"><nav class="navbar navbar-inverse 
navbar-static-top"><div class="container-fluid"><div 
class="navbar-header"><button type="button" class="navbar-toggle collapsed" 
data-toggle="collapse" data-target="#navbar" aria-expanded="false" 
aria-controls="navbar"><span class="sr-only">Toggle navigation</span> <span 
class="icon-bar"></span> <span class="icon-bar"></span> <span 
class="icon-bar"></span></button> <a class="navbar-brand" href="#"><img 
style="max-width:200px; margin-top: -9px;" 
src="assets/knox-logo-transparent.gif" alt="Apache Knox 
Manager"></a></div></div></nav></div><!-- Content --><resource-management></res
 ource-management><footer class="footer"><div>Knox Manager Version 
0.1.0</div><gateway-version></gateway-version></footer><script 
type="text/javascript" 
src="inline.49eec4a5979db513c1fa.bundle.js"></script><script 
type="text/javascript" 
src="scripts.c50bb762c438ae0f8842.bundle.js"></script><script 
type="text/javascript" 
src="main.a4b4cc18906d76011422.bundle.js"></script></div></body></html>
\ No newline at end of file
+--><!doctype html><html><head><meta charset="utf-8"><title>Apache Knox 
Manager</title><meta name="viewport" 
content="width=device-width,initial-scale=1"><link rel="icon" 
type="image/x-icon" href="favicon.ico"><meta name="viewport" 
content="width=device-width,initial-scale=1"><!-- Latest compiled and minified 
CSS --><link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"; 
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
 crossorigin="anonymous"><!-- Optional theme --><link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css";
 
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
 crossorigin="anonymous"><!-- Custom styles for this template --><link 
href="assets/sticky-footer.css" rel="stylesheet"><script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js";></script><!--
 Latest compiled and minified JavaScript --><scr
 ipt src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"; 
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
 crossorigin="anonymous"></script><script 
src="assets/vkbeautify.js"></script><link 
href="styles.2ee5b7f4cd59a6cf015e.bundle.css" 
rel="stylesheet"/></head><body><div class="navbar-wrapper"><div 
class="container-fluid"><nav class="navbar navbar-inverse 
navbar-static-top"><div class="container-fluid"><div 
class="navbar-header"><button type="button" class="navbar-toggle collapsed" 
data-toggle="collapse" data-target="#navbar" aria-expanded="false" 
aria-controls="navbar"><span class="sr-only">Toggle navigation</span> <span 
class="icon-bar"></span> <span class="icon-bar"></span> <span 
class="icon-bar"></span></button> <a class="navbar-brand" href="#"><img 
style="max-width:200px; margin-top: -9px;" 
src="assets/knox-logo-transparent.gif" alt="Apache Knox 
Manager"></a></div></div></nav></div><!-- Content --><resource-management></res
 ource-management><footer class="footer"><div>Knox Manager Version 
0.1.0</div><gateway-version></gateway-version></footer><script 
type="text/javascript" 
src="inline.49efa231bf249ddc231a.bundle.js"></script><script 
type="text/javascript" 
src="scripts.c50bb762c438ae0f8842.bundle.js"></script><script 
type="text/javascript" 
src="main.511817c8d904b468f742.bundle.js"></script></div></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/92946b8d/gateway-applications/src/main/resources/applications/admin-ui/app/inline.49eec4a5979db513c1fa.bundle.js
----------------------------------------------------------------------
diff --git 
a/gateway-applications/src/main/resources/applications/admin-ui/app/inline.49eec4a5979db513c1fa.bundle.js
 
b/gateway-applications/src/main/resources/applications/admin-ui/app/inline.49eec4a5979db513c1fa.bundle.js
deleted file mode 100644
index 36c7e4b..0000000
--- 
a/gateway-applications/src/main/resources/applications/admin-ui/app/inline.49eec4a5979db513c1fa.bundle.js
+++ /dev/null
@@ -1 +0,0 @@
-!function(e){var 
n=window.webpackJsonp;window.webpackJsonp=function(r,c,u){for(var 
a,i,f,l=0,s=[];l<r.length;l++)t[i=r[l]]&&s.push(t[i][0]),t[i]=0;for(a in 
c)Object.prototype.hasOwnProperty.call(c,a)&&(e[a]=c[a]);for(n&&n(r,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=o(o.s=u[l]);return
 f};var r={},t={2:0};function o(n){if(r[n])return r[n].exports;var 
t=r[n]={i:n,l:!1,exports:{}};return 
e[n].call(t.exports,t,t.exports,o),t.l=!0,t.exports}o.e=function(e){var 
n=t[e];if(0===n)return new Promise(function(e){e()});if(n)return n[2];var r=new 
Promise(function(r,o){n=t[e]=[r,o]});n[2]=r;var 
c=document.getElementsByTagName("head")[0],u=document.createElement("script");u.type="text/javascript",u.charset="utf-8",u.async=!0,u.timeout=12e4,o.nc&&u.setAttribute("nonce",o.nc),u.src=o.p+""+e+"."+{0:"a4b4cc18906d76011422",1:"aed76669724804835353"}[e]+".chunk.js";var
 a=setTimeout(i,12e4);function i(){u.onerror=u.onload=null,clearTimeout(a);var 
n=t[e];0!==n&&(n&&n[1](new Error("Loading chu
 nk "+e+" failed.")),t[e]=void 0)}return 
u.onerror=u.onload=i,c.appendChild(u),r},o.m=e,o.c=r,o.d=function(e,n,r){o.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},o.n=function(e){var
 n=e&&e.__esModule?function(){return e.default}:function(){return e};return 
o.d(n,"a",n),n},o.o=function(e,n){return 
Object.prototype.hasOwnProperty.call(e,n)},o.p="",o.oe=function(e){throw 
console.error(e),e}}([]);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/92946b8d/gateway-applications/src/main/resources/applications/admin-ui/app/inline.49efa231bf249ddc231a.bundle.js
----------------------------------------------------------------------
diff --git 
a/gateway-applications/src/main/resources/applications/admin-ui/app/inline.49efa231bf249ddc231a.bundle.js
 
b/gateway-applications/src/main/resources/applications/admin-ui/app/inline.49efa231bf249ddc231a.bundle.js
new file mode 100644
index 0000000..965479e
--- /dev/null
+++ 
b/gateway-applications/src/main/resources/applications/admin-ui/app/inline.49efa231bf249ddc231a.bundle.js
@@ -0,0 +1 @@
+!function(e){var 
n=window.webpackJsonp;window.webpackJsonp=function(r,c,u){for(var 
a,i,f,l=0,s=[];l<r.length;l++)t[i=r[l]]&&s.push(t[i][0]),t[i]=0;for(a in 
c)Object.prototype.hasOwnProperty.call(c,a)&&(e[a]=c[a]);for(n&&n(r,c,u);s.length;)s.shift()();if(u)for(l=0;l<u.length;l++)f=o(o.s=u[l]);return
 f};var r={},t={2:0};function o(n){if(r[n])return r[n].exports;var 
t=r[n]={i:n,l:!1,exports:{}};return 
e[n].call(t.exports,t,t.exports,o),t.l=!0,t.exports}o.e=function(e){var 
n=t[e];if(0===n)return new Promise(function(e){e()});if(n)return n[2];var r=new 
Promise(function(r,o){n=t[e]=[r,o]});n[2]=r;var 
c=document.getElementsByTagName("head")[0],u=document.createElement("script");u.type="text/javascript",u.charset="utf-8",u.async=!0,u.timeout=12e4,o.nc&&u.setAttribute("nonce",o.nc),u.src=o.p+""+e+"."+{0:"511817c8d904b468f742",1:"aed76669724804835353"}[e]+".chunk.js";var
 a=setTimeout(i,12e4);function i(){u.onerror=u.onload=null,clearTimeout(a);var 
n=t[e];0!==n&&(n&&n[1](new Error("Loading chu
 nk "+e+" failed.")),t[e]=void 0)}return 
u.onerror=u.onload=i,c.appendChild(u),r},o.m=e,o.c=r,o.d=function(e,n,r){o.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},o.n=function(e){var
 n=e&&e.__esModule?function(){return e.default}:function(){return e};return 
o.d(n,"a",n),n},o.o=function(e,n){return 
Object.prototype.hasOwnProperty.call(e,n)},o.p="",o.oe=function(e){throw 
console.error(e),e}}([]);
\ No newline at end of file

Reply via email to