grab-api-sentinel-mocks/main.js
2023-01-02 14:54:45 -08:00

31 lines
1.1 KiB
JavaScript

import { normalized_config } from "./normalize-config.js";
import { get_run_details, create_plan_export } from "./tfc-api-functions.mjs";
const my_config = await normalized_config;
// TODO: Split all this run verification clutter out into a separate module
// verify that a run_id was provided to the program
const runid_provided = run_id => {
return (run_id ? true : false);
}
// Add negation function for readability (no 'unless' in js)
const runidNotProvided = run_id => {
return !runid_provided(run_id);
}
// Check for prefix indicating a valid run id
const startsWithRun = run_id => {
return run_id.startsWith("run-");
}
if(runidNotProvided(my_config.run_id) || !startsWithRun(my_config.run_id)){
throw new Error("A valid RunID must be provided. Please check that the supplied runID is valid");
}
// TODO: Add error handling for `data: { errors: [ { status: '404', title: 'not found' } ] }`
const run_details = await get_run_details(my_config.base_url, process.argv.slice(2), my_config.token);
const plan_id = run_details.data.data.relationships.plan.data.id;
console.log(await create_plan_export(my_config.base_url, plan_id, my_config.token));