Adding in hash handling for datasource plugins.
This commit is contained in:
parent
9d22f83e4e
commit
e53f86c0b2
|
@ -93,7 +93,11 @@ module.exports = {
|
|||
for (let plugin of plugins) {
|
||||
if (plugin.name === integration) {
|
||||
// need to use commonJS require due to its dynamic runtime nature
|
||||
return getDatasourcePlugin(plugin.name, plugin.jsUrl)
|
||||
return getDatasourcePlugin(
|
||||
plugin.name,
|
||||
plugin.jsUrl,
|
||||
plugin.schema?.hash
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -351,13 +351,20 @@ exports.extractPluginTarball = async file => {
|
|||
return { metadata, directory: path }
|
||||
}
|
||||
|
||||
exports.getDatasourcePlugin = async (name, url) => {
|
||||
exports.getDatasourcePlugin = async (name, url, hash) => {
|
||||
if (!fs.existsSync(DATASOURCE_PATH)) {
|
||||
fs.mkdirSync(DATASOURCE_PATH)
|
||||
}
|
||||
const filename = join(DATASOURCE_PATH, name)
|
||||
const metadataName = `${filename}.bbmetadata`
|
||||
if (fs.existsSync(filename)) {
|
||||
return require(filename)
|
||||
const currentHash = fs.readFileSync(metadataName, "utf8")
|
||||
// if hash is the same return the file, otherwise remove it and re-download
|
||||
if (currentHash === hash) {
|
||||
return require(filename)
|
||||
} else {
|
||||
fs.unlinkSync(filename)
|
||||
}
|
||||
}
|
||||
const fullUrl = checkSlashesInUrl(
|
||||
`${env.MINIO_URL}/${ObjectStoreBuckets.PLUGINS}/${url}`
|
||||
|
@ -366,6 +373,7 @@ exports.getDatasourcePlugin = async (name, url) => {
|
|||
if (response.status === 200) {
|
||||
const content = await response.text()
|
||||
fs.writeFileSync(filename, content)
|
||||
fs.writeFileSync(metadataName, hash)
|
||||
require(filename)
|
||||
} else {
|
||||
throw new Error(
|
||||
|
|
Loading…
Reference in New Issue