Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a newline to pem blobs if one is not present #505

Merged
merged 2 commits into from
Apr 29, 2021
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
8 changes: 7 additions & 1 deletion kube/src/config/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ pub fn default_kube_path() -> Option<PathBuf> {
}

pub fn data_or_file_with_base64<P: AsRef<Path>>(data: &Option<String>, file: &Option<P>) -> Result<Vec<u8>> {
match (data, file) {
let mut blob = match (data, file) {
(Some(d), _) => base64::decode(&d)
.map_err(ConfigError::Base64Decode)
.map_err(Error::Kubeconfig),
(_, Some(f)) => read_file(f),
_ => Err(ConfigError::NoBase64FileOrData.into()),
}?;
//Ensure there is a trailing newline in the blob
//Don't bother if the blob is empty
if blob.last().map(|end| *end != b'\n').unwrap_or(false) {
blob.push(b'\n');
}
Ok(blob)
}

pub fn read_file<P: AsRef<Path>>(file: P) -> Result<Vec<u8>> {
Expand Down
1 change: 0 additions & 1 deletion kube/src/service/auth/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{
task::{Context, Poll},
};


use futures::{ready, Future};
use http::{header::AUTHORIZATION, Request};
use hyper::Body;
Expand Down
7 changes: 3 additions & 4 deletions kube/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ use self::{log::LogRequest, url::set_cluster_url};
use auth::AuthLayer;
#[cfg(feature = "gzip")] use compression::{accept_compressed, maybe_decompress};
use headers::set_default_headers;
use tls::HttpsConnector;

use std::convert::{TryFrom, TryInto};

use http::{HeaderValue, Request, Response};
use hyper::{Body, Client as HyperClient};
use hyper_timeout::TimeoutConnector;
use std::convert::{TryFrom, TryInto};
use tls::HttpsConnector;

use tower::{buffer::Buffer, util::BoxService, BoxError, ServiceBuilder};

use crate::{error::ConfigError, Config, Error, Result};
Expand Down