Skip to content

Commit a41bf39

Browse files
committed
Fix github actions and add files tagging
Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent 299c6d2 commit a41bf39

4 files changed

Lines changed: 32 additions & 15 deletions

File tree

.github/workflows/docker.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ jobs:
3434
run: echo "${{ github.actor }}" > github_username.txt
3535
- name: Set name of docker image on staging
3636
if: ${{ github.event.inputs.environment == 'staging' }}
37-
run: echo "ghcr.io/${{ github.actor }}/kernelci-storage:staging" > image_name.txt
37+
run: echo "ghcr.io/${{ github.repository_owner }}/kernelci-storage:staging" > image_name.txt
3838
- name: Set name of docker image on production
3939
if: ${{ github.event.inputs.environment == 'production' }}
40-
run: echo "ghcr.io/${{ github.actor }}/kernelci-storage:latest" > image_name.txt
40+
run: echo "ghcr.io/${{ github.repository_owner }}/kernelci-storage:latest" > image_name.txt
4141
- name: Set up Docker Buildx
4242
uses: docker/setup-buildx-action@v3
4343
- name: Login to ghcr.io

src/azure.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn calculate_checksum(filename: &String, data: &[u8]) {
7171

7272
/// Write file to Azure blob storage
7373
/// TBD: Rework, do not keep whole file as Vec<u8> in memory!!!
74-
async fn write_file_to_blob(filename: String, data: Vec<u8>, cont_type: String) -> &'static str {
74+
async fn write_file_to_blob(filename: String, data: Vec<u8>, cont_type: String, owner_email: Option<String>) -> &'static str {
7575
let azure_cfg = Arc::new(get_azure_credentials("azure"));
7676

7777
let storage_account = azure_cfg.account.as_str();
@@ -145,6 +145,20 @@ async fn write_file_to_blob(filename: String, data: Vec<u8>, cont_type: String)
145145
eprintln!("Error getting blob URL: {:?}", e);
146146
}
147147
}
148+
149+
// Set owner tag if email is provided
150+
if let Some(email) = owner_email {
151+
let mut tags = Tags::new();
152+
tags.insert("owner".to_string(), email);
153+
match blob_client.set_tags(tags).await {
154+
Ok(_) => {
155+
debug_log!("Owner tag set successfully");
156+
}
157+
Err(e) => {
158+
eprintln!("Error setting owner tag: {:?}", e);
159+
}
160+
}
161+
}
148162
}
149163
Err(e) => {
150164
eprintln!("Error uploading block list: {:?}", e);
@@ -371,12 +385,12 @@ async fn azure_list_files(directory: String) -> Vec<String> {
371385

372386
/// Implement Driver trait for AzureDriver
373387
impl super::Driver for AzureDriver {
374-
fn write_file(&self, filename: String, data: Vec<u8>, cont_type: String) -> String {
388+
fn write_file(&self, filename: String, data: Vec<u8>, cont_type: String, owner_email: Option<String>) -> String {
375389
let filenameret = filename.clone();
376390
/* Call async write_file_to_blob use tokio::task::block_in_place */
377391
tokio::task::block_in_place(|| {
378392
let rt = tokio::runtime::Runtime::new().unwrap();
379-
rt.block_on(write_file_to_blob(filename, data, cont_type));
393+
rt.block_on(write_file_to_blob(filename, data, cont_type, owner_email));
380394
});
381395
filenameret
382396
}

src/local.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn calculate_checksum(filename: &str, data: &[u8]) {
101101
}
102102

103103
/// Write file to local storage
104-
fn write_file_to_local(filename: String, data: Vec<u8>, cont_type: String) -> Result<String, String> {
104+
fn write_file_to_local(filename: String, data: Vec<u8>, cont_type: String, owner_email: Option<String>) -> Result<String, String> {
105105
let file_path = get_storage_file_path(&filename);
106106

107107
// Ensure directory structure exists
@@ -122,11 +122,14 @@ fn write_file_to_local(filename: String, data: Vec<u8>, cont_type: String) -> Re
122122
}
123123
}
124124

125-
// Create and write metadata (headers)
125+
// Create and write metadata (headers and owner tag)
126126
let metadata_path = get_metadata_file_path(&filename);
127127
if let Ok(mut metadata_file) = File::create(&metadata_path) {
128-
let headers_content = format!("content-type:{}\n", cont_type);
129-
let _ = metadata_file.write_all(headers_content.as_bytes());
128+
let mut metadata_content = format!("content-type:{}\n", cont_type);
129+
if let Some(email) = owner_email {
130+
metadata_content.push_str(&format!("tag-owner:{}\n", email));
131+
}
132+
let _ = metadata_file.write_all(metadata_content.as_bytes());
130133
}
131134

132135
debug_log!("File written to local storage: {}", file_path.display());
@@ -266,8 +269,8 @@ fn set_tags_for_local_file(filename: String, user_tags: Vec<(String, String)>) -
266269

267270
/// Implement Driver trait for LocalDriver
268271
impl super::Driver for LocalDriver {
269-
fn write_file(&self, filename: String, data: Vec<u8>, cont_type: String) -> String {
270-
match write_file_to_local(filename.clone(), data, cont_type) {
272+
fn write_file(&self, filename: String, data: Vec<u8>, cont_type: String, owner_email: Option<String>) -> String {
273+
match write_file_to_local(filename.clone(), data, cont_type, owner_email) {
271274
Ok(_) => filename,
272275
Err(e) => {
273276
eprintln!("Local storage write error: {}", e);

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct ReceivedFile {
104104
}
105105

106106
trait Driver {
107-
fn write_file(&self, filename: String, data: Vec<u8>, cont_type: String) -> String;
107+
fn write_file(&self, filename: String, data: Vec<u8>, cont_type: String, owner_email: Option<String>) -> String;
108108
fn get_file(&self, filename: String) -> ReceivedFile;
109109
fn tag_file(
110110
&self,
@@ -492,7 +492,7 @@ async fn ax_post_file(headers: HeaderMap, State(state): State<AppState>, mut mul
492492
};
493493

494494
// TBD
495-
let message = write_file_driver(full_path, file0, content_type.to_string());
495+
let message = write_file_driver(full_path, file0, content_type.to_string(), Some(owner));
496496
if !message.is_empty() {
497497
return (StatusCode::CONFLICT, Vec::new());
498498
}
@@ -711,10 +711,10 @@ fn driver_get_file(filepath: String) -> ReceivedFile {
711711
driver.get_file(filepath)
712712
}
713713

714-
fn write_file_driver(filename: String, data: Vec<u8>, cont_type: String) -> String {
714+
fn write_file_driver(filename: String, data: Vec<u8>, cont_type: String, owner_email: Option<String>) -> String {
715715
let driver_name = get_driver_type();
716716
let driver = init_driver(&driver_name);
717-
driver.write_file(filename, data, cont_type);
717+
driver.write_file(filename, data, cont_type, owner_email);
718718
"".to_string()
719719
}
720720

0 commit comments

Comments
 (0)