mirror of
https://codeberg.org/spire/dispenser.git
synced 2026-06-03 10:04:07 +02:00
clippy
This commit is contained in:
parent
76ba9682a5
commit
38f3b96e35
5 changed files with 38 additions and 18 deletions
14
.github/workflows/ci.yml
vendored
14
.github/workflows/ci.yml
vendored
|
|
@ -4,7 +4,6 @@ name: CI
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: Check
|
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
@ -16,6 +15,19 @@ jobs:
|
||||||
authToken: '${{ secrets.ATTIC_TOKEN }}'
|
authToken: '${{ secrets.ATTIC_TOKEN }}'
|
||||||
- run: nix build .#check
|
- run: nix build .#check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
needs: check
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: cachix/install-nix-action@v20
|
||||||
|
- uses: icewind1991/attic-action@v1
|
||||||
|
with:
|
||||||
|
name: ci
|
||||||
|
instance: https://cache.icewind.me
|
||||||
|
authToken: '${{ secrets.ATTIC_TOKEN }}'
|
||||||
|
- run: nix build .#clippy
|
||||||
|
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: check
|
needs: check
|
||||||
|
|
|
||||||
15
flake.nix
15
flake.nix
|
|
@ -50,6 +50,21 @@
|
||||||
cargoBuild = _: ''cargo $cargo_options check $cargo_build_options >> $cargo_build_output_json'';
|
cargoBuild = _: ''cargo $cargo_options check $cargo_build_options >> $cargo_build_output_json'';
|
||||||
root = src;
|
root = src;
|
||||||
};
|
};
|
||||||
|
clippy = (naerskForTarget hostTarget).buildPackage {
|
||||||
|
pname = "dispenser";
|
||||||
|
cargoBuild = _: ''cargo $cargo_options clippy -j "$NIX_BUILD_CORES" --message-format=$cargo_message_format -- -A all >> $cargo_build_output_json'';
|
||||||
|
overrideMain = cfg: cfg // {
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
export SOURCE_DATE_EPOCH=1
|
||||||
|
|
||||||
|
logRun cargo $cargo_options clippy -j "$NIX_BUILD_CORES" -- -D warnings
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
root = src;
|
||||||
|
};
|
||||||
dockerImage = pkgs.dockerTools.buildImage {
|
dockerImage = pkgs.dockerTools.buildImage {
|
||||||
name = "spiretf/dispenser";
|
name = "spiretf/dispenser";
|
||||||
tag = "latest";
|
tag = "latest";
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ impl Vultr {
|
||||||
.applications
|
.applications
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find_map(|application| {
|
.find_map(|application| {
|
||||||
(application.short_name == short_name).then(|| application.image_id)
|
(application.short_name == short_name).then_some(application.image_id)
|
||||||
})
|
})
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
ResponseError::Other(format!("Application \"{}\" not found", short_name))
|
ResponseError::Other(format!("Application \"{}\" not found", short_name))
|
||||||
|
|
|
||||||
|
|
@ -73,9 +73,7 @@ where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let raw = <Option<String>>::deserialize(deserializer)?;
|
let raw = <Option<String>>::deserialize(deserializer)?;
|
||||||
raw.map(load_secret)
|
raw.map(load_secret).transpose().map_err(D::Error::custom)
|
||||||
.transpose()
|
|
||||||
.map_err(|e| D::Error::custom(e))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_secret<'de, D>(deserializer: D) -> Result<String, D::Error>
|
fn deserialize_secret<'de, D>(deserializer: D) -> Result<String, D::Error>
|
||||||
|
|
@ -83,12 +81,12 @@ where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let raw = String::deserialize(deserializer)?;
|
let raw = String::deserialize(deserializer)?;
|
||||||
load_secret(raw).map_err(|e| D::Error::custom(e))
|
load_secret(raw).map_err(D::Error::custom)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_secret(raw: String) -> Result<String, std::io::Error> {
|
fn load_secret(raw: String) -> Result<String, std::io::Error> {
|
||||||
let path: &Path = raw.as_ref();
|
let path: &Path = raw.as_ref();
|
||||||
if raw.starts_with("/") && path.exists() {
|
if raw.starts_with('/') && path.exists() {
|
||||||
let raw = read_to_string(raw)?;
|
let raw = read_to_string(raw)?;
|
||||||
Ok(raw.trim().into())
|
Ok(raw.trim().into())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
17
src/main.rs
17
src/main.rs
|
|
@ -35,7 +35,7 @@ struct Args {
|
||||||
config: String,
|
config: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand, Default)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
/// Start a new server if none is running
|
/// Start a new server if none is running
|
||||||
Start,
|
Start,
|
||||||
|
|
@ -44,15 +44,10 @@ enum Commands {
|
||||||
/// List running servers
|
/// List running servers
|
||||||
List,
|
List,
|
||||||
/// Run the management daemon
|
/// Run the management daemon
|
||||||
|
#[default]
|
||||||
Daemon,
|
Daemon,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Commands {
|
|
||||||
fn default() -> Self {
|
|
||||||
Commands::Daemon
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Error while interacting with cloud provider: {0}")]
|
#[error("Error while interacting with cloud provider: {0}")]
|
||||||
|
|
@ -360,9 +355,9 @@ async fn start(cloud: &dyn Cloud, config: &Config) -> Result<Server, Error> {
|
||||||
|
|
||||||
async fn set_dyndns(dns_config: DynDnsConfig, ip: IpAddr) {
|
async fn set_dyndns(dns_config: DynDnsConfig, ip: IpAddr) {
|
||||||
let dns = DynDnsClient::new(
|
let dns = DynDnsClient::new(
|
||||||
dns_config.update_url.to_string(),
|
dns_config.update_url,
|
||||||
dns_config.username.to_string(),
|
dns_config.username,
|
||||||
dns_config.password.to_string(),
|
dns_config.password,
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"Updating DynDNS entry for {} to {}",
|
"Updating DynDNS entry for {} to {}",
|
||||||
|
|
@ -380,7 +375,7 @@ async fn connect_ssh(ip: IpAddr, auth: &CreatedAuth) -> Result<SshSession, Error
|
||||||
tries += 1;
|
tries += 1;
|
||||||
sleep(Duration::from_secs(5)).await;
|
sleep(Duration::from_secs(5)).await;
|
||||||
|
|
||||||
match SshSession::open(ip, &auth).await {
|
match SshSession::open(ip, auth).await {
|
||||||
Ok(ssh) => {
|
Ok(ssh) => {
|
||||||
return Ok(ssh);
|
return Ok(ssh);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue