mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
Adding vault to the new multi select credential widget
the vault credential gets saved to the JT and not to the extra_credentials endpoint.
This commit is contained in:
parent
b79627d57c
commit
20acfd231b
@ -281,6 +281,12 @@
|
|||||||
} else {
|
} else {
|
||||||
data.credential = null;
|
data.credential = null;
|
||||||
}
|
}
|
||||||
|
if ($scope.selectedCredentials && $scope.selectedCredentials
|
||||||
|
.vault && $scope.selectedCredentials
|
||||||
|
.vault.id) {
|
||||||
|
data.vault_credential = $scope.selectedCredentials
|
||||||
|
.vault.id;
|
||||||
|
}
|
||||||
|
|
||||||
data.extra_vars = ToJSON($scope.parseType,
|
data.extra_vars = ToJSON($scope.parseType,
|
||||||
$scope.variables, true);
|
$scope.variables, true);
|
||||||
|
@ -487,13 +487,18 @@ export default
|
|||||||
data.skip_tags = (Array.isArray($scope.skip_tags)) ? $scope.skip_tags.join() : "";
|
data.skip_tags = (Array.isArray($scope.skip_tags)) ? $scope.skip_tags.join() : "";
|
||||||
if ($scope.selectedCredentials && $scope.selectedCredentials
|
if ($scope.selectedCredentials && $scope.selectedCredentials
|
||||||
.machine && $scope.selectedCredentials
|
.machine && $scope.selectedCredentials
|
||||||
.machine) {
|
.machine.id) {
|
||||||
data.credential = $scope.selectedCredentials
|
data.credential = $scope.selectedCredentials
|
||||||
.machine.id;
|
.machine.id;
|
||||||
} else {
|
} else {
|
||||||
data.credential = null;
|
data.credential = null;
|
||||||
}
|
}
|
||||||
|
if ($scope.selectedCredentials && $scope.selectedCredentials
|
||||||
|
.vault && $scope.selectedCredentials
|
||||||
|
.vault.id) {
|
||||||
|
data.vault_credential = $scope.selectedCredentials
|
||||||
|
.vault.id;
|
||||||
|
}
|
||||||
data.extra_vars = ToJSON($scope.parseType,
|
data.extra_vars = ToJSON($scope.parseType,
|
||||||
$scope.variables, true);
|
$scope.variables, true);
|
||||||
|
|
||||||
|
@ -83,6 +83,21 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
$scope.credentialTypeOptions);
|
$scope.credentialTypeOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let updateVaultCredentialList = function() {
|
||||||
|
$scope.credentials.forEach(cred => {
|
||||||
|
if (cred.credential_type === 3) {
|
||||||
|
cred.checked = ($scope.selectedCredentials
|
||||||
|
.vault !== null &&
|
||||||
|
cred.id === $scope.selectedCredentials
|
||||||
|
.vault.id) ? 1 : 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$scope.credTags = MultiCredentialService
|
||||||
|
.updateCredentialTags($scope.selectedCredentials,
|
||||||
|
$scope.credentialTypeOptions);
|
||||||
|
};
|
||||||
|
|
||||||
let uncheckAllCredentials = function() {
|
let uncheckAllCredentials = function() {
|
||||||
$scope.credentials.forEach(cred => {
|
$scope.credentials.forEach(cred => {
|
||||||
cred.checked = 0;
|
cred.checked = 0;
|
||||||
@ -156,6 +171,16 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$scope.$watch('selectedCredentials.vault', () => {
|
||||||
|
if($scope.selectedCredentials &&
|
||||||
|
$scope.selectedCredentials.vault &&
|
||||||
|
parseInt($scope.credentialKind) === 3) {
|
||||||
|
updateVaultCredentialList();
|
||||||
|
} else {
|
||||||
|
uncheckAllCredentials();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$scope.$watchGroup(['credentials',
|
$scope.$watchGroup(['credentials',
|
||||||
'selectedCredentials.machine'], () => {
|
'selectedCredentials.machine'], () => {
|
||||||
if($scope.credentials &&
|
if($scope.credentials &&
|
||||||
@ -164,6 +189,10 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
$scope.selectedCredentials.machine &&
|
$scope.selectedCredentials.machine &&
|
||||||
parseInt($scope.credentialKind) === 1) {
|
parseInt($scope.credentialKind) === 1) {
|
||||||
updateMachineCredentialList();
|
updateMachineCredentialList();
|
||||||
|
} else if($scope.selectedCredentials &&
|
||||||
|
$scope.selectedCredentials.vault &&
|
||||||
|
parseInt($scope.credentialKind) === 3) {
|
||||||
|
updateVaultCredentialList();
|
||||||
} else if($scope.selectedCredentials &&
|
} else if($scope.selectedCredentials &&
|
||||||
$scope.selectedCredentials.extra &&
|
$scope.selectedCredentials.extra &&
|
||||||
$scope.selectedCredentials.extra.length > 0 &&
|
$scope.selectedCredentials.extra.length > 0 &&
|
||||||
@ -189,6 +218,14 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
} else {
|
} else {
|
||||||
$scope.selectedCredentials.machine = _.cloneDeep(selectedRow);
|
$scope.selectedCredentials.machine = _.cloneDeep(selectedRow);
|
||||||
}
|
}
|
||||||
|
}else if(parseInt($scope.credentialKind) === 3) {
|
||||||
|
if($scope.selectedCredentials &&
|
||||||
|
$scope.selectedCredentials.vault &&
|
||||||
|
$scope.selectedCredentials.vault.id === selectedRow.id) {
|
||||||
|
$scope.selectedCredentials.vault = null;
|
||||||
|
} else {
|
||||||
|
$scope.selectedCredentials.vault = _.cloneDeep(selectedRow);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let rowDeselected = false;
|
let rowDeselected = false;
|
||||||
for (let i = $scope.selectedCredentials.extra.length - 1; i >= 0; i--) {
|
for (let i = $scope.selectedCredentials.extra.length - 1; i >= 0; i--) {
|
||||||
@ -211,6 +248,7 @@ export default ['templateUrl', 'Rest', 'GetBasePath', 'generateList', '$compile'
|
|||||||
$scope.selectedCredentialsDirty = function() {
|
$scope.selectedCredentialsDirty = function() {
|
||||||
if ($scope.originalSelectedCredentials) {
|
if ($scope.originalSelectedCredentials) {
|
||||||
return !($scope.originalSelectedCredentials.machine === null &&
|
return !($scope.originalSelectedCredentials.machine === null &&
|
||||||
|
$scope.originalSelectedCredentials.vault === null &&
|
||||||
$scope.originalSelectedCredentials.extra.length === 0) &&
|
$scope.originalSelectedCredentials.extra.length === 0) &&
|
||||||
!_.isEqual($scope.selectedCredentials,
|
!_.isEqual($scope.selectedCredentials,
|
||||||
$scope.originalSelectedCredentials);
|
$scope.originalSelectedCredentials);
|
||||||
|
@ -84,7 +84,7 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
|
|||||||
data.results.forEach((credentialType => {
|
data.results.forEach((credentialType => {
|
||||||
credential_types[credentialType.id] = credentialType;
|
credential_types[credentialType.id] = credentialType;
|
||||||
if(credentialType.kind
|
if(credentialType.kind
|
||||||
.match(/^(machine|cloud|net|ssh)$/)) {
|
.match(/^(machine|cloud|net|ssh|vault)$/)) {
|
||||||
credentialTypeOptions.push({
|
credentialTypeOptions.push({
|
||||||
name: credentialType.name,
|
name: credentialType.name,
|
||||||
value: credentialType.id
|
value: credentialType.id
|
||||||
@ -111,6 +111,7 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
|
|||||||
val.updateCredentialTags = (creds, typeOpts) => {
|
val.updateCredentialTags = (creds, typeOpts) => {
|
||||||
let machineCred = [];
|
let machineCred = [];
|
||||||
let extraCreds = [];
|
let extraCreds = [];
|
||||||
|
let vaultCred = [];
|
||||||
|
|
||||||
if (creds.machine) {
|
if (creds.machine) {
|
||||||
let mach = creds.machine;
|
let mach = creds.machine;
|
||||||
@ -118,6 +119,12 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
|
|||||||
machineCred = [mach];
|
machineCred = [mach];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (creds.vault) {
|
||||||
|
let vault = creds.vault;
|
||||||
|
vault.postType = "vault";
|
||||||
|
vaultCred = [vault];
|
||||||
|
}
|
||||||
|
|
||||||
if (creds.extra) {
|
if (creds.extra) {
|
||||||
extraCreds = creds.extra
|
extraCreds = creds.extra
|
||||||
.map((cred) => {
|
.map((cred) => {
|
||||||
@ -127,7 +134,7 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return machineCred.concat(extraCreds).map(cred => ({
|
return machineCred.concat(extraCreds).concat(vaultCred).map(cred => ({
|
||||||
name: cred.name,
|
name: cred.name,
|
||||||
id: cred.id,
|
id: cred.id,
|
||||||
postType: cred.postType,
|
postType: cred.postType,
|
||||||
@ -145,6 +152,8 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
|
|||||||
if (credToRemove === cred.id) {
|
if (credToRemove === cred.id) {
|
||||||
if (cred.postType === 'machine') {
|
if (cred.postType === 'machine') {
|
||||||
structuredObj[cred.postType] = null;
|
structuredObj[cred.postType] = null;
|
||||||
|
} else if (cred.postType === 'vault') {
|
||||||
|
structuredObj[cred.postType] = null;
|
||||||
} else {
|
} else {
|
||||||
structuredObj[cred.postType] = structuredObj[cred.postType]
|
structuredObj[cred.postType] = structuredObj[cred.postType]
|
||||||
.filter(cred => cred
|
.filter(cred => cred
|
||||||
@ -163,6 +172,7 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
|
|||||||
val.loadCredentials = (data) => {
|
val.loadCredentials = (data) => {
|
||||||
let selectedCredentials = {
|
let selectedCredentials = {
|
||||||
machine: null,
|
machine: null,
|
||||||
|
vault: null,
|
||||||
extra: []
|
extra: []
|
||||||
}, credTypes, credTypeOptions, credTags;
|
}, credTypes, credTypeOptions, credTags;
|
||||||
|
|
||||||
@ -187,6 +197,24 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.related.vault_credential) {
|
||||||
|
Rest.setUrl(data.related.vault_credential);
|
||||||
|
credDefers.push(Rest.get()
|
||||||
|
.then(({data}) => {
|
||||||
|
selectedCredentials.vault = data;
|
||||||
|
})
|
||||||
|
.catch(({data, status}) => {
|
||||||
|
ProcessErrors(
|
||||||
|
null, data, status, null,
|
||||||
|
{
|
||||||
|
hdr: 'Error!',
|
||||||
|
msg: 'Failed to get machine credential. ' +
|
||||||
|
'Get returned status: ' +
|
||||||
|
status
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
// get extra credentials
|
// get extra credentials
|
||||||
if (data.related.extra_credentials) {
|
if (data.related.extra_credentials) {
|
||||||
Rest.setUrl(data.related.extra_credentials);
|
Rest.setUrl(data.related.extra_credentials);
|
||||||
|
Loading…
Reference in New Issue
Block a user