Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional api-server prefix #1126

Merged
merged 4 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/api-server/config/main/config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ config.dataSourceService = {
prefix: 'api/v1'
};

config.ingressPrefix = process.env.INGRESS_PREFIX || '';

config.debugUrl = {
path: path.join(process.env.INGRESS_PREFIX || '', 'hkube/debug')
path: path.join(config.ingressPrefix, 'hkube/debug')
};

config.addDefaultAlgorithms = process.env.ADD_DEFAULT_ALGORITHMS || true;
Expand All @@ -51,7 +53,7 @@ config.swagger = {
protocol: secured ? 'https' : 'http',
host: process.env.BASE_URL_HOST || 'localhost',
port: process.env.BASE_URL_PORT || config.rest.port,
path: (process.env.BASE_URL_PATH || '')
path: process.env.BASE_URL_PATH? path.join(config.ingressPrefix, process.env.BASE_URL_PATH): config.ingressPrefix
};

config.jobs = {
Expand Down
17 changes: 17 additions & 0 deletions core/api-server/tests/algorithms-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { expect } = require('chai');
const fse = require('fs-extra');
const nock = require('nock');
const HttpStatus = require('http-status-codes');
const pathLib = require('path');
const merge = require('lodash.merge');
const { uid: uuid } = require('@hkube/uid');
const stateManager = require('../lib/state/state-manager');
Expand All @@ -26,6 +27,7 @@ describe('Store/Algorithms', () => {
restUrl = global.testParams.restUrl;
restPath = `${restUrl}/store/algorithms`;
applyPath = `${restPath}/apply`;
debugRestUrl = `${restPath}/debug`;
versionsPath = `${restUrl}/versions/algorithms`;
nock(baseApi).persist().get(emptyGit).query(true).reply(HttpStatus.BAD_REQUEST, 'Git Repository is empty');
nock(baseApi).persist().get(fullGit).query(true).reply(HttpStatus.OK, commit.data);
Expand Down Expand Up @@ -1851,4 +1853,19 @@ describe('Store/Algorithms', () => {
expect(response.body.algorithmImage).to.not.eql(body.algorithmImage);
});
});
describe('/store/algorithms/debug POST', () => {
it('should succeed to set debugUrl', async () => {
const body = {
name: uuid(),
}
const options = {
uri: debugRestUrl,
body
};
const response = await request(options);
const { version, created, modified, data, ...algorithm } = response.body;
expect(response.response.statusCode).to.equal(HttpStatus.CREATED);
expect(data.path).to.eql(pathLib.join(process.env.INGRESS_PREFIX || '', 'hkube', 'debug', body.name));
});
})
});
37 changes: 37 additions & 0 deletions core/api-server/tests/configTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { expect } = require('chai');
const configIt = require('@hkube/config');
const path = require('path');
let envSave={};
describe('config',()=>{
beforeEach(() => {
envSave = {...process.env};
delete require.cache[require.resolve(path.resolve('config/main/config.base.js'))];
});
afterEach(()=>{
process.env = envSave
})
it('empty env', () => {
const { main } = configIt.load();
expect(main.debugUrl.path).to.eql('hkube/debug')
expect(main.swagger.path).to.eql('')
});
it('ingress prefix env', () => {
process.env.INGRESS_PREFIX='/foo'
const { main } = configIt.load();
expect(main.debugUrl.path).to.eql('/foo/hkube/debug')
expect(main.swagger.path).to.eql('/foo')
});
it('base path env', () => {
process.env.BASE_URL_PATH='/hkube/api-server'
const { main } = configIt.load();
expect(main.debugUrl.path).to.eql('hkube/debug')
expect(main.swagger.path).to.eql('/hkube/api-server')
});
it('ingress and base path env', () => {
process.env.BASE_URL_PATH='/hkube/api-server'
process.env.INGRESS_PREFIX='/foo'
const { main } = configIt.load();
expect(main.debugUrl.path).to.eql('/foo/hkube/debug')
expect(main.swagger.path).to.eql('/foo/hkube/api-server')
});
})