Skip to content

Commit 200988d

Browse files
authored
feat: Allow starting tui with custom clouds.yaml (#1290)
Add support for `os_client_config_file` and `os_client_secure_file` to the TUI in the same way it is done for OSC.
1 parent de82a40 commit 200988d

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

openstack_cli/src/cli.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use clap::builder::{
1717
Styles,
1818
styling::{AnsiColor, Effects},
1919
};
20-
use clap::{Args, Parser, ValueEnum};
20+
use clap::{Args, Parser, ValueEnum, ValueHint};
2121
use clap_complete::Shell;
2222

2323
use openstack_sdk::AsyncOpenStack;
@@ -156,6 +156,7 @@ pub struct GlobalOpts {
156156
long,
157157
env = "OS_CLIENT_CONFIG_FILE",
158158
global = true,
159+
value_hint = ValueHint::FilePath,
159160
display_order = 905
160161
)]
161162
pub os_client_config_file: Option<String>,
@@ -165,6 +166,7 @@ pub struct GlobalOpts {
165166
long,
166167
env = "OS_CLIENT_SECURE_FILE",
167168
global = true,
169+
value_hint = ValueHint::FilePath,
168170
display_order = 905
169171
)]
170172
pub os_client_secure_file: Option<String>,

openstack_tui/src/app.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::collections::HashMap;
1919
use tokio::sync::mpsc;
2020
use tracing::{debug, error, instrument};
2121

22+
use crate::cli::Cli;
2223
use crate::{
2324
action::Action,
2425
cloud_worker::Cloud,
@@ -100,15 +101,17 @@ pub struct App {
100101
}
101102

102103
impl App {
103-
pub fn new(tick_rate: f64, frame_rate: f64, cloud_name: Option<String>) -> Result<Self> {
104+
pub fn new(args: &Cli) -> Result<Self> {
104105
let config = Config::new()?;
105106
let mode = Mode::Home;
106107
let (action_tx, action_rx) = mpsc::unbounded_channel();
107108

108109
let (cloud_worker, mut cloud_worker_receiver) = mpsc::unbounded_channel();
109110
let cloud_worker_app_tx = action_tx.clone();
111+
let client_config = args.os_client_config_file.clone();
112+
let client_secure_config = args.os_client_secure_file.clone();
110113
tokio::spawn(async move {
111-
let mut cloud = Cloud::new();
114+
let mut cloud = Cloud::new(client_config, client_secure_config);
112115
cloud
113116
.run(cloud_worker_app_tx, &mut cloud_worker_receiver)
114117
.await
@@ -194,8 +197,8 @@ impl App {
194197
components.insert(Mode::NetworkSubnets, Box::new(NetworkSubnets::new()));
195198

196199
Ok(Self {
197-
tick_rate,
198-
frame_rate,
200+
tick_rate: args.tick_rate,
201+
frame_rate: args.frame_rate,
199202
components,
200203
header: Box::new(Header::new()),
201204
should_quit: false,
@@ -207,7 +210,7 @@ impl App {
207210
action_rx,
208211
cloud_worker_tx: cloud_worker,
209212
last_tick_key_events: Vec::new(),
210-
cloud_name,
213+
cloud_name: args.os_cloud.clone(),
211214
cloud_connected: false,
212215
active_popup: None,
213216
popups: HashMap::from([

openstack_tui/src/bin/ostui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async fn tokio_main() -> Result<()> {
2828

2929
let args = Cli::parse();
3030

31-
let mut app = App::new(args.tick_rate, args.frame_rate, args.os_cloud)?;
31+
let mut app = App::new(&args)?;
3232
app.run().await?;
3333

3434
Ok(())

openstack_tui/src/cli.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,34 @@
1111
// limitations under the License.
1212
//
1313
// SPDX-License-Identifier: Apache-2.0
14-
15-
use clap::Parser;
14+
//! TUI Cli parameters
15+
use clap::{Parser, ValueHint};
16+
use std::path::PathBuf;
1617

1718
use crate::utils::version;
1819

20+
/// TUI Cli parameters
1921
#[derive(Parser, Debug)]
2022
#[command(author, version = version(), about)]
2123
pub struct Cli {
22-
#[arg(
23-
short,
24-
long,
25-
value_name = "FLOAT",
26-
help = "Tick rate, i.e. number of ticks per second",
27-
default_value_t = 0.2
28-
)]
24+
/// Number of ticks per second. May be used by certain views to trigger certain actions, but
25+
/// most likely not used.
26+
#[arg(short, long, value_name = "FLOAT", default_value_t = 0.2)]
2927
pub tick_rate: f64,
3028

31-
#[arg(
32-
short,
33-
long,
34-
value_name = "FLOAT",
35-
help = "Frame rate, i.e. number of frames per second",
36-
default_value_t = 1.0
37-
)]
29+
/// Refresh frame rate (number of frames per second)
30+
#[arg(short, long, value_name = "FLOAT", default_value_t = 1.0)]
3831
pub frame_rate: f64,
39-
#[arg(long)]
32+
33+
/// Cloud name to connect to after the start
34+
#[arg(long, env = "OS_CLOUD")]
4035
pub os_cloud: Option<String>,
36+
37+
/// Custom path to the `clouds.yaml` config file
38+
#[arg(long, env = "OS_CLIENT_CONFIG_FILE", value_hint = ValueHint::FilePath)]
39+
pub os_client_config_file: Option<PathBuf>,
40+
41+
/// Custom path to the `secure.yaml` config file
42+
#[arg(long, env = "OS_CLIENT_SECURE_FILE", value_hint = ValueHint::FilePath)]
43+
pub os_client_secure_file: Option<PathBuf>,
4144
}

openstack_tui/src/cloud_worker.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
// limitations under the License.
1212
//
1313
// SPDX-License-Identifier: Apache-2.0
14+
//! Cloud worker module.
15+
//!
16+
//! Handle communication with the cloud including connection, re-connection (when auth expires) and
17+
//! all the API requests.
1418
1519
use chrono::TimeDelta;
1620
use eyre::{Report, Result, eyre};
1721
use openstack_sdk::{
1822
AsyncOpenStack, auth::AuthState, config::ConfigFile, types::identity::v3::AuthResponse,
1923
};
24+
use std::path::PathBuf;
2025
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
2126
use tracing::debug;
2227

@@ -44,8 +49,16 @@ pub(crate) struct Cloud {
4449
}
4550

4651
impl Cloud {
47-
pub fn new() -> Self {
48-
let cfg = ConfigFile::new().unwrap();
52+
pub fn new(
53+
client_config_config_file: Option<PathBuf>,
54+
client_secure_config_file: Option<PathBuf>,
55+
) -> Self {
56+
let cfg = ConfigFile::new_with_user_specified_configs(
57+
client_config_config_file.as_deref(),
58+
client_secure_config_file.as_deref(),
59+
)
60+
.expect("unable to load config files");
61+
4962
Self {
5063
cloud_configs: cfg,
5164
cloud: None,

0 commit comments

Comments
 (0)