Skip to content
Draft
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
15 changes: 9 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion linkup-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "linkup-cli"
version = "3.5.0"
edition = "2021"
edition = "2024"
build = "build.rs"

[[bin]]
Expand Down
11 changes: 8 additions & 3 deletions linkup-cli/src/commands/completion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::io::stdout;

use clap::{Command, CommandFactory};
use clap_complete::{generate, Generator, Shell};
use clap_complete::{Generator, Shell, generate};

use crate::{Cli, Result};

Expand All @@ -19,6 +19,11 @@ pub fn completion(args: &Args) -> Result<()> {

Ok(())
}
fn print_completions<G: Generator + Clone>(gen: &G, cmd: &mut Command) {
generate(gen.clone(), cmd, cmd.get_name().to_string(), &mut stdout());
fn print_completions<G: Generator + Clone>(generator: &G, cmd: &mut Command) {
generate(
generator.clone(),
cmd,
cmd.get_name().to_string(),
&mut stdout(),
);
}
27 changes: 13 additions & 14 deletions linkup-cli/src/commands/deploy/api.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use reqwest::{multipart, Client};
use reqwest::{Client, multipart};
use serde::{Deserialize, Serialize};
use serde_json::json;

use super::{
DeployError,
auth::CloudflareApiAuth,
resources::{DNSRecord, Rule, WorkerMetadata, WorkerScriptInfo, WorkerScriptPart},
DeployError,
};

pub trait CloudflareApi {
Expand Down Expand Up @@ -795,20 +795,19 @@ impl CloudflareApi for AccountCloudflareApi {
return Err(DeployError::OtherError);
}

if let Some(records) = data.result {
if let Some(r) = records
if let Some(records) = data.result
&& let Some(r) = records
.into_iter()
.find(|r| r.comment == Some(comment.clone()))
{
return Ok(Some(DNSRecord {
id: r.id,
name: r.name,
record_type: r.record_type,
content: r.content,
comment: comment.clone(),
proxied: r.proxied.unwrap_or(false),
}));
}
{
return Ok(Some(DNSRecord {
id: r.id,
name: r.name,
record_type: r.record_type,
content: r.content,
comment: comment.clone(),
proxied: r.proxied.unwrap_or(false),
}));
}

Ok(None)
Expand Down
15 changes: 9 additions & 6 deletions linkup-cli/src/commands/deploy/cf_deploy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::Result;
use crate::commands::deploy::auth;
use crate::commands::deploy::resources::cf_resources;
use crate::Result;

use super::api::{AccountCloudflareApi, CloudflareApi};
use super::console_notify::ConsoleNotifier;
Expand Down Expand Up @@ -125,7 +125,7 @@ pub async fn deploy_to_cloudflare(
#[cfg(test)]
mod tests {
use cloudflare::framework::{
async_api::Client, auth, endpoint::spec::EndpointSpec, Environment, HttpApiClientConfig,
Environment, HttpApiClientConfig, async_api::Client, auth, endpoint::spec::EndpointSpec,
};
use mockito::ServerGuard;
use std::cell::RefCell;
Expand All @@ -135,8 +135,9 @@ mod tests {
api::Token,
cf_destroy::destroy_from_cloudflare,
resources::{
rules_equal, DNSRecord, KvNamespace, Rule, TargectCfZoneResources, TargetCacheRules,
DNSRecord, KvNamespace, Rule, TargectCfZoneResources, TargetCacheRules,
TargetDNSRecord, TargetWorkerRoute, WorkerMetadata, WorkerScriptInfo, WorkerScriptPart,
rules_equal,
},
};

Expand Down Expand Up @@ -651,9 +652,11 @@ export default {
let dns_records = api.dns_records.borrow();
assert_eq!(dns_records.len(), 1);
assert_eq!(dns_records[0].name, "linkup-integration-test");
assert!(dns_records[0]
.content
.contains("linkup-integration-test-script.workers.dev"));
assert!(
dns_records[0]
.content
.contains("linkup-integration-test-script.workers.dev")
);

// Check route created
let routes = api.worker_routes.borrow();
Expand Down
2 changes: 1 addition & 1 deletion linkup-cli/src/commands/deploy/cf_destroy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::Result;
use crate::commands::deploy::{
api::AccountCloudflareApi, auth, console_notify::ConsoleNotifier, resources::cf_resources,
};
use crate::Result;

use super::{api::CloudflareApi, cf_deploy::DeployNotifier, resources::TargetCfResources};

Expand Down
4 changes: 2 additions & 2 deletions linkup-cli/src/commands/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod cf_destroy;
mod console_notify;
mod resources;

pub use cf_deploy::{deploy, DeployArgs, DeployError};
pub use cf_destroy::{destroy, DestroyArgs};
pub use cf_deploy::{DeployArgs, DeployError, deploy};
pub use cf_destroy::{DestroyArgs, destroy};
30 changes: 13 additions & 17 deletions linkup-cli/src/commands/deploy/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use reqwest::StatusCode;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};

use super::{api::CloudflareApi, cf_deploy::DeployNotifier, DeployError};
use super::{DeployError, api::CloudflareApi, cf_deploy::DeployNotifier};

const LINKUP_WORKER_SHIM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/shim.mjs"));
const LINKUP_WORKER_INDEX_WASM: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/index.wasm"));
Expand Down Expand Up @@ -527,7 +527,7 @@ impl TargetCfResources {
let bindings = match client.request(&req).await {
Ok(response) => response.result,
Err(cloudflare::framework::response::ApiFailure::Error(StatusCode::NOT_FOUND, _)) => {
return Ok(None)
return Ok(None);
}
Err(error) => return Err(DeployError::from(error)),
};
Expand All @@ -536,10 +536,10 @@ impl TargetCfResources {
use cloudflare::endpoints::workers::WorkersBinding;

// NOTE(augustoccesar)[2025-02-26]: We are saving WORKER_TOKEN as plain text, so we don't need other binding types
if let WorkersBinding::PlainText { name, text } = binding {
if name == "WORKER_TOKEN" {
return Ok(Some(text));
}
if let WorkersBinding::PlainText { name, text } = binding
&& name == "WORKER_TOKEN"
{
return Ok(Some(text));
}
}

Expand Down Expand Up @@ -642,25 +642,21 @@ impl TargetCfResources {
name,
namespace_id,
} = binding
&& *name == kv_namespace.binding
{
if *name == kv_namespace.binding {
*namespace_id = kv_ns_id.clone();
break;
}
*namespace_id = kv_ns_id.clone();
break;
}
}
}

if let Some(token) = token {
for binding in final_metadata.bindings.iter_mut() {
if let cloudflare::endpoints::workers::WorkersBinding::SecretText {
name,
text,
} = binding
if let cloudflare::endpoints::workers::WorkersBinding::SecretText { name, text } =
binding
&& *name == "CLOUDFLARE_API_TOKEN"
{
if *name == "CLOUDFLARE_API_TOKEN" {
*text = Some(token.clone());
}
*text = Some(token.clone());
}
}
}
Expand Down
Loading
Loading