Skip to content

Commit

Permalink
Sogar update (#168)
Browse files Browse the repository at this point in the history
* sogar update + avoid delete file when we push videos to a registry + log improvement

* cargo fmt
  • Loading branch information
fdubois1 authored Jul 14, 2021
1 parent 8aec9a9 commit 80d20e8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

17 changes: 7 additions & 10 deletions devolutions-gateway/src/http/controllers/sogar_token.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
use crate::config::{Config, SogarUser};
use picky::{
jose::{jws::JwsAlg, jwt::JwtSig},
key::PrivateKey,
};
use saphir::{
controller::Controller,
http::{Method, StatusCode},
macros::controller,
prelude::Request,
};
use picky::jose::jws::JwsAlg;
use picky::jose::jwt::JwtSig;
use picky::key::PrivateKey;
use saphir::controller::Controller;
use saphir::http::{Method, StatusCode};
use saphir::macros::controller;
use saphir::prelude::Request;
use serde::{Deserialize, Serialize};
use slog_scope::error;
use sogar_core::AccessToken;
Expand Down
11 changes: 6 additions & 5 deletions devolutions-gateway/src/http/middlewares/sogar_auth.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::{
config::{Config, SogarPermission, SogarUser},
http::middlewares::auth::{parse_auth_header, AuthHeaderType},
};
use crate::config::{Config, SogarPermission, SogarUser};
use crate::http::middlewares::auth::{parse_auth_header, AuthHeaderType};
use picky::jose::jwt::{JwtSig, JwtValidator};
use saphir::{http, http_context::State, prelude::*, response::Builder as ResponseBuilder};
use saphir::http;
use saphir::http_context::State;
use saphir::prelude::*;
use saphir::response::Builder as ResponseBuilder;
use slog_scope::error;
use sogar_core::registry::{
BLOB_DOWNLOAD_ENDPOINT, BLOB_EXIST_ENDPOINT, BLOB_GET_LOCATION_ENDPOINT, BLOB_UPLOAD_ENDPOINT,
Expand Down
25 changes: 10 additions & 15 deletions devolutions-gateway/src/registry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
mod push_files;

use crate::config::Config;
use crate::http::http_server::{NAMESPACE, REGISTRY_NAME};
use crate::registry::push_files::{get_file_list_from_path, SogarData};
use crate::{
config::Config,
http::http_server::{NAMESPACE, REGISTRY_NAME},
};
use slog_scope::{debug, error};
use sogar_core::{create_annotation_for_filename, parse_digest, read_file_data, registry, FileInfo, Layer};
use std::{
fs,
path::{Path, PathBuf},
sync::Arc,
thread,
time::Duration,
};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
use std::{fs, thread};
use tempfile::NamedTempFile;

pub struct Registry {
Expand Down Expand Up @@ -57,12 +52,12 @@ impl Registry {
}

if let Some(true) = config.keep_files {
thread::spawn(move || {
if let Some(duration) = config.keep_time {
if let Some(duration) = config.keep_time {
thread::spawn(move || {
thread::sleep(Duration::from_secs(duration as u64));
remove_files(files);
}
});
});
}
} else {
remove_files(files);
}
Expand Down
10 changes: 4 additions & 6 deletions devolutions-gateway/src/registry/push_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ impl SogarData {
let reference = format!("{}:{}", self.image_name, tag);
let joined_path: &str = &file_paths.join(";");
self.invoke_command(joined_path, reference);
for filepath in file_paths {
if let Err(e) = fs::remove_file(filepath.as_str()) {
error!("Failed to delete file {} after push: {}", filepath, e);
}
}
}

fn invoke_command(&self, file_path: &str, reference: String) {
if self.sogar_path.to_str().is_none() || !self.sogar_path.is_file() {
error!("Failed to retrieve path string or path is not a file.");
error!(
"Failed to retrieve path string or path is not a file: {}",
self.sogar_path.display()
);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion devolutions-gateway/src/utils/association.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn remove_jet_association(
}
}
if !association.is_connected() {
debug!("Association is removed!");
debug!("Association {} is removed!", association_id);
let removed = jet_associations.remove(&association_id).is_some();
return removed;
} else {
Expand Down

0 comments on commit 80d20e8

Please sign in to comment.