From 041859a742223e6134e4be49b222ad689c670eaa Mon Sep 17 00:00:00 2001 From: Rami Daghlawi Date: Sun, 27 Aug 2023 17:36:52 +0200 Subject: [PATCH] rename config -> kubeconfig for clearity --- src/commands.rs | 6 +++--- src/config.rs | 20 ++++++++++---------- src/model.rs | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index e4de366..ed70bd5 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,4 +1,4 @@ -use crate::model::Config; +use crate::model::KubeConfig; use crate::config; use std::process; @@ -86,12 +86,12 @@ pub fn selectable_list(input: Vec) -> String { selected_items[0].output().to_string() } -pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &Config) { +pub fn set_namespace(ctx: &str, selection: &str, temp_dir: &str, config: &KubeConfig) { let choice = config.contexts.iter().find(|x| x.name == ctx); config::write(choice.unwrap(), Some(selection), temp_dir) } -pub fn set_context(ctx: &str, temp_dir: &str, config: &Config) { +pub fn set_context(ctx: &str, temp_dir: &str, config: &KubeConfig) { let choice = config.contexts.iter().find(|x| x.name == ctx); config::write(choice.unwrap(), None, temp_dir); } diff --git a/src/config.rs b/src/config.rs index a72f93c..0cb29fb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,11 +1,11 @@ -use crate::model::{Config, Context, Contexts}; +use crate::model::{KubeConfig, Context, Contexts}; use crate::{KUBECONFIG, KUBESESSCONFIG}; use std::fs::{self, File}; use std::io::{BufReader, BufWriter, Read}; use std::path::Path; -fn build(ctx: &Contexts, ns: Option<&str>, strbuf: &str) -> Config { - let mut config: Config = serde_yaml::from_str(&strbuf).unwrap(); +fn build(ctx: &Contexts, ns: Option<&str>, strbuf: &str) -> KubeConfig { + let mut config: KubeConfig = serde_yaml::from_str(&strbuf).unwrap(); config.api_version = "v1".to_string(); config.kind = "Config".to_string(); config.current_context = format!("{}", ctx.name); @@ -71,14 +71,14 @@ pub fn write(ctx: &Contexts, namespace: Option<&str>, dest: &str) { serde_yaml::to_writer(writer, &config).unwrap(); } -pub fn get() -> Config { - let mut configs = Config::default(); +pub fn get() -> KubeConfig { + let mut configs = KubeConfig::default(); for s in KUBECONFIG.rsplit(":") { if s.contains("/kubesess/cache") { continue; } - let config: Config = get_config(s); + let config: KubeConfig = get_config(s); configs.current_context = config.current_context; configs.api_version = config.api_version; @@ -91,7 +91,7 @@ pub fn get() -> Config { let path = entry.unwrap().path(); if let Some(extension) = path.extension() { if extension == "yaml" { - let config: Config = get_config(path.to_str().unwrap()); + let config: KubeConfig = get_config(path.to_str().unwrap()); configs.contexts.extend(config.contexts); } @@ -101,7 +101,7 @@ pub fn get() -> Config { configs } -fn get_config(path: &str) -> Config { +fn get_config(path: &str) -> KubeConfig { let f = File::open(path).unwrap(); let mut reader = BufReader::new(f); @@ -110,12 +110,12 @@ fn get_config(path: &str) -> Config { .read_to_string(&mut tmp) .expect("Unable to read file"); - let config: Config = serde_yaml::from_str(&tmp.trim()).unwrap(); + let config: KubeConfig = serde_yaml::from_str(&tmp.trim()).unwrap(); config } -pub fn get_current_session() -> Config { +pub fn get_current_session() -> KubeConfig { let config; let current; diff --git a/src/model.rs b/src/model.rs index b5df030..ed75048 100644 --- a/src/model.rs +++ b/src/model.rs @@ -17,7 +17,7 @@ pub struct Context { } #[derive(Default, Debug, PartialEq, Serialize, Deserialize)] -pub struct Config { +pub struct KubeConfig { #[serde(skip_serializing_if = "String::is_empty", default)] pub kind: String, #[serde(rename = "apiVersion")]