thank you clippy now shut up
This commit is contained in:
parent
9777a7ec64
commit
e085f734f8
4 changed files with 10 additions and 11 deletions
|
@ -17,7 +17,7 @@ where
|
||||||
{
|
{
|
||||||
type Rejection = (StatusCode, &'static str);
|
type Rejection = (StatusCode, &'static str);
|
||||||
|
|
||||||
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
|
||||||
if let Some(user_agent) = parts.headers.get(ACCEPT) {
|
if let Some(user_agent) = parts.headers.get(ACCEPT) {
|
||||||
Ok(ExtractAccept(user_agent.clone()))
|
Ok(ExtractAccept(user_agent.clone()))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl From<ContainerInspectResponse> for ContainerInfo {
|
||||||
fn from(value: ContainerInspectResponse) -> Self {
|
fn from(value: ContainerInspectResponse) -> Self {
|
||||||
ContainerInfo {
|
ContainerInfo {
|
||||||
name: value.name.unwrap(),
|
name: value.name.unwrap(),
|
||||||
state: value.state.map(|s| s.status).flatten().unwrap().to_string(),
|
state: value.state.and_then(|s| s.status).unwrap().to_string(),
|
||||||
image: value.image.unwrap(),
|
image: value.image.unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,9 @@ pub enum StackError {
|
||||||
NotFound,
|
NotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<AppError> for StackError {
|
impl From<StackError> for AppError {
|
||||||
fn into(self) -> AppError {
|
fn from(value: StackError) -> Self {
|
||||||
match self {
|
match value {
|
||||||
StackError::NotFound => AppError::Client {
|
StackError::NotFound => AppError::Client {
|
||||||
status: StatusCode::NOT_FOUND,
|
status: StatusCode::NOT_FOUND,
|
||||||
code: "stack-not-found",
|
code: "stack-not-found",
|
||||||
|
|
|
@ -2,12 +2,12 @@ use super::error::StackError;
|
||||||
use crate::http::error::Result;
|
use crate::http::error::Result;
|
||||||
use bollard::{container::ListContainersOptions, service::ContainerSummary, Docker};
|
use bollard::{container::ListContainersOptions, service::ContainerSummary, Docker};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::{collections::HashMap, path::PathBuf};
|
use std::{collections::HashMap, path::Path};
|
||||||
use tokio::fs::{read_dir, try_exists};
|
use tokio::fs::{read_dir, try_exists};
|
||||||
|
|
||||||
const COMPOSE_FILE: &str = "arion-compose.nix";
|
const COMPOSE_FILE: &str = "arion-compose.nix";
|
||||||
|
|
||||||
async fn is_stack(dir: &PathBuf) -> Result<bool> {
|
async fn is_stack(dir: &Path) -> Result<bool> {
|
||||||
Ok(try_exists(dir.join(COMPOSE_FILE)).await?)
|
Ok(try_exists(dir.join(COMPOSE_FILE)).await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ pub async fn get_containers(docker: &Docker, stack_name: &str) -> Result<Vec<Con
|
||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_compose(base_dir: &PathBuf, stack_name: &str) -> Result<String> {
|
pub async fn get_compose(base_dir: &Path, stack_name: &str) -> Result<String> {
|
||||||
let dir = base_dir.join(stack_name);
|
let dir = base_dir.join(stack_name);
|
||||||
if !is_stack(&dir).await? {
|
if !is_stack(&dir).await? {
|
||||||
return Err(StackError::NotFound.into());
|
return Err(StackError::NotFound.into());
|
||||||
|
@ -41,7 +41,7 @@ pub struct StackInfo {
|
||||||
pub active: bool,
|
pub active: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list(base_dir: &PathBuf, docker: &Docker) -> Result<Vec<StackInfo>> {
|
pub async fn list(base_dir: &Path, docker: &Docker) -> Result<Vec<StackInfo>> {
|
||||||
let containers = docker
|
let containers = docker
|
||||||
.list_containers(Some(ListContainersOptions {
|
.list_containers(Some(ListContainersOptions {
|
||||||
all: false,
|
all: false,
|
||||||
|
@ -65,8 +65,7 @@ pub async fn list(base_dir: &PathBuf, docker: &Docker) -> Result<Vec<StackInfo>>
|
||||||
let project = cont
|
let project = cont
|
||||||
.clone()
|
.clone()
|
||||||
.labels
|
.labels
|
||||||
.map(|lab| lab.get("com.docker.compose.project").cloned())
|
.and_then(|lab| lab.get("com.docker.compose.project").cloned())
|
||||||
.flatten()
|
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
name == project
|
name == project
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue