Преглед на файлове

[security] Picking up the current HiveServer2 server

Romain Rigaux преди 11 години
родител
ревизия
46f3efa763

+ 1 - 0
apps/security/src/security/templates/hive.mako

@@ -26,6 +26,7 @@ from django.utils.translation import ugettext as _
 ${ commonheader(_('Hadoop Security'), "security", user) | n,unicode }
 ${ layout.menubar(section='hive') }
 
+
 <script type="text/html" id="role">
   <div class="acl-block-title"><i class="fa fa-cube"></i> <a href="javascript: void(0)"><span data-bind="text: name"></span></a></div>
   <div data-bind="template: { name: 'privilege', foreach: privileges }"></div>

+ 2 - 5
apps/security/src/security/views.py

@@ -17,16 +17,13 @@
 
 import json
 
-from beeswax.api import autocomplete
 from desktop.lib.django_util import render
+from libsentry.sentry_site import get_hive_sentry_provider
 
 
 def hive(request):
-  assist = autocomplete(request, database=None, table=None)
-
   return render("hive.mako", request, {
-      'assist': assist,
-      'initial': json.dumps({'user': request.user.username}),
+      'initial': json.dumps({'user': request.user.username, 'sentry_provider': get_hive_sentry_provider()}),
   })
 
 

+ 3 - 3
apps/security/static/js/hive.ko.js

@@ -236,7 +236,7 @@ var Role = function (vm, role) {
 }
 
 
-var Assist = function (vm) {
+var Assist = function (vm, initial) {
   var self = this;
 
   self.compareNames = function (a, b) {
@@ -251,7 +251,7 @@ var Assist = function (vm) {
   self.path.subscribe(function (path) {
     vm.updatePathHash(path);
   });
-  self.server = ko.observable('server1');
+  self.server = ko.observable(initial.sentry_provider);
   self.db = ko.computed(function () {
     return self.path().split(/[.]/)[0];
   });
@@ -636,7 +636,7 @@ var HiveViewModel = function (initial) {
   }, self);
 
   self.availableHadoopGroups = ko.observableArray();
-  self.assist = new Assist(self);
+  self.assist = new Assist(self, initial);
 
   // Editing
   self.showCreateRole = ko.observable(false);

+ 8 - 0
desktop/libs/libsentry/src/libsentry/conf.py

@@ -15,6 +15,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
+
 from django.utils.translation import ugettext_lazy as _t
 from desktop.lib.conf import Config
 
@@ -32,3 +34,9 @@ PORT=Config(
   type=int,
   default=10001,
 )
+
+SENTRY_CONF_DIR = Config(
+  key='sentry_conf_dir',
+  help=_t('Sentry configuration directory, where sentry-site.xml is located.'),
+  default=os.environ.get("SENTRY_CONF_DIR", '/etc/sentry/conf')
+)

+ 65 - 0
desktop/libs/libsentry/src/libsentry/sentry_site.py

@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. 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 errno
+import logging
+import os.path
+
+from hadoop import confparse
+
+from libsentry.conf import SENTRY_CONF_DIR
+
+
+LOG = logging.getLogger(__name__)
+
+
+_SENTRY_SITE_PATH = None
+_SENTRY_SITE_DICT = None
+
+_CONF_HIVE_PROVIDER = 'hive.sentry.provider'
+
+
+def reset():
+  global _SENTRY_SITE_DICT
+  _SENTRY_SITE_DICT = None
+
+
+def get_conf():
+  if _SENTRY_SITE_DICT is None:
+    _parse_site()
+  return _SENTRY_SITE_DICT
+
+
+
+def get_hive_sentry_provider():
+  return get_conf().get(_CONF_HIVE_PROVIDER, 'default')
+
+
+def _parse_site():
+  global _SENTRY_SITE_DICT
+  global _SENTRY_SITE_PATH
+
+  _SENTRY_SITE_PATH = os.path.join(SENTRY_CONF_DIR.get(), 'sentry-site.xml')
+  try:
+    data = file(_SENTRY_SITE_PATH, 'r').read()
+  except IOError, err:
+    if err.errno != errno.ENOENT:
+      LOG.error('Cannot read from "%s": %s' % (_SENTRY_SITE_PATH, err))
+      return
+    data = ""
+
+  _SENTRY_SITE_DICT = confparse.ConfParse(data)