/usr/share/maas/web/static/js/angular/directives/ssh_keys.js is in maas-region-api 2.4.0~beta2-6865-gec43e47e6-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | /* Copyright 2016 Canonical Ltd. This software is licensed under the
* GNU Affero General Public License version 3 (see the file LICENSE).
*
* SSH keys directive.
*/
angular.module('MAAS').directive('maasSshKeys', [
'$sce', 'SSHKeysManager', 'ManagerHelperService', 'JSONService',
function($sce, SSHKeysManager, ManagerHelperService, JSONService) {
return {
restrict: "E",
scope: {},
templateUrl: (
'static/partials/ssh-keys.html?v=' + (
MAAS_config.files_version)),
controller: function($scope, $rootScope, $element, $document) {
$scope.loading = true;
$scope.keys = SSHKeysManager.getItems();
$scope.groupedKeys = [];
$scope.add = {
source: 'lp',
authId: '',
key: '',
error: null,
saving: false
};
$scope.sourceTitles = {
'lp': 'Launchpad',
'gh': 'Github',
'upload': 'Upload'
};
$scope.openRow = null;
$scope.rowMode = null;
// Expose trustAsHtml on the scope for the view to use.
$scope.trustAsHtml = $sce.trustAsHtml;
// Open a row.
$scope.open = function(obj, mode) {
$scope.openRow = obj.id;
$scope.rowMode = mode;
};
// Close the open row.
$scope.close = function() {
$scope.openRow = null;
};
// Returns true if the key can be imported.
$scope.canImportKeys = function() {
if($scope.add.saving) {
return false;
} else if ($scope.add.source === 'lp' ||
$scope.add.source === 'gh') {
return $scope.add.authId.length > 0;
} else {
return $scope.add.key.length > 0;
}
};
// Called to import the key.
$scope.importKeys = function() {
if(!$scope.canImportKeys()) {
return;
}
$scope.add.error = null;
$scope.add.saving = true;
if($scope.add.source === 'lp' ||
$scope.add.source === 'gh') {
SSHKeysManager.importKeys({
'protocol': $scope.add.source,
'auth_id': $scope.add.authId
}).then(function() {
$scope.add.saving = false;
$scope.add.source = 'lp';
$scope.add.authId = '';
$scope.add.key = '';
}, function(error) {
$scope.add.saving = false;
var errorJson = JSONService.tryParse(error);
if(angular.isObject(errorJson)) {
if(angular.isArray(errorJson.__all__)) {
$scope.add.error = errorJson.__all__[0];
} else {
$scope.add.error = error;
}
} else {
$scope.add.error = error;
}
});
} else {
SSHKeysManager.createItem({
'key': $scope.add.key
}).then(function() {
$scope.add.saving = false;
$scope.add.source = 'lp';
$scope.add.authId = '';
$scope.add.key = '';
}, function(error) {
$scope.add.saving = false;
var errorJson = JSONService.tryParse(error);
if(angular.isObject(errorJson)) {
if(angular.isArray(errorJson.key)) {
$scope.add.error = errorJson.key[0];
} else if(angular.isArray(errorJson.__all__)) {
$scope.add.error = errorJson.__all__[0];
} else {
$scope.add.error = error;
}
} else {
$scope.add.error = error;
}
});
}
};
// Called to delete the selected group of keys.
$scope.confirmDelete = function(obj) {
angular.forEach(obj.keys, function(key) {
SSHKeysManager.deleteItem(key);
});
};
// Updates the groupedKeys that is used to render the table.
$scope.$watchCollection("keys", function() {
$scope.groupedKeys = [];
var keyMap = {};
angular.forEach($scope.keys, function(key) {
var groupObj, keysource = key.keysource;
if(angular.isObject(keysource)) {
var keysourceKey = (
keysource.protocol + '/' + keysource.auth_id);
groupObj = keyMap[keysourceKey];
if(angular.isObject(groupObj)) {
groupObj.keys.push(key);
} else {
groupObj = {
id: keysourceKey,
source: keysource.protocol,
authId: keysource.auth_id,
keys: [key]
};
keyMap[keysourceKey] = groupObj;
$scope.groupedKeys.push(groupObj);
}
} else {
groupObj = {
id: 'upload/' + key.id,
source: 'upload',
authId: '',
keys: [key]
};
$scope.groupedKeys.push(groupObj);
}
});
});
ManagerHelperService.loadManager($scope, SSHKeysManager).then(
function() {
$scope.loading = false;
});
}
};
}]);
|