Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ed1d00a32 | ||
|
|
a3901c7a8e |
@@ -0,0 +1,73 @@
|
|||||||
|
name: simodels Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
name: Check
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: cargo check
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test Suite
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: cargo test
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
name: Rustfmt
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add rustfmt
|
||||||
|
- run: cargo fmt --all -- --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
name: Clippy
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add clippy
|
||||||
|
- run: cargo clippy -- -D warnings
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: build
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.97
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: cargo build
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
name: labyrinth release Tagging
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Important for git describe --tags
|
||||||
|
|
||||||
|
- name: Install Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.97
|
||||||
|
components: cargo
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
|
||||||
|
- name: Extract Version from Cargo.toml
|
||||||
|
id: version
|
||||||
|
run: |
|
||||||
|
VERSION=$(grep '^version = "' Cargo.toml | sed -E 's/version = "([^"]+)"/\1/')
|
||||||
|
PROJECT_COMMIT_HASH=$(git rev-parse HEAD | cut -c 1-10)
|
||||||
|
BRANCH_REF="${{ gitea.ref }}"
|
||||||
|
BRANCH_NAME=$(echo "$BRANCH_REF" | cut -d '/' -f 3)
|
||||||
|
PROJECT_TAG_RELEASE="v$VERSION-$BRANCH_NAME-$PROJECT_COMMIT_HASH-928"
|
||||||
|
|
||||||
|
echo "::set-output name=project_tag_release::$PROJECT_TAG_RELEASE"
|
||||||
|
|
||||||
|
echo "Version: $VERSION"
|
||||||
|
echo "Hash: $PROJECT_COMMIT_HASH"
|
||||||
|
echo "Branh ref: $BRANCH_REF"
|
||||||
|
echo "Branch: $BRANCH_NAME"
|
||||||
|
echo "Tag Release: $PROJECT_TAG_RELEASE"
|
||||||
|
|
||||||
|
- name: Print version
|
||||||
|
id: Version
|
||||||
|
run: |
|
||||||
|
echo "Printing version"
|
||||||
|
echo "Version: ${{ steps.version.outputs.project_tag_release }}"
|
||||||
|
|
||||||
|
- name: Create GitHub Release
|
||||||
|
uses: actions/create-release@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
tag_name: ${{ steps.version.outputs.project_tag_release }}
|
||||||
|
release_name: Release ${{ steps.version.outputs.project_tag_release }}
|
||||||
|
body: |
|
||||||
|
Release of version ${{ steps.version.outputs.project_tag_release }}
|
||||||
Generated
+1
-1
@@ -1370,7 +1370,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "labyrinth"
|
name = "labyrinth"
|
||||||
version = "0.0.1"
|
version = "0.0.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aws-config",
|
"aws-config",
|
||||||
"aws-sdk-s3",
|
"aws-sdk-s3",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "labyrinth"
|
name = "labyrinth"
|
||||||
version = "0.0.1"
|
version = "0.0.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
description = "Library for managing soaricarus storage"
|
description = "Library for managing soaricarus storage"
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2025 Kun Deng
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
|
#[derive(Debug, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub bucket: String,
|
pub bucket: String,
|
||||||
pub region: String,
|
pub region: String,
|
||||||
|
pub access_key_id: String,
|
||||||
|
pub secret_key: String,
|
||||||
}
|
}
|
||||||
|
|||||||
+56
-4
@@ -1,6 +1,8 @@
|
|||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
#[derive(Default)]
|
use aws_sdk_s3::config::{Credentials, Region};
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
pub struct Data {
|
pub struct Data {
|
||||||
pub filepath: String,
|
pub filepath: String,
|
||||||
pub raw_data: Vec<u8>,
|
pub raw_data: Vec<u8>,
|
||||||
@@ -14,6 +16,31 @@ pub async fn load_data(filepath: &str) -> Result<Vec<u8>, std::io::Error> {
|
|||||||
tokio::fs::read(filepath).await
|
tokio::fs::read(filepath).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn init_client(config: &config::Config) -> aws_sdk_s3::Client {
|
||||||
|
let credentials = Credentials::new(
|
||||||
|
config.access_key_id.clone(),
|
||||||
|
config.secret_key.clone(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"maze",
|
||||||
|
);
|
||||||
|
|
||||||
|
let region = Region::new(config.region.to_string());
|
||||||
|
let config = aws_config::from_env()
|
||||||
|
.region(region)
|
||||||
|
.credentials_provider(credentials)
|
||||||
|
.endpoint_url(config.url.clone())
|
||||||
|
.load()
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let s3_config = aws_sdk_s3::config::Builder::from(&config)
|
||||||
|
.force_path_style(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
aws_sdk_s3::Client::from_conf(s3_config)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Info(String),
|
Info(String),
|
||||||
SError(aws_sdk_s3::operation::put_object::PutObjectError),
|
SError(aws_sdk_s3::operation::put_object::PutObjectError),
|
||||||
@@ -25,9 +52,7 @@ impl Labyrinth {
|
|||||||
file_key: &str,
|
file_key: &str,
|
||||||
data: &Data,
|
data: &Data,
|
||||||
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
|
) -> Result<aws_sdk_s3::operation::put_object::PutObjectOutput, Error> {
|
||||||
let config = aws_config::load_from_env().await;
|
let client = init_client(&self.config).await;
|
||||||
let client = aws_sdk_s3::Client::new(&config);
|
|
||||||
|
|
||||||
let data_content = if data.raw_data.is_empty() {
|
let data_content = if data.raw_data.is_empty() {
|
||||||
match load_data(&data.filepath).await {
|
match load_data(&data.filepath).await {
|
||||||
Ok(content) => content,
|
Ok(content) => content,
|
||||||
@@ -51,4 +76,31 @@ impl Labyrinth {
|
|||||||
Err(err) => Err(Error::Info(err.to_string())),
|
Err(err) => Err(Error::Info(err.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn download(&self, file_key: &str) -> Result<Vec<u8>, Error> {
|
||||||
|
let client = init_client(&self.config).await;
|
||||||
|
|
||||||
|
match client
|
||||||
|
.get_object()
|
||||||
|
.bucket(self.config.bucket.clone())
|
||||||
|
.key(file_key)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(response) => {
|
||||||
|
let body = response.body;
|
||||||
|
|
||||||
|
// Get the body as ByteStream
|
||||||
|
match body.collect().await {
|
||||||
|
Ok(data) => {
|
||||||
|
let bytes = data.into_bytes();
|
||||||
|
let raw_data = bytes.to_vec();
|
||||||
|
Ok(raw_data)
|
||||||
|
}
|
||||||
|
Err(err) => Err(Error::Info(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(Error::Info(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user