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

Set up endpoint for razeedeploy-job #193

Merged
merged 3 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typings/

### Local ignores
dev-envvars.sh
dev/

# vscode settings
.vscode
56 changes: 26 additions & 30 deletions app/routes/install/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,25 @@ const getBunyanConfig = require('../../utils/bunyan.js').getBunyanConfig;

router.use(ebl(getBunyanConfig('/api/install')));

router.get('/inventory', asyncHandler(async(req, res, next) => {
const orgKey = req.orgKey;
var razeeapiUrl = `${req.protocol}://${req.get('host')}/api/v2`;
const wk_url = 'https://github.com/razee-io/Watch-keeper/releases/download/0.2.0/resource.yaml';

router.get('/razeedeploy-job', asyncHandler(async (req, res, next) => {
let args = req.query.args ? req.query.args : [];
let args_array = Array.isArray(args) ? args : [args];
args_array.push(`--razeedash-url='${req.protocol}://${req.get('host')}/api/v2'`);
args_array.push(`--razeedash-org-key=${req.query.orgKey}`);
args_array = JSON.stringify(args_array);

try {
const inventory = await readFile(`${__dirname}/inventory.yaml`, 'utf8');
const wk = await request.get(wk_url);
const rdd_job = await request.get('https://github.com/razee-io/razeedeploy-delta/releases/latest/download/job.yaml');
const view = {
RAZEEDASH_URL: razeeapiUrl,
RAZEEDASH_ORG_KEY: Buffer.from(orgKey).toString('base64'),
WATCH_KEEPER: wk
NAMESPACE: req.query.namespace || 'razeedeploy',
COMMAND: req.query.command || 'install',
ARGS_ARRAY: args_array
};
const configYaml = Mustache.render(inventory, view);
const m_esc = Mustache.escape;
Mustache.escape = (text) => { return text; };
const configYaml = Mustache.render(rdd_job, view);
Mustache.escape = m_esc;
res.setHeader('content-type', 'application/yaml');
return res.status(200).send(configYaml);
} catch (e) {
Expand All @@ -46,21 +52,21 @@ router.get('/inventory', asyncHandler(async(req, res, next) => {
}
}));

// Delete once we fully sunset the kapitan name
router.get('/kapitan', asyncHandler(async (req, res, next) => {
// =============================================================================
// DEPRICATED ROUTES:
// These routes are being depricated. please use '/job'
// =============================================================================
router.get('/inventory', asyncHandler(async (req, res, next) => {
const orgKey = req.orgKey;
var razeeapiUrl = `${req.protocol}://${req.get('host')}/api/v2`;
const wk_url = 'https://github.com/razee-io/Watch-keeper/releases/download/0.2.0/resource.yaml';
const kptn_url = 'https://github.com/razee-io/razeedeploy-delta/releases/latest/download/resource.yaml';
try {
const inventory = await readFile(`${__dirname}/razeedeploy.yaml`, 'utf8');
const inventory = await readFile(`${__dirname}/inventory.yaml`, 'utf8');
const wk = await request.get(wk_url);
const kptn = await request.get(kptn_url);
const view = {
RAZEEDASH_URL: razeeapiUrl,
RAZEEDASH_ORG_KEY: Buffer.from(orgKey).toString('base64'),
WATCH_KEEPER: wk,
RAZEEDEPLOY: kptn
WATCH_KEEPER: wk
};
const configYaml = Mustache.render(inventory, view);
res.setHeader('content-type', 'application/yaml');
Expand Down Expand Up @@ -119,19 +125,6 @@ router.get('/cluster', asyncHandler(async (req, res, next) => {
}
}));

//Remove once we fully sunset the kapitan name
router.get('/kapitan/:component', asyncHandler(async (req, res, next) => {
const kptn_url = `https://github.com/razee-io/${req.params.component}/releases/latest/download/resource.yaml`;
try {
const kptn = await request.get(kptn_url);
res.setHeader('content-type', 'application/yaml');
return res.status(200).send(kptn);
} catch (e) {
req.log.error(e);
next(e);
}
}));

router.get('/razeedeploy/:component', asyncHandler(async (req, res, next) => {
const kptn_url = `https://github.com/razee-io/${req.params.component}/releases/latest/download/resource.yaml`;
try {
Expand All @@ -143,6 +136,9 @@ router.get('/razeedeploy/:component', asyncHandler(async (req, res, next) => {
next(e);
}
}));
// =============================================================================
// DEPRICATED ROUTES
// =============================================================================


module.exports = router;