Skip to content

Commit

Permalink
Fixed mirrord-operator compilation with no enabled features (metalb…
Browse files Browse the repository at this point in the history
…ear-co#2568)

* Removed fixed missing http dependency

* Changelog entry
  • Loading branch information
Razz4780 authored Jul 2, 2024
1 parent dbe58ed commit 889796e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelog.d/+fixed-missing-http-dep.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed compilation of `mirrord-operator` crate with no features.
20 changes: 12 additions & 8 deletions mirrord/operator/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use base64::{engine::general_purpose, Engine};
use chrono::{DateTime, Utc};
use conn_wrapper::ConnectionWrapper;
use error::{OperatorApiError, OperatorApiResult, OperatorOperation};
use http::{request::Request, HeaderValue};
use http::{request::Request, HeaderName, HeaderValue};
use kube::{
api::{ListParams, PostParams},
Api, Client, Config, Resource,
Expand Down Expand Up @@ -387,7 +387,9 @@ impl OperatorApi<NoClientCert> {
let header = Self::make_client_cert_header(&certificate)?;

let mut config = self.client_cert.base_config;
config.headers.push((CLIENT_CERT_HEADER.clone(), header));
config
.headers
.push((HeaderName::from_static(CLIENT_CERT_HEADER), header));
let client = Client::try_from(config)
.map_err(KubeApiError::from)
.map_err(OperatorApiError::CreateKubeClient)?;
Expand Down Expand Up @@ -546,15 +548,15 @@ where
.map_err(OperatorApiError::CreateKubeClient)?;

client_config.headers.push((
MIRRORD_CLI_VERSION_HEADER.clone(),
HeaderName::from_static(MIRRORD_CLI_VERSION_HEADER),
HeaderValue::from_static(env!("CARGO_PKG_VERSION")),
));

let UserIdentity { name, hostname } = UserIdentity::load();

let headers = [
(CLIENT_NAME_HEADER.clone(), name),
(CLIENT_HOSTNAME_HEADER.clone(), hostname),
(CLIENT_NAME_HEADER, name),
(CLIENT_HOSTNAME_HEADER, hostname),
];
for (name, raw_value) in headers {
let Some(raw_value) = raw_value else {
Expand All @@ -568,7 +570,9 @@ where
.to_string();
let value = HeaderValue::from_str(&cleaned);
match value {
Ok(value) => client_config.headers.push((name, value)),
Ok(value) => client_config
.headers
.push((HeaderName::from_static(name), value)),
Err(error) => {
tracing::debug!(%error, %name, raw_value = raw_value, cleaned, "Invalid header value");
}
Expand Down Expand Up @@ -799,7 +803,7 @@ impl OperatorApi<PreparedClientCert> {
let cert_header = Self::make_client_cert_header(&session.client_cert)?;
config
.headers
.push((CLIENT_CERT_HEADER.clone(), cert_header));
.push((HeaderName::from_static(CLIENT_CERT_HEADER), cert_header));

let client = Client::try_from(config)
.map_err(KubeApiError::from)
Expand All @@ -818,7 +822,7 @@ impl OperatorApi<PreparedClientCert> {
) -> OperatorApiResult<(Sender<ClientMessage>, Receiver<DaemonMessage>)> {
let request = Request::builder()
.uri(&session.connect_url)
.header(SESSION_ID_HEADER.clone(), session.id.to_string())
.header(SESSION_ID_HEADER, session.id.to_string())
.body(vec![])
.map_err(OperatorApiError::ConnectRequestBuildError)?;

Expand Down
22 changes: 10 additions & 12 deletions mirrord/operator/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use chrono::NaiveDate;
use http::HeaderName;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand All @@ -14,26 +13,25 @@ pub struct LicenseInfoOwned {
pub subscription_id: Option<String>,
}

/// HTTP header containing CLI version.
/// Name of HTTP header containing CLI version.
/// Sent with each request to the mirrord operator.
pub static MIRRORD_CLI_VERSION_HEADER: HeaderName =
HeaderName::from_static("x-mirrord-cli-version");
pub const MIRRORD_CLI_VERSION_HEADER: &str = "x-mirrord-cli-version";

/// HTTP header containing client certificate.
/// Name of HTTP header containing client certificate.
/// Sent with each request to the mirrord operator (if available) except:
/// 1. Initial GET on the operator resource
/// 2. User certificate request
/// Required for making the target connection request.
pub static CLIENT_CERT_HEADER: HeaderName = HeaderName::from_static("x-client-der");
pub const CLIENT_CERT_HEADER: &str = "x-client-der";

/// HTTP header containing client hostname.
/// Name of HTTP header containing client hostname.
/// Sent with each request to the mirrord operator (if available).
pub static CLIENT_HOSTNAME_HEADER: HeaderName = HeaderName::from_static("x-client-hostname");
pub const CLIENT_HOSTNAME_HEADER: &str = "x-client-hostname";

/// HTTP header containing client name.
/// Name of HTTP header containing client name.
/// Sent with each request to the mirrord operator (if available).
pub static CLIENT_NAME_HEADER: HeaderName = HeaderName::from_static("x-client-name");
pub const CLIENT_NAME_HEADER: &str = "x-client-name";

/// HTTP header containing operator session id.
/// Name of HTTP header containing operator session id.
/// Sent with target connection request.
pub static SESSION_ID_HEADER: HeaderName = HeaderName::from_static("x-session-id");
pub const SESSION_ID_HEADER: &str = "x-session-id";

0 comments on commit 889796e

Please sign in to comment.