hdfs.ko.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. function parseAcl(acl) {
  17. m = acl.match(/(.*?):(.*?):(.)(.)(.)/);
  18. return {
  19. 'type': m[1],
  20. 'name': m[2],
  21. 'r': m[3],
  22. 'w': m[4],
  23. 'x': m[5],
  24. }
  25. }
  26. function printAcl(acl) {
  27. return acl['type'] + ':' + acl['name'] + ':' + acl['r'] + acl['w'] + acl['x'];
  28. }
  29. var Assist = function (vm, assist) {
  30. var self = this;
  31. self.path = ko.observable('');
  32. self.path.subscribe(function () {
  33. self.fetchPath()
  34. });
  35. self.files = ko.observableArray();
  36. self.acls = ko.observableArray();
  37. self.owner = ko.observable('');
  38. self.group = ko.observable('');
  39. self.changed = ko.observable(true); // mocking to true
  40. self.addAcl = function() {
  41. // should have a good template, also understable for non user, user/group icons button
  42. self.acls.push(parseAcl('::---'));
  43. };
  44. self.fetchPath = function () {
  45. $.getJSON('/filebrowser/view' + self.path() + "?pagesize=15&format=json", function (data) { // Will create a cleaner API by calling directly directly webhdfs#LISTDIR?
  46. self.files.removeAll();
  47. $.each(data.files, function(index, item) {
  48. self.files.push(item.path);
  49. });
  50. self.getAcls();
  51. }).fail(function (xhr, textStatus, errorThrown) {
  52. $(document).trigger("error", xhr.responseText);
  53. });
  54. };
  55. self.getAcls = function () {
  56. $.getJSON('/security/api/hdfs/get_acls', {
  57. 'path': self.path()
  58. }, function (data) {
  59. self.acls.removeAll();
  60. $.each(data.entries, function(index, item) {
  61. self.acls.push(item);
  62. });
  63. self.acls.push(parseAcl("user:joe:r-x")); // mocking
  64. self.acls.push(parseAcl("group::r--")); // mocking
  65. self.acls.push(parseAcl("group:execs:rw-")); // mocking
  66. self.owner(data.owner);
  67. self.group(data.group);
  68. }).fail(function (xhr, textStatus, errorThrown) {
  69. $(document).trigger("error", xhr.responseText);
  70. });
  71. };
  72. self.save = function () {
  73. // update acls, add new ones, remove ones?
  74. }
  75. }
  76. // not sure if we should merge Assist here yet
  77. var HdfsViewModel = function (context_json) {
  78. var self = this;
  79. // Models
  80. self.assist = new Assist(self, context_json.assist);
  81. self.assist.path('/tmp');
  82. function logGA(page) {
  83. if (typeof trackOnGA == 'function') {
  84. trackOnGA('security/hdfs' + page);
  85. }
  86. }
  87. };