mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-05 16:01:50 -05:00
add api for testing credential plugins
This commit is contained in:
@@ -4,7 +4,9 @@ function AddCredentialsController (
|
||||
$scope,
|
||||
strings,
|
||||
componentsStrings,
|
||||
ConfigService
|
||||
ConfigService,
|
||||
ngToast,
|
||||
$filter
|
||||
) {
|
||||
const vm = this || {};
|
||||
|
||||
@@ -36,6 +38,7 @@ function AddCredentialsController (
|
||||
vm.form.credential_type._route = 'credentials.add.credentialType';
|
||||
vm.form.credential_type._model = credentialType;
|
||||
vm.form.credential_type._placeholder = strings.get('inputs.CREDENTIAL_TYPE_PLACEHOLDER');
|
||||
vm.isTestable = credentialType.get('kind') === 'external';
|
||||
|
||||
const gceFileInputSchema = {
|
||||
id: 'gce_service_account_key',
|
||||
@@ -62,6 +65,8 @@ function AddCredentialsController (
|
||||
become._choices = Array.from(apiConfig.become_methods, method => method[0]);
|
||||
}
|
||||
|
||||
vm.isTestable = credentialType.get('kind') === 'external';
|
||||
|
||||
return fields;
|
||||
},
|
||||
_source: vm.form.credential_type,
|
||||
@@ -69,6 +74,45 @@ function AddCredentialsController (
|
||||
_key: 'inputs'
|
||||
};
|
||||
|
||||
vm.form.secondary = ({ inputs }) => {
|
||||
const name = $filter('sanitize')(credentialType.get('name'));
|
||||
const endpoint = `${credentialType.get('id')}/test/`;
|
||||
|
||||
return credentialType.http.post({ url: endpoint, data: { inputs }, replace: false })
|
||||
.then(() => {
|
||||
ngToast.success({
|
||||
content: `
|
||||
<div class="Toast-wrapper">
|
||||
<div class="Toast-icon">
|
||||
<i class="fa fa-check-circle Toast-successIcon"></i>
|
||||
</div>
|
||||
<div>
|
||||
<b>${name}:</b> ${strings.get('edit.TEST_PASSED')}
|
||||
</div>
|
||||
</div>`,
|
||||
dismissButton: false,
|
||||
dismissOnTimeout: true
|
||||
});
|
||||
})
|
||||
.catch(({ data }) => {
|
||||
const msg = data.inputs ? `${$filter('sanitize')(data.inputs)}` : strings.get('edit.TEST_FAILED');
|
||||
|
||||
ngToast.danger({
|
||||
content: `
|
||||
<div class="Toast-wrapper">
|
||||
<div class="Toast-icon">
|
||||
<i class="fa fa-exclamation-triangle Toast-successIcon"></i>
|
||||
</div>
|
||||
<div>
|
||||
<b>${name}:</b> ${msg}
|
||||
</div>
|
||||
</div>`,
|
||||
dismissButton: false,
|
||||
dismissOnTimeout: true
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
vm.form.save = data => {
|
||||
data.user = me.get('id');
|
||||
|
||||
@@ -149,7 +193,9 @@ AddCredentialsController.$inject = [
|
||||
'$scope',
|
||||
'CredentialsStrings',
|
||||
'ComponentsStrings',
|
||||
'ConfigService'
|
||||
'ConfigService',
|
||||
'ngToast',
|
||||
'$filter'
|
||||
];
|
||||
|
||||
export default AddCredentialsController;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
</at-input-group>
|
||||
|
||||
<at-action-group col="12" pos="right">
|
||||
<at-form-action type="secondary" ng-if="vm.isTestable"></at-form-action>
|
||||
<at-form-action type="cancel" to="credentials"></at-form-action>
|
||||
<at-form-action type="save"></at-form-action>
|
||||
</at-action-group>
|
||||
|
||||
@@ -26,6 +26,11 @@ function CredentialsStrings (BaseString) {
|
||||
PANEL_TITLE: t.s('NEW CREDENTIAL')
|
||||
};
|
||||
|
||||
ns.edit = {
|
||||
TEST_PASSED: t.s('Test passed.'),
|
||||
TEST_FAILED: t.s('Test failed.')
|
||||
};
|
||||
|
||||
ns.permissions = {
|
||||
TITLE: t.s('CREDENTIALS PERMISSIONS')
|
||||
};
|
||||
|
||||
@@ -4,7 +4,10 @@ function EditCredentialsController (
|
||||
$scope,
|
||||
strings,
|
||||
componentsStrings,
|
||||
ConfigService
|
||||
ConfigService,
|
||||
ngToast,
|
||||
Wait,
|
||||
$filter,
|
||||
) {
|
||||
const vm = this || {};
|
||||
|
||||
@@ -83,6 +86,7 @@ function EditCredentialsController (
|
||||
vm.form.credential_type._value = credentialType.get('id');
|
||||
vm.form.credential_type._displayValue = credentialType.get('name');
|
||||
vm.form.credential_type._placeholder = strings.get('inputs.CREDENTIAL_TYPE_PLACEHOLDER');
|
||||
vm.isTestable = (isEditable && credentialType.get('kind') === 'external');
|
||||
|
||||
const gceFileInputSchema = {
|
||||
id: 'gce_service_account_key',
|
||||
@@ -124,6 +128,7 @@ function EditCredentialsController (
|
||||
}
|
||||
}
|
||||
}
|
||||
vm.isTestable = (isEditable && credentialType.get('kind') === 'external');
|
||||
|
||||
return fields;
|
||||
},
|
||||
@@ -132,6 +137,45 @@ function EditCredentialsController (
|
||||
_key: 'inputs'
|
||||
};
|
||||
|
||||
vm.form.secondary = ({ inputs }) => {
|
||||
const name = $filter('sanitize')(credentialType.get('name'));
|
||||
const endpoint = `${credential.get('id')}/test/`;
|
||||
|
||||
return credential.http.post({ url: endpoint, data: { inputs }, replace: false })
|
||||
.then(() => {
|
||||
ngToast.success({
|
||||
content: `
|
||||
<div class="Toast-wrapper">
|
||||
<div class="Toast-icon">
|
||||
<i class="fa fa-check-circle Toast-successIcon"></i>
|
||||
</div>
|
||||
<div>
|
||||
<b>${name}:</b> ${strings.get('edit.TEST_PASSED')}
|
||||
</div>
|
||||
</div>`,
|
||||
dismissButton: false,
|
||||
dismissOnTimeout: true
|
||||
});
|
||||
})
|
||||
.catch(({ data }) => {
|
||||
const msg = data.inputs ? `${$filter('sanitize')(data.inputs)}` : strings.get('edit.TEST_FAILED');
|
||||
|
||||
ngToast.danger({
|
||||
content: `
|
||||
<div class="Toast-wrapper">
|
||||
<div class="Toast-icon">
|
||||
<i class="fa fa-exclamation-triangle Toast-successIcon"></i>
|
||||
</div>
|
||||
<div>
|
||||
<b>${name}:</b> ${msg}
|
||||
</div>
|
||||
</div>`,
|
||||
dismissButton: false,
|
||||
dismissOnTimeout: true
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* If a credential's `credential_type` is changed while editing, the inputs associated with
|
||||
* the old type need to be cleared before saving the inputs associated with the new type.
|
||||
@@ -210,7 +254,10 @@ EditCredentialsController.$inject = [
|
||||
'$scope',
|
||||
'CredentialsStrings',
|
||||
'ComponentsStrings',
|
||||
'ConfigService'
|
||||
'ConfigService',
|
||||
'ngToast',
|
||||
'Wait',
|
||||
'$filter',
|
||||
];
|
||||
|
||||
export default EditCredentialsController;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.at-ActionGroup {
|
||||
margin-top: @at-margin-panel;
|
||||
|
||||
button:last-child {
|
||||
margin-left: @at-margin-panel-inset;
|
||||
button {
|
||||
margin-left: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ function atFormActionController ($state, strings) {
|
||||
case 'save':
|
||||
vm.setSaveDefaults();
|
||||
break;
|
||||
case 'secondary':
|
||||
vm.setSecondaryDefaults();
|
||||
break;
|
||||
default:
|
||||
vm.setCustomDefaults();
|
||||
}
|
||||
@@ -43,6 +46,13 @@ function atFormActionController ($state, strings) {
|
||||
scope.color = 'success';
|
||||
scope.action = () => { form.submit(); };
|
||||
};
|
||||
|
||||
vm.setSecondaryDefaults = () => {
|
||||
scope.text = strings.get('TEST');
|
||||
scope.fill = '';
|
||||
scope.color = 'info';
|
||||
scope.action = () => { form.submitSecondary(); };
|
||||
};
|
||||
}
|
||||
|
||||
atFormActionController.$inject = ['$state', 'ComponentsStrings'];
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<button class="btn at-Button{{ fill }}--{{ color }}"
|
||||
ng-disabled="type !== 'cancel' && (form.disabled || (type === 'save' && !form.isValid))"
|
||||
ng-disabled="type !== 'cancel' && (form.disabled
|
||||
|| (type === 'save' && !form.isValid))
|
||||
|| (type === 'secondary' && !form.isValid)"
|
||||
ng-click="action()">
|
||||
{{::text}}
|
||||
</button>
|
||||
|
||||
@@ -62,6 +62,40 @@ function AtFormController (eventService, strings) {
|
||||
scope.$apply(vm.submit);
|
||||
};
|
||||
|
||||
vm.getSubmitData = () => vm.components
|
||||
.filter(component => component.category === 'input')
|
||||
.reduce((values, component) => {
|
||||
if (component.state._value === undefined) {
|
||||
return values;
|
||||
}
|
||||
|
||||
if (component.state._format === 'selectFromOptions') {
|
||||
values[component.state.id] = component.state._value[0];
|
||||
} else if (component.state._key && typeof component.state._value === 'object') {
|
||||
values[component.state.id] = component.state._value[component.state._key];
|
||||
} else if (component.state._group) {
|
||||
values[component.state._key] = values[component.state._key] || {};
|
||||
values[component.state._key][component.state.id] = component.state._value;
|
||||
} else {
|
||||
values[component.state.id] = component.state._value;
|
||||
}
|
||||
|
||||
return values;
|
||||
}, {});
|
||||
|
||||
vm.submitSecondary = () => {
|
||||
if (!vm.state.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
vm.state.disabled = true;
|
||||
|
||||
const data = vm.getSubmitData();
|
||||
|
||||
scope.state.secondary(data)
|
||||
.finally(() => { vm.state.disabled = false; });
|
||||
};
|
||||
|
||||
vm.submit = () => {
|
||||
if (!vm.state.isValid) {
|
||||
return;
|
||||
@@ -69,26 +103,7 @@ function AtFormController (eventService, strings) {
|
||||
|
||||
vm.state.disabled = true;
|
||||
|
||||
const data = vm.components
|
||||
.filter(component => component.category === 'input')
|
||||
.reduce((values, component) => {
|
||||
if (component.state._value === undefined) {
|
||||
return values;
|
||||
}
|
||||
|
||||
if (component.state._format === 'selectFromOptions') {
|
||||
values[component.state.id] = component.state._value[0];
|
||||
} else if (component.state._key && typeof component.state._value === 'object') {
|
||||
values[component.state.id] = component.state._value[component.state._key];
|
||||
} else if (component.state._group) {
|
||||
values[component.state._key] = values[component.state._key] || {};
|
||||
values[component.state._key][component.state.id] = component.state._value;
|
||||
} else {
|
||||
values[component.state.id] = component.state._value;
|
||||
}
|
||||
|
||||
return values;
|
||||
}, {});
|
||||
const data = vm.getSubmitData();
|
||||
|
||||
scope.state.save(data)
|
||||
.then(scope.state.onSaveSuccess)
|
||||
|
||||
@@ -153,17 +153,22 @@ function httpPost (config = {}) {
|
||||
const req = {
|
||||
method: 'POST',
|
||||
url: this.path,
|
||||
data: config.data
|
||||
data: config.data,
|
||||
};
|
||||
|
||||
if (config.url) {
|
||||
req.url = `${this.path}${config.url}`;
|
||||
}
|
||||
|
||||
if (!('replace' in config)) {
|
||||
config.replace = true;
|
||||
}
|
||||
|
||||
return $http(req)
|
||||
.then(res => {
|
||||
this.model.GET = res.data;
|
||||
|
||||
if (config.replace) {
|
||||
this.model.GET = res.data;
|
||||
}
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ function BaseStringService (namespace) {
|
||||
this.COPY = t.s('COPY');
|
||||
this.YES = t.s('YES');
|
||||
this.CLOSE = t.s('CLOSE');
|
||||
this.TEST = t.s('TEST');
|
||||
this.SUCCESSFUL_CREATION = resource => t.s('{{ resource }} successfully created', { resource: $filter('sanitize')(resource) });
|
||||
|
||||
this.deleteResource = {
|
||||
|
||||
Reference in New Issue
Block a user