Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ RUN apt-get update && apt-get install -y \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

RUN cargo install sccache
RUN cargo install sccache --locked watchexec-cli

ENV RUSTC_WRAPPER=sccache
ENV SCCACHE_DIR=/sccache
ENV RUSTFLAGS="-Awarnings"

WORKDIR /usr/src/nebulous

CMD ["cargo", "run", "--", "serve", "--host", "0.0.0.0", "--port", "3000"]
CMD ["watchexec", "-w", "src", "-w", "Cargo.toml", "-r", "cargo", "run", "--", "serve", "--host", "0.0.0.0", "--port", "3000"]
4 changes: 2 additions & 2 deletions src/agent/ns.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::config::CONFIG;
use crate::config::SERVER_CONFIG;
use crate::entities::namespaces;
use anyhow::Result;
use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter};
Expand All @@ -25,7 +25,7 @@ pub async fn auth_ns(

if namespace == "root" {
debug!("Namespace is root");
let root_owner = CONFIG.root_owner.clone();
let root_owner = SERVER_CONFIG.root_owner.clone();
if !owner_ids.contains(&root_owner) {
error!("User not authorized to access root namespace");
return Err(anyhow::anyhow!("User not authorized to access namespace"));
Expand Down
4 changes: 2 additions & 2 deletions src/client/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::config::GlobalConfig;
use crate::config::ClientConfig;
use crate::models::V1StreamData;
use crate::resources::v1::containers::models::{
V1Container, V1ContainerRequest, V1ContainerSearch, V1Containers, V1UpdateContainer,
Expand Down Expand Up @@ -49,7 +49,7 @@ impl NebulousClient {
/// Creates a new NebulousClient by reading from the global config.
/// You could also pass server and api key directly if preferred.
pub fn new_from_config() -> Result<Self, Box<dyn Error>> {
let config = GlobalConfig::read()?;
let config = ClientConfig::read()?;
let current_server = config
.get_current_server_config()
.ok_or("No current server config found")?;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/delete_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::commands::request::server_request;
use futures::future::join_all;
use nebulous::config::GlobalConfig;
use nebulous::config::ClientConfig;
use nebulous::resources::v1::containers::models::V1Containers;
use reqwest::Client;
use std::error::Error;
Expand Down Expand Up @@ -138,7 +138,7 @@ pub async fn delete_processor(
namespace: Option<String>,
) -> Result<(), Box<dyn Error>> {
let client = Client::new();
let config = GlobalConfig::read()?;
let config = ClientConfig::read()?;
let current_server = config.get_current_server_config().unwrap();
let server = current_server.server.as_ref().unwrap();
let api_key = current_server.api_key.as_ref().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/commands/get_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
use serde::Serialize;

use crate::commands::request::server_request;
use nebulous::config::GlobalConfig;
use nebulous::config::ClientConfig;
use nebulous::resources::v1::containers::models::{V1Container, V1Containers};
use serde_json::Value;
use std::error::Error;
Expand Down Expand Up @@ -281,7 +281,7 @@ pub async fn get_processors(
name: Option<String>,
namespace: Option<String>,
) -> Result<(), Box<dyn Error>> {
let config = GlobalConfig::read()?;
let config = ClientConfig::read()?;
debug!("Config: {:?}", config);
let current_server = config.get_current_server_config().unwrap();
let server = current_server.server.as_ref().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions src/commands/log_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use nebulous::config::GlobalConfig;
use nebulous::config::ClientConfig;
use std::error::Error as StdError;
use std::io::Write;

Expand All @@ -15,7 +15,7 @@ pub async fn fetch_container_logs(
follow: bool,
) -> Result<String, Box<dyn StdError>> {
// Load config
let config = GlobalConfig::read()?;
let config = ClientConfig::read()?;
let current_server = config.get_current_server_config().unwrap();
let server = current_server.server.as_ref().unwrap();
let api_key = current_server.api_key.as_ref().unwrap();
Expand Down Expand Up @@ -143,7 +143,7 @@ async fn fetch_container_id_from_api(
namespace: &str,
name: &str,
) -> Result<String, Box<dyn StdError>> {
let config = nebulous::config::GlobalConfig::read()?;
let config = ClientConfig::read()?;
let current_server = config.get_current_server_config().unwrap();
let server = current_server.server.as_ref().unwrap();
let api_key = current_server.api_key.as_ref().unwrap();
Expand Down
20 changes: 9 additions & 11 deletions src/commands/login_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::error::Error;
use std::io::{self, Write};

use nebulous::config::{GlobalConfig, ServerConfig};
use nebulous::config::{ClientConfig, ClientServerConfig};
use open;
use rpassword;

Expand All @@ -17,7 +17,7 @@ pub async fn execute(

let nebu_url = nebu_url.trim().trim_end_matches("/").to_string();

let mut config = GlobalConfig::read()?;
let mut client_config = ClientConfig::read()?;

if auth.is_some() && hub.is_some() {
let auth_url = auth.unwrap().trim().trim_end_matches("/").to_string();
Expand All @@ -35,13 +35,12 @@ pub async fn execute(
io::stdout().flush()?;
let api_key = rpassword::read_password()?;

config.servers.push(ServerConfig {
name: Some("cloud".to_string()),
client_config.add_server(ClientServerConfig {
name: "cloud".to_string(),
server: Some(nebu_url),
api_key: Some(api_key),
auth_server: Some(auth_url),
});
config.current_server = Some("cloud".to_string());
}, true);
} else {
println!(
r#"Configuring the Nebulous CLI to use the integrated auth server.
Expand All @@ -63,15 +62,14 @@ When you're running nebulous on Kubernetes, use:
io::stdout().flush()?;
let api_key = rpassword::read_password()?;

config.servers.push(ServerConfig {
name: Some("nebu".to_string()),
client_config.add_server(ClientServerConfig {
name: "nebu".to_string(),
server: Some(nebu_url),
api_key: Some(api_key),
auth_server: None,
});
config.current_server = Some("nebu".to_string());
}, true);
}
config.write()?;
client_config.write()?;

// TODO: Check that we can actually reach and authenticate with the server

Expand Down
3 changes: 2 additions & 1 deletion src/commands/request.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use serde_json::Value;
use nebulous::config::ClientConfig;

fn prepare_request(
path: &str,
method: reqwest::Method,
) -> Result<reqwest::RequestBuilder, Box<dyn std::error::Error>> {
let config = nebulous::config::GlobalConfig::read()?;
let config = ClientConfig::read()?;
let current_server = config
.get_current_server_config()
.ok_or("Failed to get current server configuration")?;
Expand Down
4 changes: 2 additions & 2 deletions src/commands/send_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use nebulous::config::GlobalConfig;
use nebulous::config::ClientConfig;
use nebulous::models::V1StreamData;
use serde_json::Value;
use std::error::Error;
Expand All @@ -7,7 +7,7 @@ use std::io::{self, Read};
use tracing::debug;

pub async fn send_messages(args: &crate::cli::SendMessageCommands) -> Result<(), Box<dyn Error>> {
let config = GlobalConfig::read()?;
let config = ClientConfig::read()?;
debug!("Config: {:?}", config);
let current_server = config.get_current_server_config().unwrap(); // Handle error more gracefully
let server = current_server.server.as_ref().unwrap(); // Handle error
Expand Down
9 changes: 3 additions & 6 deletions src/commands/set_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use colored::Colorize;
use nebulous::config::GlobalConfig;
use nebulous::config::ClientConfig;
use std::error::Error;

pub async fn set_context(server_name: &str) -> Result<(), Box<dyn Error>> {
// Read the current config
let mut config = GlobalConfig::read()?;
let mut config = ClientConfig::read()?;

// Check if the server exists
let server_exists = config
.servers
.iter()
.any(|s| s.name.as_deref() == Some(server_name));
let server_exists = config.contains_server(server_name);

if !server_exists {
return Err(format!("Server '{}' not found in configuration", server_name).into());
Expand Down
18 changes: 5 additions & 13 deletions src/commands/show_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use anyhow::{Context, Result};
use colored::Colorize;
use nebulous::config::GlobalConfig;
use nebulous::config::ClientConfig;
use std::error::Error;

pub async fn show_config() -> Result<(), Box<dyn Error>> {
let config = GlobalConfig::read()?;
let config = ClientConfig::read()?;

println!("{}", "Global Configuration:".bold().underline());

Expand All @@ -19,24 +19,16 @@ pub async fn show_config() -> Result<(), Box<dyn Error>> {
if config.servers.is_empty() {
println!(" {}", "No servers configured".yellow());
} else {
for (idx, server) in config.servers.iter().enumerate() {
let is_current = config
.current_server
.as_ref()
.and_then(|current| server.name.as_ref().map(|name| current == name))
.unwrap_or(false);
for (idx, (_, server)) in config.servers.iter().enumerate() {
let is_current = config.current_server == Some(server.name.clone());

let prefix = if is_current {
"→ ".green()
} else {
" ".normal()
};

if let Some(name) = &server.name {
println!("{}{}", prefix, name.bold());
} else {
println!("{}{}", prefix, format!("Server #{}", idx + 1).bold());
}
println!("{}{}", prefix, server.name.bold());

if let Some(api_key) = &server.api_key {
let hidden_key = format!(
Expand Down
Loading