Skip to content

Commit

Permalink
chore: use advanced formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed Sep 14, 2024
1 parent 54b2a3a commit 377dc1c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/argo_cd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ impl ArgoCD {

let app_name = self.argo_config.application.as_str();
let url = format!(
"{}/api/v1/applications/{name}/sync",
self.argo_config.base_url,
"{baseUrl}/api/v1/applications/{name}/sync",
baseUrl = self.argo_config.base_url,
name = encode(app_name)
);

Expand Down Expand Up @@ -127,7 +127,7 @@ impl ArgoCD {
match argocd_token {
Ok(token) => {
debug!("Applying bearer token to ArgoCD request");
request_builder.header("Authorization", format!("Bearer {}", token))
request_builder.header("Authorization", format!("Bearer {token}"))
}
Err(_) => {
warn!("You're accessing ArgoCD without authentication (missing {} environment variable)", ARGO_CD_TOKEN);
Expand All @@ -145,8 +145,8 @@ impl ArgoCD {

fn wait_for_status_change(&mut self, condition: fn(&Application) -> bool) {
let url = format!(
"{}/api/v1/applications/{name}",
self.argo_config.base_url,
"{baseUrl}/api/v1/applications/{name}",
baseUrl = self.argo_config.base_url,
name = encode(self.argo_config.application.as_str())
);

Expand Down
10 changes: 5 additions & 5 deletions tests/rotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn rotate_secrets() {

let (argocd_port, stop_sender) = open_argocd_server_port_forward(&kubectl).await;

let argocd_url = format!("http://localhost:{}", argocd_port);
let argocd_url = format!("http://localhost:{argocd_port}");

let argocd_token = get_argocd_access_token(&kubectl, argocd_url.as_str()).await;
create_argocd_application(argocd_url.as_str(), argocd_token.as_str()).await;
Expand Down Expand Up @@ -160,7 +160,7 @@ async fn rotate_application_sync_timeout() {

let (argocd_port, stop_sender) = open_argocd_server_port_forward(&kubectl).await;

let argocd_url = format!("http://localhost:{}", argocd_port);
let argocd_url = format!("http://localhost:{argocd_port}");

let argocd_token = get_argocd_access_token(&kubectl, argocd_url.as_str()).await;
create_argocd_application(argocd_url.as_str(), argocd_token.as_str()).await;
Expand Down Expand Up @@ -406,7 +406,7 @@ async fn create_argocd_application(argocd_url: &str, auth_token: &str) {
.build()
.expect("Failed to build custom http client for insecure ArgoCD connection");

let url = format!("{}/api/v1/applications", argocd_url);
let url = format!("{argocd_url}/api/v1/applications");

let argocd_application = json!({
"metadata": {
Expand Down Expand Up @@ -443,7 +443,7 @@ async fn create_argocd_application(argocd_url: &str, auth_token: &str) {
loop {
let response = insecure_client
.post(&url)
.header("Authorization", format!("Bearer {}", auth_token))
.header("Authorization", format!("Bearer {auth_token}"))
.json(&argocd_application)
.send()
.await;
Expand Down Expand Up @@ -498,7 +498,7 @@ async fn wait_for_argocd_application_rollout(

let request = client
.get(url.as_str())
.header("Authorization", format!("Bearer {}", argocd_token))
.header("Authorization", format!("Bearer {argocd_token}"))
.build()
.expect("Failed to build ArgoCD sync status request");

Expand Down
18 changes: 6 additions & 12 deletions tests/utilities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub async fn get_kube_client(container: &ContainerAsync<K3s>) -> Client {
.expect("Failed to read kube secure port");
config.clusters.iter_mut().for_each(|cluster| {
if let Some(server) = cluster.cluster.as_mut().and_then(|c| c.server.as_mut()) {
*server = format!("https://127.0.0.1:{}", port)
*server = format!("https://127.0.0.1:{port}")
}
});

Expand Down Expand Up @@ -212,7 +212,7 @@ async fn create_namespace(kubectl: &Client, namespace_name: &str) {
namespaces
.create(&Default::default(), &argocd_namespace)
.await
.expect(format!("Failed to create namespace '{}'", namespace_name).as_str());
.expect(format!("Failed to create namespace '{namespace_name}'").as_str());
}

fn create_singleton_btree(key: &str, value: &str) -> Option<BTreeMap<String, String>> {
Expand Down Expand Up @@ -255,13 +255,7 @@ async fn await_pod_is_running(pods: &Api<Pod>, label_filter: &str, timeout_durat
await_condition(pods.clone(), pod_name.as_str(), is_pod_running()),
)
.await
.expect(
format!(
"Timed out waiting for pod matching filter: {}",
label_filter
)
.as_str(),
);
.expect(format!("Timed out waiting for pod matching filter: {label_filter}",).as_str());
}

async fn get_pod_name_matching_label_filter(pods: &Api<Pod>, label_filter: &str) -> String {
Expand Down Expand Up @@ -371,7 +365,7 @@ pub async fn get_argocd_access_token(kubectl: &Client, argocd_url: &str) -> Stri
.build()
.expect("Failed to build custom http client for insecure ArgoCD connection");

let url = format!("{}/api/v1/session", argocd_url);
let url = format!("{argocd_url}/api/v1/session");
let authentication_information = json!({
"username": "admin",
"password": password
Expand Down Expand Up @@ -402,7 +396,7 @@ pub async fn get_argocd_access_token(kubectl: &Client, argocd_url: &str) -> Stri
pub fn create_vault_client(vault_host: &str, vault_port: u16) -> VaultClient {
VaultClient::new(
VaultClientSettingsBuilder::default()
.address(format!("http://{}:{}", vault_host, vault_port))
.address(format!("http://{vault_host}:{vault_port}"))
.token("root-token")
.build()
.expect("Failed to build vault client settings"),
Expand Down Expand Up @@ -431,7 +425,7 @@ pub async fn read_vault_secret(vault_client: &VaultClient, secret_path: &str) ->

pub fn write_string_to_tempfile(content: &str) -> String {
let mut dir = temp_dir();
let filename = format!("temp_file_{}", random::<u64>());
let filename = format!("temp_file_{suffix}", suffix = random::<u64>());

dir.push(filename);

Expand Down

0 comments on commit 377dc1c

Please sign in to comment.