1818use :: rpc:: forge as rpc;
1919
2020use super :: args:: MaintenanceOptions ;
21- use crate :: errors:: CarbideCliResult ;
21+ use crate :: errors:: { CarbideCliError , CarbideCliResult } ;
2222use crate :: rpc:: ApiClient ;
2323
24+ fn resolve_firmware_upgrade_source (
25+ args : & MaintenanceOptions ,
26+ ) -> CarbideCliResult < ( String , Option < String > ) > {
27+ if args. firmware_version . is_some ( ) && args. sot_json_file . is_some ( ) {
28+ return Err ( CarbideCliError :: ChooseOneError (
29+ "--firmware-version" ,
30+ "--sot-json-file" ,
31+ ) ) ;
32+ }
33+
34+ let firmware_version = if let Some ( path) = args. sot_json_file . as_ref ( ) {
35+ let config_json = std:: fs:: read_to_string ( path) ?;
36+ serde_json:: from_str :: < serde_json:: Value > ( & config_json) ?;
37+ config_json
38+ } else {
39+ args. firmware_version . clone ( ) . unwrap_or_default ( )
40+ } ;
41+
42+ let access_token = args. access_token . as_ref ( ) . and_then ( |token| {
43+ if token. trim ( ) . is_empty ( ) {
44+ None
45+ } else {
46+ Some ( token. clone ( ) )
47+ }
48+ } ) ;
49+
50+ if args. sot_json_file . is_some ( ) && access_token. is_none ( ) {
51+ return Err ( CarbideCliError :: GenericError (
52+ "--access-token is required with --sot-json-file" . to_string ( ) ,
53+ ) ) ;
54+ }
55+ if args. access_token . is_some ( ) && firmware_version. trim ( ) . is_empty ( ) {
56+ return Err ( CarbideCliError :: GenericError (
57+ "--access-token requires SOT JSON from --sot-json-file or --firmware-version"
58+ . to_string ( ) ,
59+ ) ) ;
60+ }
61+ if access_token. is_some ( ) {
62+ serde_json:: from_str :: < serde_json:: Value > ( & firmware_version) ?;
63+ }
64+
65+ Ok ( ( firmware_version, access_token) )
66+ }
67+
2468pub async fn on_demand_rack_maintenance (
2569 api_client : & ApiClient ,
2670 args : MaintenanceOptions ,
2771) -> CarbideCliResult < ( ) > {
2872 use rpc:: maintenance_activity_config:: Activity as ProtoActivity ;
2973
30- let firmware_version = args . firmware_version . unwrap_or_default ( ) ;
74+ let ( firmware_version, access_token ) = resolve_firmware_upgrade_source ( & args ) ? ;
3175 let components = args. components . unwrap_or_default ( ) ;
3276 let firmware_object_id = args. firmware_object_id . unwrap_or_default ( ) ;
77+ let force_update = args. force_update ;
3378
3479 let activities: Vec < rpc:: MaintenanceActivityConfig > = args
3580 . activities
@@ -41,8 +86,8 @@ pub async fn on_demand_rack_maintenance(
4186 rpc:: FirmwareUpgradeActivity {
4287 firmware_version : firmware_version. clone ( ) ,
4388 components : components. clone ( ) ,
44- access_token : None ,
45- force_update : false ,
89+ access_token : access_token . clone ( ) ,
90+ force_update,
4691 } ,
4792 ) ) ,
4893 "nvos-update" => Ok ( ProtoActivity :: NvosUpdate (
0 commit comments