addSecurity_controller.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /**
  29. * Loads all prior steps on refresh
  30. */
  31. loadAllPriorSteps: function () {
  32. var step = this.get('currentStep');
  33. switch (step) {
  34. case '4':
  35. case '3':
  36. case '2':
  37. this.loadServiceConfigs();
  38. case '1':
  39. this.loadServices();
  40. }
  41. },
  42. clearServices: function () {
  43. if (this.get('content.services')) {
  44. this.get('content.services').clear();
  45. }
  46. },
  47. /**
  48. * Loads all installed services
  49. */
  50. loadServices: function () {
  51. this.clearServices();
  52. var secureServices = require('data/secure_configs');
  53. var installedServices = App.Service.find().mapProperty('serviceName');
  54. //General (only non service tab) tab is always displayed
  55. this.get('content.services').push(secureServices.findProperty('serviceName', 'GENERAL'));
  56. installedServices.forEach(function (_service) {
  57. var secureService = secureServices.findProperty('serviceName', _service);
  58. if (secureService) {
  59. this.get('content.services').push(secureService);
  60. }
  61. }, this);
  62. },
  63. saveServiceConfigProperties: function (stepController) {
  64. var serviceConfigProperties = [];
  65. stepController.get('stepConfigs').forEach(function (_content) {
  66. _content.get('configs').forEach(function (_configProperties) {
  67. var displayType = _configProperties.get('displayType');
  68. if (displayType === 'directories' || displayType === 'directory') {
  69. var value = _configProperties.get('value').trim().split(/\s+/g).join(',');
  70. _configProperties.set('value', value);
  71. }
  72. var overrides = _configProperties.get('overrides');
  73. var overridesArray = [];
  74. if(overrides!=null){
  75. overrides.forEach(function(override){
  76. var overrideEntry = {
  77. value: override.get('value'),
  78. hosts: []
  79. };
  80. override.get('selectedHostOptions').forEach(function(host){
  81. overrideEntry.hosts.push(host);
  82. });
  83. overridesArray.push(overrideEntry);
  84. });
  85. }
  86. overridesArray = (overridesArray.length) ? overridesArray : null;
  87. var configProperty = {
  88. id: _configProperties.get('id'),
  89. name: _configProperties.get('name'),
  90. value: _configProperties.get('value'),
  91. defaultValue: _configProperties.get('defaultValue'),
  92. serviceName: _configProperties.get('serviceName'),
  93. domain: _configProperties.get('domain'),
  94. filename: _configProperties.get('filename'),
  95. unit: _configProperties.get('unit'),
  96. components: _configProperties.get('components'),
  97. component: _configProperties.get('component'),
  98. overrides: overridesArray
  99. };
  100. serviceConfigProperties.push(configProperty);
  101. }, this);
  102. }, this);
  103. App.db.setSecureConfigProperties(serviceConfigProperties);
  104. this.set('content.serviceConfigProperties', serviceConfigProperties);
  105. },
  106. /**
  107. * Loads all service config properties
  108. */
  109. loadServiceConfigs: function () {
  110. var serviceConfigProperties = App.db.getSecureConfigProperties();
  111. this.set('content.serviceConfigProperties', serviceConfigProperties);
  112. }
  113. });