-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add cli to generate and install plugin bundle #6397
Conversation
@@ -154,6 +154,10 @@ enum Action { | |||
}, | |||
/// Will generate a plugin bundle | |||
GeneratePluginBundle(GeneratePluginBundle), | |||
/// Will insert generated plugin bundle | |||
InstallPluginBundle(InstallPluginBundle), |
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.
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) { |
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 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 = |
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.
Copied from
open-msupply/server/service/src/sync/api_v6/upload_file.rs
Lines 60 to 61 in 86be0d6
fn to_reqwest_multipart( | |
json_reqwest: &SyncUploadFileRequestV6, |
query: &str, | ||
variables: serde_json::Value, | ||
token: Option<&str>, | ||
expected_typename: Option<&str>, |
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.
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 })); |
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.
If there is not 'consumption' then it will be zero, changed to '1' to see effect of the plugin
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.
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](https://private-user-images.githubusercontent.com/8287373/409748368-530d9cf8-47e1-4b68-91a0-519bfbcc5202.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMjA3MTksIm5iZiI6MTczOTEyMDQxOSwicGF0aCI6Ii84Mjg3MzczLzQwOTc0ODM2OC01MzBkOWNmOC00N2UxLTRiNjgtOTFhMC01MTliZmJjYzUyMDIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDlUMTcwMDE5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2I0NDk1YzY1NGZiYzM4NzAxNWE3YmY4OWI0ODYwOTA2ZDU1MDAzMTU1ZmYxZTg5YmVmNDIwZjQ2NzhhMWVkZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.Klim63Ur3wIiADK2zj1lF7t4iFIiXCs8BuNCQ11T_Oc)
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....
server/cli/src/plugins.rs
Outdated
out_file: out_file.clone(), | ||
})?; | ||
|
||
let api = Api::new_with_token(url.clone(), username, password).await?; |
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.
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..
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.
Agree, thanks: 532f988
Thanks for flagging, made an issue: #6447 |
Thanks for review @jmbrunskill |
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