addSecurity_controller.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.AddSecurityController = App.WizardController.extend({
  20. name: 'addSecurityController',
  21. securityEnabled: false,
  22. totalSteps: 4,
  23. content: Em.Object.create({
  24. services: [],
  25. serviceConfigProperties: null,
  26. controllerName: 'addSecurityController'
  27. }),
  28. installedServices: function() {
  29. return App.Service.find().mapProperty('serviceName');
  30. }.property(),
  31. /**
  32. * Loads all prior steps on refresh
  33. */
  34. loadAllPriorSteps: function () {
  35. var step = this.get('currentStep');
  36. switch (step) {
  37. case '4':
  38. case '3':
  39. case '2':
  40. this.loadServiceConfigs();
  41. case '1':
  42. this.loadServices();
  43. }
  44. },
  45. clearServices: function () {
  46. if (this.get('content.services')) {
  47. this.get('content.services').clear();
  48. }
  49. },
  50. /**
  51. * Loads all installed services
  52. */
  53. loadServices: function () {
  54. this.clearServices();
  55. var secureServices;
  56. if(App.get('isHadoop2Stack')) {
  57. secureServices = require('data/HDP2/secure_configs');
  58. } else {
  59. secureServices = require('data/secure_configs');
  60. }
  61. var installedServices = this.get('installedServices');
  62. //General (only non service tab) tab is always displayed
  63. this.get('content.services').push(secureServices.findProperty('serviceName', 'GENERAL'));
  64. installedServices.forEach(function (_service) {
  65. var secureService = secureServices.findProperty('serviceName', _service);
  66. if (secureService) {
  67. this.get('content.services').push(secureService);
  68. }
  69. }, this);
  70. },
  71. saveServiceConfigProperties: function (stepController) {
  72. var serviceConfigProperties = [];
  73. stepController.get('stepConfigs').forEach(function (_content) {
  74. _content.get('configs').forEach(function (_configProperties) {
  75. var displayType = _configProperties.get('displayType');
  76. if (displayType === 'directories' || displayType === 'directory') {
  77. var value = _configProperties.get('value').trim().split(/\s+/g).join(',');
  78. _configProperties.set('value', value);
  79. }
  80. var overrides = _configProperties.get('overrides');
  81. var overridesArray = [];
  82. if(overrides!=null){
  83. overrides.forEach(function(override){
  84. var overrideEntry = {
  85. value: override.get('value'),
  86. hosts: []
  87. };
  88. override.get('selectedHostOptions').forEach(function(host){
  89. overrideEntry.hosts.push(host);
  90. });
  91. overridesArray.push(overrideEntry);
  92. });
  93. }
  94. overridesArray = (overridesArray.length) ? overridesArray : null;
  95. var configProperty = {
  96. id: _configProperties.get('id'),
  97. name: _configProperties.get('name'),
  98. value: _configProperties.get('value'),
  99. defaultValue: _configProperties.get('defaultValue'),
  100. serviceName: _configProperties.get('serviceName'),
  101. domain: _configProperties.get('domain'),
  102. filename: _configProperties.get('filename'),
  103. unit: _configProperties.get('unit'),
  104. components: _configProperties.get('components'),
  105. component: _configProperties.get('component'),
  106. overrides: overridesArray
  107. };
  108. serviceConfigProperties.push(configProperty);
  109. }, this);
  110. }, this);
  111. App.db.setSecureConfigProperties(serviceConfigProperties);
  112. this.set('content.serviceConfigProperties', serviceConfigProperties);
  113. },
  114. /**
  115. * Loads all service config properties
  116. */
  117. loadServiceConfigs: function () {
  118. var serviceConfigProperties = App.db.getSecureConfigProperties();
  119. this.set('content.serviceConfigProperties', serviceConfigProperties);
  120. }
  121. });