Change to using a single input
This commit is contained in:
parent
1d92118146
commit
e9b47b1898
37 changed files with 173 additions and 112 deletions
34
lib/config-utils.js
generated
34
lib/config-utils.js
generated
|
|
@ -883,7 +883,7 @@ function dbLocationOrDefault(dbLocation, tempDir) {
|
|||
* This will parse the config from the user input if present, or generate
|
||||
* a default config. The parsed config is then stored to a known location.
|
||||
*/
|
||||
async function initConfig(languagesInput, queriesInput, packsInput, configFile, dbLocation, trapCachingEnabled, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, codeQL, workspacePath, gitHubVersion, apiDetails, featureFlags, logger) {
|
||||
async function initConfig(languagesInput, queriesInput, packsInput, registriesInput, configFile, dbLocation, trapCachingEnabled, debugMode, debugArtifactName, debugDatabaseName, repository, tempDir, codeQL, workspacePath, gitHubVersion, apiDetails, featureFlags, logger) {
|
||||
var _a, _b, _c;
|
||||
let config;
|
||||
// If no config file was provided create an empty one
|
||||
|
|
@ -909,13 +909,22 @@ async function initConfig(languagesInput, queriesInput, packsInput, configFile,
|
|||
// happen in the CLI during the `database init` command, so no need
|
||||
// to download them here.
|
||||
if (!(await (0, util_1.useCodeScanningConfigInCli)(codeQL))) {
|
||||
await downloadPacks(codeQL, config.languages, config.packs, config.originalUserInput.registries, apiDetails, config.tempDir, logger);
|
||||
const registries = parseRegistries(registriesInput);
|
||||
await downloadPacks(codeQL, config.languages, config.packs, registries, apiDetails, config.tempDir, logger);
|
||||
}
|
||||
// Save the config so we can easily access it again in the future
|
||||
await saveConfig(config, logger);
|
||||
return config;
|
||||
}
|
||||
exports.initConfig = initConfig;
|
||||
function parseRegistries(registriesInput) {
|
||||
try {
|
||||
return registriesInput ? JSON.parse(registriesInput) : undefined;
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(`Invalid registries input. Must be a JSON string, but got: ${e instanceof Error ? e.message : String(e)}`);
|
||||
}
|
||||
}
|
||||
function isLocal(configPath) {
|
||||
// If the path starts with ./, look locally
|
||||
if (configPath.indexOf("./") === 0) {
|
||||
|
|
@ -997,17 +1006,19 @@ async function getConfig(tempDir, logger) {
|
|||
exports.getConfig = getConfig;
|
||||
async function downloadPacks(codeQL, languages, packs, registries, apiDetails, tmpDir, logger) {
|
||||
let qlconfigFile;
|
||||
let registriesAuthTokens;
|
||||
if (registries) {
|
||||
// generate a qlconfig.yml file to hold the registry configs.
|
||||
const qlconfig = {
|
||||
registries,
|
||||
};
|
||||
const qlconfig = createRegistriesBlock(registries);
|
||||
qlconfigFile = path.join(tmpDir, "qlconfig.yml");
|
||||
fs.writeFileSync(qlconfigFile, yaml.dump(qlconfig), "utf8");
|
||||
registriesAuthTokens = registries
|
||||
.map((registry) => `${registry.url}=${registry.token}`)
|
||||
.join(",");
|
||||
}
|
||||
await wrapEnvironment({
|
||||
GITHUB_TOKEN: apiDetails.auth,
|
||||
CODEQL_REGISTRIES_AUTH: apiDetails.registriesAuthTokens,
|
||||
CODEQL_REGISTRIES_AUTH: registriesAuthTokens,
|
||||
}, async () => {
|
||||
let numPacksDownloaded = 0;
|
||||
logger.startGroup("Downloading packs");
|
||||
|
|
@ -1032,6 +1043,17 @@ async function downloadPacks(codeQL, languages, packs, registries, apiDetails, t
|
|||
});
|
||||
}
|
||||
exports.downloadPacks = downloadPacks;
|
||||
function createRegistriesBlock(registries) {
|
||||
// be sure to remove the `token` field from the registry before writing it to disk.
|
||||
const safeRegistries = registries.map((registry) => ({
|
||||
url: registry.url,
|
||||
packages: registry.packages,
|
||||
}));
|
||||
const qlconfig = {
|
||||
registries: safeRegistries,
|
||||
};
|
||||
return qlconfig;
|
||||
}
|
||||
async function wrapEnvironment(env, operation) {
|
||||
// Remember the original env
|
||||
const oldEnv = { ...process.env };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue