Skip to content
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

Add cli to generate and install plugin bundle #6397

Merged
merged 5 commits into from
Feb 9, 2025

Conversation

andreievg
Copy link
Collaborator

Fixes #6396

πŸ‘©πŸ»β€πŸ’» What does this PR do?

Add install-plugin-bundle cli and general-and-install-plugin-bundle cli, see amc.js on notes of how to use.

πŸ’Œ Any notes for the reviewer?

There is now API accessor in the cli (api struct), which is similar to what was done in the report_builder but a bit easier on the consumer, we would use this abstraction when time comes to delete report builder

πŸ§ͺ Testing

Make changes to amc.js
Run
cargo run --bin remote_server_cli -- generate-and-install-plugin-bundle -i './service/src/backend_plugin/examples/amc' -u 'http://localhost:8000' --username 'test' --password 'pass', and see your AMC values update when looking at catalogue

@github-actions github-actions bot added this to the v2.6.0 milestone Feb 3, 2025
@github-actions github-actions bot added enhancement New feature or request feature: plugin labels Feb 3, 2025
@@ -154,6 +154,10 @@ enum Action {
},
/// Will generate a plugin bundle
GeneratePluginBundle(GeneratePluginBundle),
/// Will insert generated plugin bundle
InstallPluginBundle(InstallPluginBundle),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was thinking maybe we just need generate and install, kept this one however as a manual was to install via CLI

@@ -0,0 +1,16 @@
pub(super) const AUTH_QUERY: &str = r#"
query AuthToken($username: String!, $password: String) {
root: authToken(password: $password, username: $username) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this root relates to the GraphQlResponse struct and Root struct, it seems cleaner to use struct with auto derived de/se and map graphql field to root, rather then manually accessing serde_json::Value type

.header("Cookie", auth_cooke_value);

// Add file to request
let mut file_handle =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from

fn to_reqwest_multipart(
json_reqwest: &SyncUploadFileRequestV6,

query: &str,
variables: serde_json::Value,
token: Option<&str>,
expected_typename: Option<&str>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check typename at the 'root' if specified

@@ -36,6 +42,9 @@ let plugins = {
const sql_result = sql(sql_statement);
const response = {};

// Fill all item_ids with default
item_ids.forEach((itemId) => (response[itemId] = { average_monthly_consumption: 1 }));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is not 'consumption' then it will be zero, changed to '1' to see effect of the plugin

@andreievg andreievg added the Team Ruru πŸ¦‰ Roxy, Ferg, Noel label Feb 4, 2025
@jmbrunskill jmbrunskill self-assigned this Feb 4, 2025
Copy link
Contributor

@jmbrunskill jmbrunskill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THanks @andreievg works well for me...

One thing to note, not related to this PR directly, but if your plugin has an error in it, or fails the whole request seems to be killed.

image
    if (Math.random() > 0.5) {
      throw new Error("Random error");
    }

I'm not sure if we've talked about expected error handling? Maybe wort thinking about, I think ideally this shouldn't stop me seeing my whole item list...
But won't be easy to handle it an show an error else where. Maybe it's fine how it is but I can imagine a small plugin bug breaking the whole system for a client....

out_file: out_file.clone(),
})?;

let api = Api::new_with_token(url.clone(), username, password).await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially can call the function install_plugin_bundle from with in this one, but I agree it's not too much code duplication, so I'm happy with this..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, thanks: 532f988

@andreievg
Copy link
Collaborator Author

One thing to note, not related to this PR directly, but if your plugin has an error in it, or fails the whole request seems to be killed.

Thanks for flagging, made an issue: #6447

@andreievg
Copy link
Collaborator Author

Thanks for review @jmbrunskill

@andreievg andreievg merged commit 0740340 into develop Feb 9, 2025
2 checks passed
@andreievg andreievg deleted the 6396-CLI-to-generate-and-isntall-plugin-bundle branch February 9, 2025 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature: plugin Team Ruru πŸ¦‰ Roxy, Ferg, Noel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it easier to generate and install plugin bundle
2 participants