hive.ko.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. // groups, priviledges
  17. var Priviledge = function (vm, priviledge) {
  18. var self = this;
  19. self.privilegeScope = ko.observable(typeof priviledge.privilegeScope != "undefined" && priviledge.privilegeScope != null ? priviledge.privilegeScope : "");
  20. self.serverName = ko.observable(typeof priviledge.serverName != "undefined" && priviledge.serverName != null ? priviledge.serverName : "");
  21. self.dbName = ko.observable(typeof priviledge.dbName != "undefined" && priviledge.dbName != null ? priviledge.dbName : "");
  22. self.tableName = ko.observable(typeof priviledge.tableName != "undefined" && priviledge.tableName != null ? priviledge.tableName : "");
  23. self.URI = ko.observable(typeof priviledge.URI != "undefined" && priviledge.URI != null ? priviledge.URI : "");
  24. self.action = ko.observable(typeof priviledge.action != "undefined" && priviledge.action != null ? priviledge.action : "");
  25. self.availablePriviledges = ko.observableArray(['SERVER', 'DATABASE', 'TABLE']);
  26. self.availableActions = ko.observableArray(['SELECT', 'INSERT', 'ALL']);
  27. }
  28. var Role = function(vm, priviledge) {
  29. var self = this;
  30. self.priviledges = ko.observableArray();
  31. self.groups = ko.observableArray();
  32. self.name = ko.observable('');
  33. self.addGroup = function() {
  34. self.groups.push('');
  35. }
  36. self.addPriviledge = function() {
  37. self.priviledges.push(new Priviledge(vm, {}));
  38. }
  39. self.edit = function() {
  40. $(".jHueNotify").hide();
  41. $.post("/security/api/hive/edit_role", {
  42. role: ko.mapping.toJSON(self)
  43. }, function (data) {
  44. if (data.status == 0) {
  45. $(document).trigger("info", data.message);
  46. self.roles.push(self);
  47. }
  48. else {
  49. $(document).trigger("error", data.message);
  50. }
  51. }).fail(function (xhr, textStatus, errorThrown) {
  52. $(document).trigger("error", xhr.responseText);
  53. });
  54. }
  55. }
  56. var Assist = function (vm) {
  57. var self = this;
  58. self.path = ko.observable('');
  59. self.path.subscribe(function () {
  60. self.fetchDatabases();
  61. });
  62. self.files = ko.observableArray();
  63. self.fetchDatabases = function() {
  64. var request = {
  65. url: '/beeswax/api/autocomplete', // impala too
  66. dataType: 'json',
  67. type: 'GET',
  68. success: function(data) {
  69. self.files(data.databases);
  70. },
  71. cache: false
  72. };
  73. $.ajax(request).fail(function (xhr, textStatus, errorThrown) {
  74. $(document).trigger("error", xhr.responseText);
  75. });
  76. };
  77. }
  78. var HiveViewModel = function (initial) {
  79. var self = this;
  80. // Models
  81. self.roles = ko.observableArray();
  82. self.privileges = ko.observableArray();
  83. self.availableHadoopGroups = ko.mapping.fromJS(initial.hadoop_groups);
  84. self.assist = new Assist(self);
  85. // Edition
  86. self.role = new Role();
  87. self.init = function() {
  88. self.list_sentry_roles_by_group();
  89. self.assist.fetchDatabases();
  90. };
  91. self.list_sentry_roles_by_group = function() {
  92. $.getJSON('/security/api/hive/list_sentry_roles_by_group', {
  93. }, function (data) {
  94. $.each(data.roles, function(index, item) {
  95. self.roles.push(item);
  96. });
  97. }).fail(function (xhr, textStatus, errorThrown) {
  98. $(document).trigger("error", xhr.responseText);
  99. });
  100. };
  101. self.list_sentry_privileges_by_role = function(role) {
  102. $.ajax({
  103. type: "POST",
  104. url: "/security/api/hive/list_sentry_privileges_by_role",
  105. data: {
  106. 'roleName': role.name
  107. },
  108. success: function (data) {
  109. $.each(data.sentry_privileges, function(index, item) {
  110. self.privileges.push(item);
  111. });
  112. window.location.hash = "#privileges";
  113. }
  114. }).fail(function (xhr, textStatus, errorThrown) {
  115. $(document).trigger("error", xhr.responseText);
  116. });
  117. };
  118. };
  119. function logGA(page) {
  120. if (typeof trackOnGA == 'function') {
  121. trackOnGA('security/' + page);
  122. }
  123. }