forked from github-starred/komodo
implement core pass tokens
This commit is contained in:
@@ -147,6 +147,7 @@ impl Resolve<RunBuild, User> for State {
|
||||
res = periphery
|
||||
.request(api::git::CloneRepo {
|
||||
args: (&build).into(),
|
||||
github_token: None,
|
||||
}) => res,
|
||||
_ = cancel.cancelled() => {
|
||||
info!("build cancelled during clone, cleaning up builder");
|
||||
@@ -178,6 +179,7 @@ impl Resolve<RunBuild, User> for State {
|
||||
res = periphery
|
||||
.request(api::build::Build {
|
||||
build: build.clone(),
|
||||
docker_token: None,
|
||||
}) => res.context("failed at call to periphery to build"),
|
||||
_ = cancel.cancelled() => {
|
||||
info!("build cancelled during build, cleaning up builder");
|
||||
|
||||
@@ -107,6 +107,7 @@ impl Resolve<Deploy, User> for State {
|
||||
deployment,
|
||||
stop_signal,
|
||||
stop_time,
|
||||
docker_token: None,
|
||||
})
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -77,6 +77,7 @@ impl Resolve<CloneRepo, User> for State {
|
||||
let logs = match periphery
|
||||
.request(api::git::CloneRepo {
|
||||
args: (&repo).into(),
|
||||
github_token: None,
|
||||
})
|
||||
.await
|
||||
{
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
use async_trait::async_trait;
|
||||
use monitor_client::entities::{
|
||||
optional_string, server::docker_image::ImageSummary, update::Log,
|
||||
server::docker_image::ImageSummary, update::Log,
|
||||
};
|
||||
use periphery_client::api::build::{
|
||||
Build, GetImageList, PruneImages,
|
||||
};
|
||||
use resolver_api::Resolve;
|
||||
use serror::serialize_error_pretty;
|
||||
|
||||
use crate::{
|
||||
helpers::{
|
||||
docker::{self, client::docker_client},
|
||||
get_docker_token,
|
||||
},
|
||||
helpers::docker::{self, client::docker_client},
|
||||
State,
|
||||
};
|
||||
|
||||
@@ -21,23 +17,13 @@ impl Resolve<Build> for State {
|
||||
#[instrument(name = "Build", skip(self))]
|
||||
async fn resolve(
|
||||
&self,
|
||||
Build { build }: Build,
|
||||
Build {
|
||||
build,
|
||||
docker_token,
|
||||
}: Build,
|
||||
_: (),
|
||||
) -> anyhow::Result<Vec<Log>> {
|
||||
let log = match get_docker_token(&optional_string(
|
||||
&build.config.docker_account,
|
||||
)) {
|
||||
Ok(docker_token) => {
|
||||
match docker::build::build(&build, docker_token).await {
|
||||
Ok(logs) => logs,
|
||||
Err(e) => {
|
||||
vec![Log::error("build", serialize_error_pretty(&e))]
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => vec![Log::error("build", serialize_error_pretty(&e))],
|
||||
};
|
||||
Ok(log)
|
||||
docker::build::build(&build, docker_token).await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use anyhow::{anyhow, Context};
|
||||
use anyhow::anyhow;
|
||||
use monitor_client::entities::{
|
||||
deployment::{ContainerSummary, DockerContainerStats},
|
||||
update::Log,
|
||||
@@ -203,25 +203,23 @@ impl Resolve<Deploy> for State {
|
||||
&self,
|
||||
Deploy {
|
||||
deployment,
|
||||
docker_token,
|
||||
stop_signal,
|
||||
stop_time,
|
||||
}: Deploy,
|
||||
_: (),
|
||||
) -> anyhow::Result<Log> {
|
||||
let log = tokio::spawn(async move {
|
||||
docker::container::deploy(
|
||||
&deployment,
|
||||
stop_signal
|
||||
.unwrap_or(deployment.config.termination_signal)
|
||||
.into(),
|
||||
stop_time
|
||||
.unwrap_or(deployment.config.termination_timeout)
|
||||
.into(),
|
||||
)
|
||||
.await
|
||||
})
|
||||
.await
|
||||
.context("failed at spawn thread for deploy")?;
|
||||
Ok(log)
|
||||
let res = docker::container::deploy(
|
||||
&deployment,
|
||||
stop_signal
|
||||
.unwrap_or(deployment.config.termination_signal)
|
||||
.into(),
|
||||
stop_time
|
||||
.unwrap_or(deployment.config.termination_timeout)
|
||||
.into(),
|
||||
docker_token,
|
||||
)
|
||||
.await;
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ impl Resolve<CloneRepo> for State {
|
||||
#[instrument(name = "CloneRepo", skip(self))]
|
||||
async fn resolve(
|
||||
&self,
|
||||
CloneRepo { args }: CloneRepo,
|
||||
CloneRepo { args, github_token }: CloneRepo,
|
||||
_: (),
|
||||
) -> anyhow::Result<Vec<Log>> {
|
||||
git::clone(args).await
|
||||
git::clone(args, github_token).await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,12 @@ use monitor_client::entities::{
|
||||
update::Log,
|
||||
EnvironmentVar, Version,
|
||||
};
|
||||
use serror::serialize_error_pretty;
|
||||
|
||||
use crate::{config::periphery_config, helpers::run_monitor_command};
|
||||
use crate::{
|
||||
config::periphery_config,
|
||||
helpers::{get_docker_token, run_monitor_command},
|
||||
};
|
||||
|
||||
use super::{docker_login, parse_extra_args, parse_labels};
|
||||
|
||||
@@ -16,7 +20,7 @@ pub async fn prune_images() -> Log {
|
||||
run_monitor_command("prune images", command).await
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
#[instrument(skip(docker_token))]
|
||||
pub async fn build(
|
||||
Build {
|
||||
name,
|
||||
@@ -39,6 +43,17 @@ pub async fn build(
|
||||
docker_token: Option<String>,
|
||||
) -> anyhow::Result<Vec<Log>> {
|
||||
let mut logs = Vec::new();
|
||||
let docker_token = match (
|
||||
docker_token,
|
||||
get_docker_token(&optional_string(docker_account)),
|
||||
) {
|
||||
(Some(docker_token), _) => Some(docker_token),
|
||||
(None, Ok(docker_token)) => docker_token,
|
||||
(None, Err(e)) => {
|
||||
logs.push(Log::error("build", serialize_error_pretty(&e)));
|
||||
return Ok(logs);
|
||||
}
|
||||
};
|
||||
let name = to_monitor_name(name);
|
||||
let using_account =
|
||||
docker_login(&optional_string(docker_account), &docker_token)
|
||||
|
||||
@@ -178,21 +178,26 @@ async fn pull_image(image: &str) -> Log {
|
||||
run_monitor_command("docker pull", command).await
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
#[instrument(skip(docker_token))]
|
||||
pub async fn deploy(
|
||||
deployment: &Deployment,
|
||||
stop_signal: Option<TerminationSignal>,
|
||||
stop_time: Option<i32>,
|
||||
docker_token: Option<String>,
|
||||
) -> Log {
|
||||
let docker_token = match get_docker_token(&optional_string(
|
||||
&deployment.config.docker_account,
|
||||
)) {
|
||||
Ok(token) => token,
|
||||
Err(e) => {
|
||||
let docker_token = match (
|
||||
docker_token,
|
||||
get_docker_token(&optional_string(
|
||||
&deployment.config.docker_account,
|
||||
)),
|
||||
) {
|
||||
(Some(token), _) => Some(token),
|
||||
(None, Ok(token)) => token,
|
||||
(None, Err(e)) => {
|
||||
return Log::error("docker login", serialize_error_pretty(&e))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
if let Err(e) = docker_login(
|
||||
&optional_string(&deployment.config.docker_account),
|
||||
&docker_token,
|
||||
|
||||
@@ -55,7 +55,10 @@ pub async fn pull(
|
||||
}
|
||||
|
||||
#[instrument]
|
||||
pub async fn clone<T>(clone_args: T) -> anyhow::Result<Vec<Log>>
|
||||
pub async fn clone<T>(
|
||||
clone_args: T,
|
||||
github_token: Option<String>,
|
||||
) -> anyhow::Result<Vec<Log>>
|
||||
where
|
||||
T: Into<CloneArgs> + std::fmt::Debug,
|
||||
{
|
||||
@@ -68,7 +71,12 @@ where
|
||||
github_account,
|
||||
} = clone_args.into();
|
||||
|
||||
let access_token = get_github_token(&github_account)?;
|
||||
let access_token =
|
||||
match (github_token, get_github_token(&github_account)) {
|
||||
(Some(token), _) => Some(token),
|
||||
(None, Ok(token)) => token,
|
||||
(None, Err(e)) => return Err(e),
|
||||
};
|
||||
|
||||
let repo = repo.as_ref().context("build has no repo attached")?;
|
||||
let name = to_monitor_name(&name);
|
||||
|
||||
@@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize};
|
||||
#[response(BuildResponse)]
|
||||
pub struct Build {
|
||||
pub build: monitor_client::entities::build::Build,
|
||||
/// Override docker token with one sent from core.
|
||||
pub docker_token: Option<String>,
|
||||
}
|
||||
|
||||
pub type BuildResponse = Vec<Log>;
|
||||
|
||||
@@ -101,6 +101,8 @@ pub struct PruneContainers {}
|
||||
#[response(Log)]
|
||||
pub struct Deploy {
|
||||
pub deployment: Deployment,
|
||||
/// Override docker token with one sent from core.
|
||||
pub docker_token: Option<String>,
|
||||
pub stop_signal: Option<TerminationSignal>,
|
||||
pub stop_time: Option<i32>,
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize};
|
||||
#[response(Vec<Log>)]
|
||||
pub struct CloneRepo {
|
||||
pub args: CloneArgs,
|
||||
/// Override github token with one sent from core.
|
||||
pub github_token: Option<String>,
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user