// // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. // use std::collections::HashMap; use type_description::{AsTypeDescription, TypeDescription}; /// How to configure a kubernetes cluster /// /// # Example /// /// ```toml /// [[cluster]] /// api_version = "25" /// ``` /// /// As you can see, this is rendered __with__ _full_ support. #[derive(Debug, TypeDescription)] pub struct KubeConfig { /// The API version of the kubernetes cluster pub api_version: String, pub clusters: Vec, pub contexts: Vec, pub current_context: String, pub kind: String, pub users: Vec, pub values: HashMap, } #[derive(Debug, TypeDescription)] pub struct Cluster { pub name: String, pub cluster: ClusterDetail, } #[derive(Debug, TypeDescription)] pub struct ClusterDetail { pub insecure_skip_tls_verify: Option, pub certificate_authority: Option, pub certificate_authority_data: Option, pub server: String, } #[derive(Debug, TypeDescription)] pub struct User { pub name: String, pub user: UserDetail, } #[derive(Debug, TypeDescription)] pub struct UserDetail { pub auth_provider: Option, pub client_certificate: Option, pub client_key: Option, pub client_certificate_data: Option, pub client_key_data: Option, pub exec: Option, pub token: Option, pub username: Option, pub password: Option, } #[derive(Debug, TypeDescription)] pub struct Exec { pub api_version: String, pub args: Vec, pub command: String, } #[derive(Debug, TypeDescription)] #[description(tag = "name")] pub enum AuthProviderDetail { Gcp(GcpAuthProviderConfig), Other, } #[derive(Debug, TypeDescription)] pub struct GcpAuthProviderConfig { pub access_token: Option, pub cmd_args: String, pub cmd_path: String, pub expiry: Option, pub expiry_key: String, pub token_key: String, } #[derive(Debug, TypeDescription)] pub struct Context { pub name: String, pub context: ContextDetail, } #[derive(Debug, TypeDescription)] pub struct ContextDetail { pub cluster: String, pub user: String, pub namespace: Option, } #[test] fn check_complex_type_desc() { let desc = KubeConfig::as_type_description(); println!( "{}", serde_json::to_string(&desc).expect("SHould be able to serialize to json") ); }