This commit is contained in:
Robin Appelman 2023-06-03 16:09:04 +02:00
commit 38f3b96e35
5 changed files with 38 additions and 18 deletions

View file

@ -4,7 +4,6 @@ name: CI
jobs:
check:
name: Check
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
@ -16,6 +15,19 @@ jobs:
authToken: '${{ secrets.ATTIC_TOKEN }}'
- 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:
runs-on: ubuntu-latest
needs: check

View file

@ -50,6 +50,21 @@
cargoBuild = _: ''cargo $cargo_options check $cargo_build_options >> $cargo_build_output_json'';
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 {
name = "spiretf/dispenser";
tag = "latest";

View file

@ -125,7 +125,7 @@ impl Vultr {
.applications
.into_iter()
.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(|| {
ResponseError::Other(format!("Application \"{}\" not found", short_name))

View file

@ -73,9 +73,7 @@ where
D: Deserializer<'de>,
{
let raw = <Option<String>>::deserialize(deserializer)?;
raw.map(load_secret)
.transpose()
.map_err(|e| D::Error::custom(e))
raw.map(load_secret).transpose().map_err(D::Error::custom)
}
fn deserialize_secret<'de, D>(deserializer: D) -> Result<String, D::Error>
@ -83,12 +81,12 @@ where
D: Deserializer<'de>,
{
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> {
let path: &Path = raw.as_ref();
if raw.starts_with("/") && path.exists() {
if raw.starts_with('/') && path.exists() {
let raw = read_to_string(raw)?;
Ok(raw.trim().into())
} else {

View file

@ -35,7 +35,7 @@ struct Args {
config: String,
}
#[derive(Subcommand)]
#[derive(Subcommand, Default)]
enum Commands {
/// Start a new server if none is running
Start,
@ -44,15 +44,10 @@ enum Commands {
/// List running servers
List,
/// Run the management daemon
#[default]
Daemon,
}
impl Default for Commands {
fn default() -> Self {
Commands::Daemon
}
}
#[derive(Debug, Error)]
pub enum Error {
#[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) {
let dns = DynDnsClient::new(
dns_config.update_url.to_string(),
dns_config.username.to_string(),
dns_config.password.to_string(),
dns_config.update_url,
dns_config.username,
dns_config.password,
);
println!(
"Updating DynDNS entry for {} to {}",
@ -380,7 +375,7 @@ async fn connect_ssh(ip: IpAddr, auth: &CreatedAuth) -> Result<SshSession, Error
tries += 1;
sleep(Duration::from_secs(5)).await;
match SshSession::open(ip, &auth).await {
match SshSession::open(ip, auth).await {
Ok(ssh) => {
return Ok(ssh);
}