Skip to content

Commit

Permalink
updates kubernetes check env vars endpoint (#18588)
Browse files Browse the repository at this point in the history
  • Loading branch information
zofskeez authored Jan 3, 2023
1 parent 423132d commit 68d0bfe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
7 changes: 3 additions & 4 deletions ui/app/adapters/kubernetes/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { encodePath } from 'vault/utils/path-encoding-helpers';
export default class KubernetesConfigAdapter extends ApplicationAdapter {
namespace = 'v1';

getURL(backend) {
return `${this.buildURL()}/${encodePath(backend)}/config`;
getURL(backend, path = 'config') {
return `${this.buildURL()}/${encodePath(backend)}/${path}`;
}
urlForUpdateRecord(name, modelName, snapshot) {
return this.getURL(snapshot.attr('backend'));
Expand Down Expand Up @@ -33,7 +33,6 @@ export default class KubernetesConfigAdapter extends ApplicationAdapter {
return this.ajax(url, 'POST', { data }).then(() => data);
}
checkConfigVars(backend) {
// this endpoint has yet to be created so this url is a mock for now and wired up in the mirage handler
return this.ajax(`${this.getURL(backend)}/vars`, 'GET');
return this.ajax(`${this.getURL(backend, 'check')}`, 'GET');
}
}
16 changes: 9 additions & 7 deletions ui/mirage/handlers/kubernetes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Response } from 'miragejs';

// yet to be defined endpoint
// exporting to use in tests in case it changes
export const configVarUri = '/:path/config/vars';

export default function (server) {
const getRecord = (schema, req, dbKey) => {
const { path, name } = req.params;
Expand Down Expand Up @@ -41,10 +37,16 @@ export default function (server) {
server.delete('/:path/config', (schema, req) => {
return deleteRecord(schema, req, 'kubernetesConfigs');
});
// to be defined endpoint for checking for environment variables necessary for inferred config
server.get(configVarUri, () => {
// endpoint for checking for environment variables necessary for inferred config
server.get('/:path/check', () => {
const response = {};
const status = Math.random() > 0.5 ? 204 : 404;
return new Response(status, {});
if (status === 404) {
response.errors = [
'Missing environment variables: KUBERNETES_SERVICE_HOST, KUBERNETES_SERVICE_PORT_HTTPS',
];
}
return new Response(status, response);
});
server.get('/:path/roles', (schema) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { setupEngine } from 'ember-engines/test-support';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { render, click, waitUntil, find, fillIn } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { configVarUri } from '../../../../../mirage/handlers/kubernetes';
import { Response } from 'miragejs';
import sinon from 'sinon';

Expand Down Expand Up @@ -58,7 +57,7 @@ module('Integration | Component | kubernetes | Page::Configure', function (hooks
assert.expect(8);

let status = 404;
this.server.get(configVarUri, () => {
this.server.get('/:path/check', () => {
assert.ok(
waitUntil(() => find('[data-test-config] button').disabled),
'Button is disabled while request is in flight'
Expand Down

0 comments on commit 68d0bfe

Please sign in to comment.