/// Loads the authentication header from the credentials available in the kubeconfig. This supports
/// exec plugins as well as specified in
/// https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins
Loads the authentication header from the credentials available in the kubeconfig.
Loads the authentication header from the credentials available in the kubeconfig .
fn load_auth_header(loader: &ConfigLoader) -> Result<Authentication> {
    let (raw_token, expiration) = match &loader.user.token {
        Some(token) => (Some(token.clone()), None),
        None => {
            if let Some(exec) = &loader.user.exec {
                let creds = exec::auth_exec(exec)?;
                let status = creds.status.ok_or(ConfigError::ExecPluginFailed)?;
                let expiration = match status.expiration_timestamp {
                    Some(ts) => Some(
                        ts.parse::<DateTime<Utc>>()
                            .map_err(ConfigError::MalformedTokenExpirationDate)?,
                    ),
                    None => None,
                };
                (status.token, expiration)
            } else {
                (None, None)
            }
        }
    };
    match (
        utils::data_or_file(&raw_token, &loader.user.token_file),
        (&loader.user.username, &loader.user.password),
        expiration,
    ) {
        (Ok(token), _, None) => Ok(Authentication::Token(format!("Bearer {}", token))),
        (Ok(token), _, Some(expire)) => Ok(Authentication::RefreshableToken(
            Arc::new(Mutex::new((format!("Bearer {}", token), expire))),
            loader.clone(),
        )),
        (_, (Some(u), Some(p)), _) => {
            let encoded = base64::encode(&format!("{}:{}", u, p));
            Ok(Authentication::Basic(format!("Basic {}", encoded)))
        }
        _ => Ok(Authentication::None),
    }
}
fn load_auth_header ( loader : & ConfigLoader ) -> Result < Authentication > { let ( raw_token , expiration ) = match & loader . user . token { Some ( token ) => ( Some ( token . clone ( ) ) , None ) , None => { if let Some ( exec ) = & loader . user . exec { let creds = exec :: auth_exec ( exec ) ? ; let status = creds . status . ok_or ( ConfigError :: ExecPluginFailed ) ? ; let expiration = match status . expiration_timestamp { Some ( ts ) => Some ( ts . parse :: < DateTime < Utc > > ( ) . map_err ( ConfigError :: MalformedTokenExpirationDate ) ? , ) , None => None , } ; ( status . token , expiration ) } else { ( None , None ) } } } ; match ( utils :: data_or_file ( & raw_token , & loader . user . token_file ) , ( & loader . user . username , & loader . user . password ) , expiration , ) { ( Ok ( token ) , _ , None ) => Ok ( Authentication :: Token ( format ! ( " " token ) ) ) , ( Ok ( token ) , _ , Some ( expire ) ) => Ok ( Authentication :: RefreshableToken ( Arc :: new ( Mutex :: new ( ( format ! ( " " token ) , expire ) ) ) , loader . clone ( ) , ) ) , ( _ , ( Some ( u ) , Some ( p ) ) , _ ) => { let encoded = base64 :: encode ( & format ! ( " " u p ) ) ; Ok ( Authentication :: Basic ( format ! ( " " encoded ) ) ) } _ => Ok ( Authentication :: None ) , } }
Loads the authentication header from the credentials available in the kubeconfig.
Loads the authentication header from the credentials available in the kubeconfig .
loader
&ConfigLoader