hive.ko.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.files = ko.observableArray();
  60. }
  61. var HiveViewModel = function (initial) {
  62. var self = this;
  63. // Models
  64. self.roles = ko.observableArray();
  65. self.privileges = ko.observableArray();
  66. self.availableHadoopGroups = ko.mapping.fromJS(initial.hadoop_groups);
  67. self.assist = new Assist(self);
  68. // Edition
  69. self.role = new Role();
  70. self.init = function() {
  71. self.list_sentry_roles_by_group();
  72. };
  73. self.list_sentry_roles_by_group = function() {
  74. $.getJSON('/security/api/hive/list_sentry_roles_by_group', {
  75. }, function (data) {
  76. $.each(data.roles, function(index, item) {
  77. self.roles.push(item);
  78. });
  79. }).fail(function (xhr, textStatus, errorThrown) {
  80. $(document).trigger("error", xhr.responseText);
  81. });
  82. };
  83. self.list_sentry_privileges_by_role = function(role) {
  84. $.ajax({
  85. type: "POST",
  86. url: "/security/api/hive/list_sentry_privileges_by_role",
  87. data: {
  88. 'roleName': role.name
  89. },
  90. success: function (data) {
  91. $.each(data.sentry_privileges, function(index, item) {
  92. self.privileges.push(item);
  93. });
  94. window.location.hash = "#privileges";
  95. }
  96. }).fail(function (xhr, textStatus, errorThrown) {
  97. $(document).trigger("error", xhr.responseText);
  98. });
  99. };
  100. };
  101. function logGA(page) {
  102. if (typeof trackOnGA == 'function') {
  103. trackOnGA('security/' + page);
  104. }
  105. }