Skip to content

Commit

Permalink
feat(bump): add ability to edit the imposter specification file refer…
Browse files Browse the repository at this point in the history
…ence on bump script of main plugin
  • Loading branch information
Desvelao committed Oct 25, 2024
1 parent 266bcba commit c9bab9f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docker/imposter/wazuh-config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
plugin: openapi
specFile: https://raw.githubusercontent.com/wazuh/wazuh/master/api/api/spec/spec.yaml
specFile: https://raw.githubusercontent.com/wazuh/wazuh/4.9.2/api/api/spec/spec.yaml
system:
stores:
# this store is preloaded from file
Expand Down
43 changes: 43 additions & 0 deletions plugins/main/scripts/release/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,47 @@ const cli = require('../../../../scripts/lib/cli/cli')(
],
);

function updateImposterSpecificationReference(configuration, logger) {
try {
logger.debug('Editing imposter specification reference');
const fs = require('fs');
const path = require('path');
const specificationFile = path.join(
__dirname,
'../../../..',
'docker/imposter/wazuh-config.yml',
);

logger.debug(`Reading ${specificationFile} file`);
const content = fs.readFileSync(specificationFile, 'utf8');

const { version } = configuration;

if (!version) {
throw new Error('Version is not specified.');
}

// specFile: https://raw.githubusercontent.com/wazuh/wazuh/<BRANCH_VERSION>/api/api/spec/spec.yaml
const updatedContent = content.replace(
/specFile:\s+\S+/m,
`specFile: https://raw.githubusercontent.com/wazuh/wazuh/${version}/api/api/spec/spec.yaml`,
);

if (content !== updatedContent) {
logger.debug(
`Updating [${specificationFile}] imposter specification file with latest changes`,
);
fs.writeFileSync(specificationFile, updatedContent, 'utf8');
logger.info(`${specificationFile} file has been updated`);
} else {
logger.debug(`Nothing to change in ${specificationFile} file`);
}
} catch (error) {
logger.error(`Error editing the specification file: ${error.message}`);
process.exit(1);
}
}

function run(configuration, logger) {
let localConfiguration = {
...configuration,
Expand Down Expand Up @@ -90,6 +131,8 @@ function run(configuration, logger) {
);
process.exit(1);
}

updateImposterSpecificationReference(localConfiguration, logger);
}

const logger = require('../../../../scripts/release/lib/logger').create([
Expand Down

0 comments on commit c9bab9f

Please sign in to comment.