-
Notifications
You must be signed in to change notification settings - Fork 917
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
Allowing custom folder name for plugin installation #446
Allowing custom folder name for plugin installation #446
Conversation
✅ DCO Check Passed c23c30e |
❌ DCO Check Failed ffa60d1 |
ffa60d1
to
86111b9
Compare
✅ DCO Check Passed 86111b9 |
86111b9
to
5fa4e2f
Compare
✅ DCO Check Passed 5fa4e2f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think naming should be standardized. it looks like pluginFolder
is an existing thing, soI would call the option pluginFolder
as well, or targetPluginFolder
.
src/cli_plugin/install/index.js
Outdated
@@ -64,6 +64,7 @@ export function installCommand(program) { | |||
'length of time before failing; 0 for never fail', | |||
parseMilliseconds | |||
) | |||
.option('-o, --override', 'override the folder name for plugin installation') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this match the folderName
name? Aka --folderName=
(can still be -o
for the short version)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the option to --folderName
.
src/cli_plugin/install/install.js
Outdated
@@ -59,11 +59,14 @@ export async function install(settings, logger) { | |||
|
|||
del.sync(settings.tempArchiveFile, { force: true }); | |||
|
|||
settings.plugins[0].pluginFolder = settings.override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be using the same name everywhere, if the option is folderName
, then this would also be folderName
and settings.folderName
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the naming consistent.
❌ DCO Check Failed d45105d |
d45105d
to
fb00d2f
Compare
✅ DCO Check Passed fb00d2f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this in the first review, apologies. I think the value of folderName
that's passed by the user should be used as-is, and not kebab-cased. It would be really confusing to users if I were to specify --folderName=myPlugin
and end up with my-plugin
, don't you think? Some test coverage of the above is needed in that case, too, then.
Thus, I think I'd want a property, settings.plugins[0].folderName
, that defaults to kebabcase(id)
on construction or some other place, and is overridden by -o
. Move the calls to kebabcasing into whenever that value is assigned, so that we would reference it everywhere consistently. Also easier to test.
The
I kept the conversion to kebab-case to keep the naming convention consistent. LMK what you think. |
Oh this is not at all how I understood this and is quite unusual! The developers of the plugin should be able to decide where the plugin is installed by default. This is how I believe this feature should be designed.
That seems much more straightforward, doesn't it? |
The first two points are definitely straightforward. For the third one, I think if the user is allowed to enter the plugin folder name in the cli command itself, it will result in problems during the next install of the same plugin. When a plugin is installed, the logic first checks for an existing installation, this is checked using the plugin's id and the plugin's folderName both specified in the |
Makes sense to me, agreed. |
fb00d2f
to
8a8327a
Compare
✅ DCO Check Passed 8a8327a |
8a8327a
to
58edde7
Compare
✅ DCO Check Passed 58edde7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor and add tests for the refactored folder name function. This also needs tests for that the target directory is settings.folderName
when specified, and is kebab-case of id when not.
src/cli_plugin/install/install.js
Outdated
@@ -63,7 +63,10 @@ export async function install(settings, logger) { | |||
|
|||
assertVersion(settings); | |||
|
|||
const targetDir = path.join(settings.pluginDir, kebabCase(settings.plugins[0].id)); | |||
const folderName = settings.plugins[0].folderName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this condition move into a targetFolderName()
method in settings (might need to be extended into a class with methods), and use .targetFolderName()
everywhere it's needed? This would avoid duplication, be more OOO, and would be easy to write unit tests against.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this to getTargetFolderName()
function.
@@ -47,6 +47,18 @@ export function existingInstall(settings, logger) { | |||
} catch (e) { | |||
if (e.code !== 'ENOENT') throw e; | |||
} | |||
if (settings.plugins[0].folderName !== '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplicate check for both .id
and .folderName
is telling me that there should only be one check here, instead of .id
it would be using .targetFolderName()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the logic to check for the targetFolderName
.
src/cli_plugin/install/zip.js
Outdated
@@ -82,6 +82,10 @@ export function analyzeArchive(archive) { | |||
plugins.push({ | |||
id: manifest.id, | |||
stripPrefix: match[1], | |||
folderName: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be .manifest.folderName
. There's nothing wrong with a null value, it shouldn't become blank if it's not set. If you move the logic to resolve targetFolderName
into a function you can check for null
or blank there and return id if the value of folderName
is either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to move the logic to getTargetFolderName
function.
58edde7
to
7b02a01
Compare
✅ DCO Check Passed 7b02a01 |
7b02a01
to
fcc3bdc
Compare
✅ DCO Check Passed fcc3bdc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot cleaner! What's this removed code? Otherwise LGTM.
@@ -38,10 +38,11 @@ import { versionSatisfies, cleanVersion } from '../../legacy/utils/version'; | |||
|
|||
export function existingInstall(settings, logger) { | |||
try { | |||
statSync(path.join(settings.pluginDir, kebabCase(settings.plugins[0].id))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may have been right to worry that previous versions of plugins may have been installed into settings.plugins[0].id
(1.1 installation on top of 1.0). Is that a valid concern. If so, make an array of all possible folder names, and do a foreach on them to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the cases I can think of now is the user first used the id of the plugin to install it, then added a folderName property to opensearch_dashboards.json
and tried installing again. It should fail saying the plugin is already installed. I will add both the checks to be on the safer side.
logger.log(pkg.id + '@' + pkg.version); | ||
} catch (e) { | ||
throw new Error('Unable to read opensearch_dashboards.json file for plugin ' + name); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason to remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the list command, the output printed was <pluginId>@<pluginVersion>
but this same output could not be used in the remove command, this was mentioned in the same issue #322 in the latest comments, I removed this so that the actual folder name can be printed which the user can use to remove the plugin with the remove command. LMK if you think this could be better.
fcc3bdc
to
72cc7e6
Compare
✅ DCO Check Passed 72cc7e6 |
Signed-off-by: Vacha Shah <[email protected]>
72cc7e6
to
a2ff1fd
Compare
✅ DCO Check Passed a2ff1fd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Maybe someone from Dashboards wants to review this as well, since I'm not super familiar with the codebase - @mihirsoni maybe?
Going to close this PR, can be picked up when required. |
Signed-off-by: Vacha Shah [email protected]
Description
This PR allows plugin owners to specify a custom folder name for plugin cli installation and override the folder name. This custom folder name can be specified in
opensearch_dashboards.json
for the plugin. If the folder name is specified in theopensearch_dashboards.json
, the plugin is installed using the custom folder name as is specified for the plugin, else the id of the plugin is used in kebab-case.Testing
The unit tests have been added. Also tested with a plugin
anomaly-detection-dashboards-plugin
, I have added an attribute inopensearch_dashboards.json
as follows:Using the above settings, I installed the plugin using:
The above command installs the plugin as:
customFolder
Issues Resolved
Part 3 and 4 of #322.
Check List