Compare commits
3 Commits
9c5d1bd27f
...
better-ind
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
387ae9f494 | ||
|
|
336e1cfefe | ||
|
|
403e199062 |
@@ -9,7 +9,7 @@ jobs:
|
||||
check:
|
||||
runs-on: docker
|
||||
container:
|
||||
image: hub.nationtech.io/harmony/harmony_composer:latest
|
||||
image: hub.nationtech.io/harmony/harmony_composer:latest@sha256:eb0406fcb95c63df9b7c4b19bc50ad7914dd8232ce98e9c9abef628e07c69386
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
@@ -7,7 +7,7 @@ on:
|
||||
jobs:
|
||||
package_harmony_composer:
|
||||
container:
|
||||
image: hub.nationtech.io/harmony/harmony_composer:latest
|
||||
image: hub.nationtech.io/harmony/harmony_composer:latest@sha256:eb0406fcb95c63df9b7c4b19bc50ad7914dd8232ce98e9c9abef628e07c69386
|
||||
runs-on: dind
|
||||
steps:
|
||||
- name: Checkout code
|
||||
@@ -45,14 +45,14 @@ jobs:
|
||||
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
|
||||
"https://git.nationtech.io/api/v1/repos/nationtech/harmony/releases/tags/snapshot-latest" \
|
||||
| jq -r '.id // empty')
|
||||
|
||||
|
||||
if [ -n "$RELEASE_ID" ]; then
|
||||
# Delete existing release
|
||||
curl -X DELETE \
|
||||
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
|
||||
"https://git.nationtech.io/api/v1/repos/nationtech/harmony/releases/$RELEASE_ID"
|
||||
fi
|
||||
|
||||
|
||||
# Create new release
|
||||
RESPONSE=$(curl -X POST \
|
||||
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
|
||||
@@ -65,7 +65,7 @@ jobs:
|
||||
"prerelease": true
|
||||
}' \
|
||||
"https://git.nationtech.io/api/v1/repos/nationtech/harmony/releases")
|
||||
|
||||
|
||||
echo "RELEASE_ID=$(echo $RESPONSE | jq -r '.id')" >> $GITHUB_ENV
|
||||
|
||||
- name: Upload Linux binary
|
||||
|
||||
236
Cargo.lock
generated
236
Cargo.lock
generated
@@ -378,7 +378,7 @@ dependencies = [
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"serde_urlencoded",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tower-service",
|
||||
@@ -473,7 +473,7 @@ dependencies = [
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -515,12 +515,6 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
|
||||
|
||||
[[package]]
|
||||
name = "cfg_aliases"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||
|
||||
[[package]]
|
||||
name = "chacha20"
|
||||
version = "0.9.1"
|
||||
@@ -1695,11 +1689,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasi 0.14.2+wasi-0.2.4",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1797,7 +1789,6 @@ dependencies = [
|
||||
"env_logger",
|
||||
"fqdn",
|
||||
"futures-util",
|
||||
"harmony-secret-derive",
|
||||
"harmony_macros",
|
||||
"harmony_types",
|
||||
"helm-wrapper-rs",
|
||||
@@ -1838,35 +1829,6 @@ dependencies = [
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "harmony-secret"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"directories",
|
||||
"harmony-secret-derive",
|
||||
"http 1.3.1",
|
||||
"infisical",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"pretty_assertions",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"thiserror 2.0.14",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "harmony-secret-derive"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "harmony_cli"
|
||||
version = "0.1.0"
|
||||
@@ -2000,7 +1962,7 @@ dependencies = [
|
||||
"non-blank-string-rs",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2168,7 +2130,7 @@ dependencies = [
|
||||
"httpdate",
|
||||
"itoa",
|
||||
"pin-project-lite",
|
||||
"socket2 0.5.10",
|
||||
"socket2",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
@@ -2247,7 +2209,6 @@ dependencies = [
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tower-service",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2310,7 +2271,7 @@ dependencies = [
|
||||
"libc",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"socket2 0.5.10",
|
||||
"socket2",
|
||||
"system-configuration 0.6.1",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
@@ -2527,21 +2488,6 @@ version = "2.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
|
||||
|
||||
[[package]]
|
||||
name = "infisical"
|
||||
version = "0.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d97c33b08e22b2f7b9f87a8fc06a7d247442db7bf216ffc6661a74ed8aea658"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"reqwest 0.12.20",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 1.0.69",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inout"
|
||||
version = "0.1.4"
|
||||
@@ -2582,17 +2528,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-uring"
|
||||
version = "0.7.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d93587f37623a1a17d94ef2bc9ada592f5465fe7732084ab7beefabe5c77c0c4"
|
||||
dependencies = [
|
||||
"bitflags 2.9.1",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.11.0"
|
||||
@@ -2686,7 +2621,7 @@ dependencies = [
|
||||
"pest_derive",
|
||||
"regex",
|
||||
"serde_json",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2787,7 +2722,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
"tokio",
|
||||
"tokio-tungstenite",
|
||||
"tokio-util",
|
||||
@@ -2812,7 +2747,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde-value",
|
||||
"serde_json",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2850,7 +2785,7 @@ dependencies = [
|
||||
"pin-project",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
@@ -2962,12 +2897,6 @@ dependencies = [
|
||||
"hashbrown 0.15.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lru-slab"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
|
||||
|
||||
[[package]]
|
||||
name = "md5"
|
||||
version = "0.7.0"
|
||||
@@ -3270,7 +3199,7 @@ dependencies = [
|
||||
"pretty_assertions",
|
||||
"rand 0.8.5",
|
||||
"serde",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 1.0.69",
|
||||
"tokio",
|
||||
"uuid",
|
||||
"xml-rs",
|
||||
@@ -3437,7 +3366,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1db05f56d34358a8b1066f67cbb203ee3e7ed2ba674a6263a1d5ec6db2204323"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
"ucd-trie",
|
||||
]
|
||||
|
||||
@@ -3658,15 +3587,6 @@ dependencies = [
|
||||
"elliptic-curve",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "3.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"
|
||||
dependencies = [
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.95"
|
||||
@@ -3682,61 +3602,6 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9e1dcb320d6839f6edb64f7a4a59d39b30480d4d1765b56873f7c858538a5fe"
|
||||
|
||||
[[package]]
|
||||
name = "quinn"
|
||||
version = "0.11.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "626214629cda6781b6dc1d316ba307189c85ba657213ce642d9c77670f8202c8"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"cfg_aliases",
|
||||
"pin-project-lite",
|
||||
"quinn-proto",
|
||||
"quinn-udp",
|
||||
"rustc-hash",
|
||||
"rustls",
|
||||
"socket2 0.5.10",
|
||||
"thiserror 2.0.14",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quinn-proto"
|
||||
version = "0.11.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49df843a9161c85bb8aae55f101bc0bac8bcafd637a620d9122fd7e0b2f7422e"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"getrandom 0.3.3",
|
||||
"lru-slab",
|
||||
"rand 0.9.1",
|
||||
"ring",
|
||||
"rustc-hash",
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"slab",
|
||||
"thiserror 2.0.14",
|
||||
"tinyvec",
|
||||
"tracing",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quinn-udp"
|
||||
version = "0.5.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcebb1209ee276352ef14ff8732e24cc2b02bbac986cd74a4c81bcb2f9881970"
|
||||
dependencies = [
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"socket2 0.5.10",
|
||||
"tracing",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
@@ -3855,7 +3720,7 @@ checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b"
|
||||
dependencies = [
|
||||
"getrandom 0.2.16",
|
||||
"libredox",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3956,7 +3821,6 @@ dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"encoding_rs",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"h2 0.4.10",
|
||||
@@ -3973,8 +3837,6 @@ dependencies = [
|
||||
"native-tls",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"quinn",
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -3982,7 +3844,6 @@ dependencies = [
|
||||
"sync_wrapper 1.0.2",
|
||||
"tokio",
|
||||
"tokio-native-tls",
|
||||
"tokio-rustls",
|
||||
"tokio-util",
|
||||
"tower",
|
||||
"tower-http",
|
||||
@@ -3992,7 +3853,6 @@ dependencies = [
|
||||
"wasm-bindgen-futures",
|
||||
"wasm-streams",
|
||||
"web-sys",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4156,7 +4016,7 @@ dependencies = [
|
||||
"flurry",
|
||||
"log",
|
||||
"serde",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
]
|
||||
@@ -4182,12 +4042,6 @@ version = "0.1.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "2.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.1"
|
||||
@@ -4287,7 +4141,6 @@ version = "1.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79"
|
||||
dependencies = [
|
||||
"web-time",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
@@ -4726,7 +4579,7 @@ checksum = "297f631f50729c8c99b84667867963997ec0b50f32b2a7dbcab828ef0541e8bb"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"num-traits",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
"time",
|
||||
]
|
||||
|
||||
@@ -4773,16 +4626,6 @@ dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "socket2"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.9.8"
|
||||
@@ -4920,9 +4763,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.105"
|
||||
version = "2.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7bc3fcb250e53458e712715cf74285c1f889686520d79294a9ef3bd7aa1fc619"
|
||||
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -5056,11 +4899,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.14"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b0949c3a6c842cbde3f1686d6eea5a010516deb7085f79db747562d4102f41e"
|
||||
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
|
||||
dependencies = [
|
||||
"thiserror-impl 2.0.14",
|
||||
"thiserror-impl 2.0.12",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5076,9 +4919,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.14"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc5b44b4ab9c2fdd0e0512e6bece8388e214c0749f5862b114cc5b7a25daf227"
|
||||
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -5144,39 +4987,21 @@ dependencies = [
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71"
|
||||
dependencies = [
|
||||
"tinyvec_macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec_macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.47.1"
|
||||
version = "1.45.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038"
|
||||
checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
"io-uring",
|
||||
"libc",
|
||||
"mio 1.0.4",
|
||||
"parking_lot",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"slab",
|
||||
"socket2 0.6.0",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"windows-sys 0.59.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5426,7 +5251,7 @@ dependencies = [
|
||||
"log",
|
||||
"rand 0.9.1",
|
||||
"sha1",
|
||||
"thiserror 2.0.14",
|
||||
"thiserror 2.0.12",
|
||||
"utf-8",
|
||||
]
|
||||
|
||||
@@ -5727,15 +5552,6 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e8983c3ab33d6fb807cfcdad2491c4ea8cbc8ed839181c7dfd9c67c83e261b2"
|
||||
dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
|
||||
@@ -12,8 +12,6 @@ members = [
|
||||
"harmony_cli",
|
||||
"k3d",
|
||||
"harmony_composer",
|
||||
"harmony_secret_derive",
|
||||
"harmony_secret",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
@@ -55,10 +53,6 @@ chrono = "0.4"
|
||||
similar = "2"
|
||||
uuid = { version = "1.11", features = ["v4", "fast-rng", "macro-diagnostics"] }
|
||||
pretty_assertions = "1.4.1"
|
||||
tempfile = "3.20.0"
|
||||
bollard = "0.19.1"
|
||||
base64 = "0.22.1"
|
||||
tar = "0.4.44"
|
||||
lazy_static = "1.5.0"
|
||||
directories = "6.0.0"
|
||||
thiserror = "2.0.14"
|
||||
|
||||
@@ -5,9 +5,6 @@ version.workspace = true
|
||||
readme.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[features]
|
||||
testing = []
|
||||
|
||||
[dependencies]
|
||||
rand = "0.9"
|
||||
hex = "0.4"
|
||||
@@ -38,8 +35,8 @@ serde-value.workspace = true
|
||||
helm-wrapper-rs = "0.4.0"
|
||||
non-blank-string-rs = "1.0.4"
|
||||
k3d-rs = { path = "../k3d" }
|
||||
directories.workspace = true
|
||||
lazy_static.workspace = true
|
||||
directories = "6.0.0"
|
||||
lazy_static = "1.5.0"
|
||||
dockerfile_builder = "0.1.5"
|
||||
temp-file = "0.1.9"
|
||||
convert_case.workspace = true
|
||||
@@ -59,7 +56,7 @@ similar.workspace = true
|
||||
futures-util = "0.3.31"
|
||||
tokio-util = "0.7.15"
|
||||
strum = { version = "0.27.1", features = ["derive"] }
|
||||
tempfile.workspace = true
|
||||
tempfile = "3.20.0"
|
||||
serde_with = "3.14.0"
|
||||
schemars = "0.8.22"
|
||||
kube-derive = "1.1.0"
|
||||
@@ -67,7 +64,6 @@ bollard.workspace = true
|
||||
tar.workspace = true
|
||||
base64.workspace = true
|
||||
once_cell = "1.21.3"
|
||||
harmony-secret-derive = { version = "0.1.0", path = "../harmony_secret_derive" }
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions.workspace = true
|
||||
|
||||
Binary file not shown.
@@ -2,8 +2,6 @@ use log::debug;
|
||||
use once_cell::sync::Lazy;
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
use crate::modules::application::ApplicationFeatureStatus;
|
||||
|
||||
use super::{
|
||||
interpret::{InterpretError, Outcome},
|
||||
topology::TopologyStatus,
|
||||
@@ -32,12 +30,6 @@ pub enum HarmonyEvent {
|
||||
status: TopologyStatus,
|
||||
message: Option<String>,
|
||||
},
|
||||
ApplicationFeatureStateChanged {
|
||||
topology: String,
|
||||
application: String,
|
||||
feature: String,
|
||||
status: ApplicationFeatureStatus,
|
||||
},
|
||||
}
|
||||
|
||||
static HARMONY_EVENT_BUS: Lazy<broadcast::Sender<HarmonyEvent>> = Lazy::new(|| {
|
||||
@@ -47,14 +39,9 @@ static HARMONY_EVENT_BUS: Lazy<broadcast::Sender<HarmonyEvent>> = Lazy::new(|| {
|
||||
});
|
||||
|
||||
pub fn instrument(event: HarmonyEvent) -> Result<(), &'static str> {
|
||||
if cfg!(any(test, feature = "testing")) {
|
||||
let _ = event; // Suppress the "unused variable" warning for `event`
|
||||
Ok(())
|
||||
} else {
|
||||
match HARMONY_EVENT_BUS.send(event) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("send error: no subscribers"),
|
||||
}
|
||||
match HARMONY_EVENT_BUS.send(event) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("send error: no subscribers"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ impl K8sClient {
|
||||
.expect("Couldn't unwrap status");
|
||||
|
||||
if let Some(s) = status.status {
|
||||
debug!("Status: {} - {:?}", s, status.details);
|
||||
debug!("Status: {}", s);
|
||||
if s == "Success" { Ok(()) } else { Err(s) }
|
||||
} else {
|
||||
Err("Couldn't get inner status of pod exec".to_string())
|
||||
|
||||
@@ -28,13 +28,7 @@ use super::{
|
||||
PreparationOutcome, Topology,
|
||||
k8s::K8sClient,
|
||||
oberservability::monitoring::AlertReceiver,
|
||||
tenant::{
|
||||
TenantConfig, TenantManager,
|
||||
k8s::K8sTenantManager,
|
||||
network_policy::{
|
||||
K3dNetworkPolicyStrategy, NetworkPolicyStrategy, NoopNetworkPolicyStrategy,
|
||||
},
|
||||
},
|
||||
tenant::{TenantConfig, TenantManager, k8s::K8sTenantManager},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -256,21 +250,16 @@ impl K8sAnywhereTopology {
|
||||
Ok(Some(state))
|
||||
}
|
||||
|
||||
async fn ensure_k8s_tenant_manager(&self, k8s_state: &K8sState) -> Result<(), String> {
|
||||
async fn ensure_k8s_tenant_manager(&self) -> Result<(), String> {
|
||||
if self.tenant_manager.get().is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.tenant_manager
|
||||
.get_or_try_init(async || -> Result<K8sTenantManager, String> {
|
||||
// TOOD: checker si K8s ou K3d/s tenant manager (ref. issue https://git.nationtech.io/NationTech/harmony/issues/94)
|
||||
let k8s_client = self.k8s_client().await?;
|
||||
let network_policy_strategy: Box<dyn NetworkPolicyStrategy> = match k8s_state.source
|
||||
{
|
||||
K8sSource::LocalK3d => Box::new(K3dNetworkPolicyStrategy::new()),
|
||||
K8sSource::Kubeconfig => Box::new(NoopNetworkPolicyStrategy::new()),
|
||||
};
|
||||
|
||||
Ok(K8sTenantManager::new(k8s_client, network_policy_strategy))
|
||||
Ok(K8sTenantManager::new(k8s_client))
|
||||
})
|
||||
.await?;
|
||||
|
||||
@@ -401,7 +390,7 @@ impl Topology for K8sAnywhereTopology {
|
||||
"no K8s client could be found or installed".to_string(),
|
||||
))?;
|
||||
|
||||
self.ensure_k8s_tenant_manager(k8s_state)
|
||||
self.ensure_k8s_tenant_manager()
|
||||
.await
|
||||
.map_err(PreparationError::new)?;
|
||||
|
||||
|
||||
@@ -20,27 +20,24 @@ use serde::de::DeserializeOwned;
|
||||
use serde_json::json;
|
||||
use tokio::sync::OnceCell;
|
||||
|
||||
use super::{TenantConfig, TenantManager, network_policy::NetworkPolicyStrategy};
|
||||
use super::{TenantConfig, TenantManager};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct K8sTenantManager {
|
||||
k8s_client: Arc<K8sClient>,
|
||||
k8s_tenant_config: Arc<OnceCell<TenantConfig>>,
|
||||
network_policy_strategy: Box<dyn NetworkPolicyStrategy>,
|
||||
}
|
||||
|
||||
impl K8sTenantManager {
|
||||
pub fn new(
|
||||
client: Arc<K8sClient>,
|
||||
network_policy_strategy: Box<dyn NetworkPolicyStrategy>,
|
||||
) -> Self {
|
||||
pub fn new(client: Arc<K8sClient>) -> Self {
|
||||
Self {
|
||||
k8s_client: client,
|
||||
k8s_tenant_config: Arc::new(OnceCell::new()),
|
||||
network_policy_strategy,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl K8sTenantManager {
|
||||
fn get_namespace_name(&self, config: &TenantConfig) -> String {
|
||||
config.name.clone()
|
||||
}
|
||||
@@ -221,6 +218,29 @@ impl K8sTenantManager {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"to": [
|
||||
{
|
||||
"ipBlock": {
|
||||
"cidr": "10.43.0.1/32",
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"to": [
|
||||
{
|
||||
//TODO this ip is from the docker network that k3d is running on
|
||||
//since k3d does not deploy kube-api-server as a pod it needs to ahve the ip
|
||||
//address opened up
|
||||
//need to find a way to automatically detect the ip address from the docker
|
||||
//network
|
||||
"ipBlock": {
|
||||
"cidr": "172.18.0.0/16",
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"to": [
|
||||
{
|
||||
@@ -390,27 +410,12 @@ impl K8sTenantManager {
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for K8sTenantManager {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
k8s_client: self.k8s_client.clone(),
|
||||
k8s_tenant_config: self.k8s_tenant_config.clone(),
|
||||
network_policy_strategy: self.network_policy_strategy.clone_box(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl TenantManager for K8sTenantManager {
|
||||
async fn provision_tenant(&self, config: &TenantConfig) -> Result<(), ExecutorError> {
|
||||
let namespace = self.build_namespace(config)?;
|
||||
let resource_quota = self.build_resource_quota(config)?;
|
||||
|
||||
let network_policy = self.build_network_policy(config)?;
|
||||
let network_policy = self
|
||||
.network_policy_strategy
|
||||
.adjust_policy(network_policy, config);
|
||||
|
||||
let resource_limit_range = self.build_limit_range(config)?;
|
||||
|
||||
self.ensure_constraints(&namespace)?;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
pub mod k8s;
|
||||
mod manager;
|
||||
pub mod network_policy;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::data::Id;
|
||||
pub use manager::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::data::Id;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] // Assuming serde for Scores
|
||||
pub struct TenantConfig {
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
use k8s_openapi::api::networking::v1::{
|
||||
IPBlock, NetworkPolicy, NetworkPolicyEgressRule, NetworkPolicyPeer, NetworkPolicySpec,
|
||||
};
|
||||
|
||||
use super::TenantConfig;
|
||||
|
||||
pub trait NetworkPolicyStrategy: Send + Sync + std::fmt::Debug {
|
||||
fn clone_box(&self) -> Box<dyn NetworkPolicyStrategy>;
|
||||
|
||||
fn adjust_policy(&self, policy: NetworkPolicy, config: &TenantConfig) -> NetworkPolicy;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct NoopNetworkPolicyStrategy {}
|
||||
|
||||
impl NoopNetworkPolicyStrategy {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for NoopNetworkPolicyStrategy {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkPolicyStrategy for NoopNetworkPolicyStrategy {
|
||||
fn clone_box(&self) -> Box<dyn NetworkPolicyStrategy> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
fn adjust_policy(&self, policy: NetworkPolicy, _config: &TenantConfig) -> NetworkPolicy {
|
||||
policy
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct K3dNetworkPolicyStrategy {}
|
||||
|
||||
impl K3dNetworkPolicyStrategy {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for K3dNetworkPolicyStrategy {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl NetworkPolicyStrategy for K3dNetworkPolicyStrategy {
|
||||
fn clone_box(&self) -> Box<dyn NetworkPolicyStrategy> {
|
||||
Box::new(self.clone())
|
||||
}
|
||||
|
||||
fn adjust_policy(&self, policy: NetworkPolicy, _config: &TenantConfig) -> NetworkPolicy {
|
||||
let mut egress = policy
|
||||
.spec
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
.egress
|
||||
.clone()
|
||||
.unwrap_or_default();
|
||||
egress.push(NetworkPolicyEgressRule {
|
||||
to: Some(vec![NetworkPolicyPeer {
|
||||
ip_block: Some(IPBlock {
|
||||
cidr: "172.18.0.0/16".into(), // TODO: query the IP range https://git.nationtech.io/NationTech/harmony/issues/108
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
}]),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
NetworkPolicy {
|
||||
spec: Some(NetworkPolicySpec {
|
||||
egress: Some(egress),
|
||||
..policy.spec.unwrap_or_default()
|
||||
}),
|
||||
..policy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use k8s_openapi::api::networking::v1::{
|
||||
IPBlock, NetworkPolicy, NetworkPolicyEgressRule, NetworkPolicyPeer, NetworkPolicySpec,
|
||||
};
|
||||
|
||||
use super::{K3dNetworkPolicyStrategy, NetworkPolicyStrategy};
|
||||
|
||||
#[test]
|
||||
pub fn should_add_ip_block_for_k3d_harmony_server() {
|
||||
let strategy = K3dNetworkPolicyStrategy::new();
|
||||
|
||||
let policy =
|
||||
strategy.adjust_policy(NetworkPolicy::default(), &super::TenantConfig::default());
|
||||
|
||||
let expected_policy = NetworkPolicy {
|
||||
spec: Some(NetworkPolicySpec {
|
||||
egress: Some(vec![NetworkPolicyEgressRule {
|
||||
to: Some(vec![NetworkPolicyPeer {
|
||||
ip_block: Some(IPBlock {
|
||||
cidr: "172.18.0.0/16".into(),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
}]),
|
||||
..Default::default()
|
||||
}]),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(expected_policy, policy);
|
||||
}
|
||||
}
|
||||
@@ -22,18 +22,12 @@ pub struct OPNSenseFirewall {
|
||||
host: LogicalHost,
|
||||
}
|
||||
|
||||
// TODO figure out a design to have a unique identifiere for this firewall
|
||||
// I think a project identifier would be good enough, then the secrets module configuration will
|
||||
// point to the project's vault and this opnsense modules doesn't need to know anything about it
|
||||
const OPNSENSE_CREDENTIALS: &str = "OPNSENSE_CREDENTIALS";
|
||||
|
||||
impl OPNSenseFirewall {
|
||||
pub fn get_ip(&self) -> IpAddress {
|
||||
self.host.ip
|
||||
}
|
||||
|
||||
pub async fn new(host: LogicalHost, port: Option<u16>, username: &str, password: &str) -> Self {
|
||||
// let credentials = Secrets::get_by_name(OPNSENSE_CREDENTIALS)
|
||||
Self {
|
||||
opnsense_config: Arc::new(RwLock::new(
|
||||
opnsense_config::Config::from_credentials(host.ip, port, username, password).await,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{io::Write, process::Command, sync::Arc};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use log::info;
|
||||
use log::{debug, error};
|
||||
use serde_yaml::Value;
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
@@ -56,11 +56,14 @@ impl<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
||||
chart_url: String,
|
||||
image_name: String,
|
||||
) -> Result<(), String> {
|
||||
// TODO: This works only with local k3d installations, which is fine only for current demo purposes. We assume usage of K8sAnywhereTopology"
|
||||
// https://git.nationtech.io/NationTech/harmony/issues/106
|
||||
error!(
|
||||
"FIXME This works only with local k3d installations, which is fine only for current demo purposes. We assume usage of K8sAnywhereTopology"
|
||||
);
|
||||
|
||||
error!("TODO hardcoded k3d bin path is wrong");
|
||||
let k3d_bin_path = (*HARMONY_DATA_DIR).join("k3d").join("k3d");
|
||||
// --- 1. Import the container image into the k3d cluster ---
|
||||
info!(
|
||||
debug!(
|
||||
"Importing image '{}' into k3d cluster 'harmony'",
|
||||
image_name
|
||||
);
|
||||
@@ -77,7 +80,7 @@ impl<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
||||
}
|
||||
|
||||
// --- 2. Get the kubeconfig for the k3d cluster and write it to a temp file ---
|
||||
info!("Retrieving kubeconfig for k3d cluster 'harmony'");
|
||||
debug!("Retrieving kubeconfig for k3d cluster 'harmony'");
|
||||
let kubeconfig_output = Command::new(&k3d_bin_path)
|
||||
.args(["kubeconfig", "get", "harmony"])
|
||||
.output()
|
||||
@@ -98,7 +101,7 @@ impl<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
||||
let kubeconfig_path = temp_kubeconfig.path().to_str().unwrap();
|
||||
|
||||
// --- 3. Install or upgrade the Helm chart in the cluster ---
|
||||
info!(
|
||||
debug!(
|
||||
"Deploying Helm chart '{}' to namespace '{}'",
|
||||
chart_url, app_name
|
||||
);
|
||||
@@ -128,7 +131,7 @@ impl<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
||||
));
|
||||
}
|
||||
|
||||
info!("Successfully deployed '{}' to local k3d cluster.", app_name);
|
||||
debug!("Successfully deployed '{}' to local k3d cluster.", app_name);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -148,12 +151,14 @@ impl<
|
||||
// Or ask for it when unknown
|
||||
|
||||
let helm_chart = self.application.build_push_helm_package(&image).await?;
|
||||
debug!("Pushed new helm chart {helm_chart}");
|
||||
|
||||
// TODO: Make building image configurable/skippable if image already exists (prompt)")
|
||||
// https://git.nationtech.io/NationTech/harmony/issues/104
|
||||
error!("TODO Make building image configurable/skippable if image already exists (prompt)");
|
||||
let image = self.application.build_push_oci_image().await?;
|
||||
debug!("Pushed new docker image {image}");
|
||||
|
||||
// TODO: this is a temporary hack for demo purposes, the deployment target should be driven
|
||||
debug!("Installing ContinuousDelivery feature");
|
||||
// TODO this is a temporary hack for demo purposes, the deployment target should be driven
|
||||
// by the topology only and we should not have to know how to perform tasks like this for
|
||||
// which the topology should be responsible.
|
||||
//
|
||||
@@ -166,20 +171,17 @@ impl<
|
||||
// access it. This forces every Topology to understand the concept of targets though... So
|
||||
// instead I'll create a new Capability which is MultiTargetTopology and we'll see how it
|
||||
// goes. It still does not feel right though.
|
||||
//
|
||||
// https://git.nationtech.io/NationTech/harmony/issues/106
|
||||
match topology.current_target() {
|
||||
DeploymentTarget::LocalDev => {
|
||||
info!("Deploying {} locally...", self.application.name());
|
||||
self.deploy_to_local_k3d(self.application.name(), helm_chart, image)
|
||||
.await?;
|
||||
}
|
||||
target => {
|
||||
info!("Deploying {} to target {target:?}", self.application.name());
|
||||
debug!("Deploying to target {target:?}");
|
||||
let score = ArgoHelmScore {
|
||||
namespace: "harmony-example-rust-webapp".to_string(),
|
||||
openshift: true,
|
||||
domain: "argo.harmonydemo.apps.ncd0.harmony.mcd".to_string(),
|
||||
namespace: "harmonydemo-staging".to_string(),
|
||||
openshift: false,
|
||||
domain: "argo.harmonydemo.apps.st.mcd".to_string(),
|
||||
argo_apps: vec![ArgoApplication::from(CDApplicationConfig {
|
||||
// helm pull oci://hub.nationtech.io/harmony/harmony-example-rust-webapp-chart --version 0.1.0
|
||||
version: Version::from("0.1.0").unwrap(),
|
||||
@@ -187,7 +189,7 @@ impl<
|
||||
helm_chart_name: "harmony-example-rust-webapp-chart".to_string(),
|
||||
values_overrides: None,
|
||||
name: "harmony-demo-rust-webapp".to_string(),
|
||||
namespace: "harmony-example-rust-webapp".to_string(),
|
||||
namespace: "harmonydemo-staging".to_string(),
|
||||
})],
|
||||
};
|
||||
score
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use async_trait::async_trait;
|
||||
use log::error;
|
||||
use non_blank_string_rs::NonBlankString;
|
||||
use serde::Serialize;
|
||||
use std::str::FromStr;
|
||||
@@ -49,6 +50,7 @@ impl<T: Topology + K8sclient + HelmCommand> Interpret<T> for ArgoInterpret {
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
error!("Uncomment below, only disabled for debugging");
|
||||
self.score.interpret(inventory, topology).await?;
|
||||
|
||||
let k8s_client = topology.k8s_client().await?;
|
||||
@@ -56,14 +58,9 @@ impl<T: Topology + K8sclient + HelmCommand> Interpret<T> for ArgoInterpret {
|
||||
.apply_yaml_many(&self.argo_apps.iter().map(|a| a.to_yaml()).collect(), None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Ok(Outcome::success(format!(
|
||||
"ArgoCD installed with {} {}",
|
||||
self.argo_apps.len(),
|
||||
match self.argo_apps.len() {
|
||||
1 => "application",
|
||||
_ => "applications",
|
||||
}
|
||||
"ArgoCD installed with {} applications",
|
||||
self.argo_apps.len()
|
||||
)))
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ use crate::modules::application::{Application, ApplicationFeature};
|
||||
use crate::modules::monitoring::application_monitoring::application_monitoring_score::ApplicationMonitoringScore;
|
||||
use crate::modules::monitoring::kube_prometheus::crd::crd_alertmanager_config::CRDPrometheus;
|
||||
|
||||
use crate::topology::MultiTargetTopology;
|
||||
use crate::{
|
||||
inventory::Inventory,
|
||||
modules::monitoring::{
|
||||
@@ -34,7 +33,6 @@ impl<
|
||||
+ 'static
|
||||
+ TenantManager
|
||||
+ K8sclient
|
||||
+ MultiTargetTopology
|
||||
+ std::fmt::Debug
|
||||
+ PrometheusApplicationMonitoring<CRDPrometheus>,
|
||||
> ApplicationFeature<T> for Monitoring
|
||||
@@ -57,11 +55,11 @@ impl<
|
||||
};
|
||||
let ntfy = NtfyScore {
|
||||
namespace: namespace.clone(),
|
||||
host: "ntfy.harmonydemo.apps.ncd0.harmony.mcd".to_string(),
|
||||
host: "localhost".to_string(),
|
||||
};
|
||||
ntfy.interpret(&Inventory::empty(), topology)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.expect("couldn't create interpret for ntfy");
|
||||
|
||||
let ntfy_default_auth_username = "harmony";
|
||||
let ntfy_default_auth_password = "harmony";
|
||||
@@ -98,7 +96,7 @@ impl<
|
||||
alerting_score
|
||||
.interpret(&Inventory::empty(), topology)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
fn name(&self) -> String {
|
||||
|
||||
@@ -14,19 +14,11 @@ use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
data::{Id, Version},
|
||||
instrumentation::{self, HarmonyEvent},
|
||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||
inventory::Inventory,
|
||||
topology::Topology,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ApplicationFeatureStatus {
|
||||
Installing,
|
||||
Installed,
|
||||
Failed { details: String },
|
||||
}
|
||||
|
||||
pub trait Application: std::fmt::Debug + Send + Sync {
|
||||
fn name(&self) -> String;
|
||||
}
|
||||
@@ -55,34 +47,13 @@ impl<A: Application, T: Topology + std::fmt::Debug> Interpret<T> for Application
|
||||
.join(", ")
|
||||
);
|
||||
for feature in self.features.iter() {
|
||||
instrumentation::instrument(HarmonyEvent::ApplicationFeatureStateChanged {
|
||||
topology: topology.name().into(),
|
||||
application: self.application.name(),
|
||||
feature: feature.name(),
|
||||
status: ApplicationFeatureStatus::Installing,
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
debug!(
|
||||
"Installing feature {} for application {app_name}",
|
||||
feature.name()
|
||||
);
|
||||
let _ = match feature.ensure_installed(topology).await {
|
||||
Ok(()) => {
|
||||
instrumentation::instrument(HarmonyEvent::ApplicationFeatureStateChanged {
|
||||
topology: topology.name().into(),
|
||||
application: self.application.name(),
|
||||
feature: feature.name(),
|
||||
status: ApplicationFeatureStatus::Installed,
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
Ok(()) => (),
|
||||
Err(msg) => {
|
||||
instrumentation::instrument(HarmonyEvent::ApplicationFeatureStateChanged {
|
||||
topology: topology.name().into(),
|
||||
application: self.application.name(),
|
||||
feature: feature.name(),
|
||||
status: ApplicationFeatureStatus::Failed {
|
||||
details: msg.clone(),
|
||||
},
|
||||
})
|
||||
.unwrap();
|
||||
return Err(InterpretError::new(format!(
|
||||
"Application Interpret failed to install feature : {msg}"
|
||||
)));
|
||||
|
||||
@@ -10,7 +10,7 @@ use dockerfile_builder::Dockerfile;
|
||||
use dockerfile_builder::instruction::{CMD, COPY, ENV, EXPOSE, FROM, RUN, USER, WORKDIR};
|
||||
use dockerfile_builder::instruction_builder::CopyBuilder;
|
||||
use futures_util::StreamExt;
|
||||
use log::{debug, info, log_enabled};
|
||||
use log::{debug, error, log_enabled};
|
||||
use serde::Serialize;
|
||||
use tar::Archive;
|
||||
|
||||
@@ -73,19 +73,19 @@ impl Application for RustWebapp {
|
||||
#[async_trait]
|
||||
impl HelmPackage for RustWebapp {
|
||||
async fn build_push_helm_package(&self, image_url: &str) -> Result<String, String> {
|
||||
info!("Starting Helm chart build and push for '{}'", self.name);
|
||||
debug!("Starting Helm chart build and push for '{}'", self.name);
|
||||
|
||||
// 1. Create the Helm chart files on disk.
|
||||
let chart_dir = self
|
||||
.create_helm_chart_files(image_url)
|
||||
.map_err(|e| format!("Failed to create Helm chart files: {}", e))?;
|
||||
info!("Successfully created Helm chart files in {:?}", chart_dir);
|
||||
debug!("Successfully created Helm chart files in {:?}", chart_dir);
|
||||
|
||||
// 2. Package the chart into a .tgz archive.
|
||||
let packaged_chart_path = self
|
||||
.package_helm_chart(&chart_dir)
|
||||
.map_err(|e| format!("Failed to package Helm chart: {}", e))?;
|
||||
info!(
|
||||
debug!(
|
||||
"Successfully packaged Helm chart: {}",
|
||||
packaged_chart_path.to_string_lossy()
|
||||
);
|
||||
@@ -94,7 +94,7 @@ impl HelmPackage for RustWebapp {
|
||||
let oci_chart_url = self
|
||||
.push_helm_chart(&packaged_chart_path)
|
||||
.map_err(|e| format!("Failed to push Helm chart: {}", e))?;
|
||||
info!("Successfully pushed Helm chart to: {}", oci_chart_url);
|
||||
debug!("Successfully pushed Helm chart to: {}", oci_chart_url);
|
||||
|
||||
Ok(oci_chart_url)
|
||||
}
|
||||
@@ -107,20 +107,20 @@ impl OCICompliant for RustWebapp {
|
||||
async fn build_push_oci_image(&self) -> Result<String, String> {
|
||||
// This function orchestrates the build and push process.
|
||||
// It's async to match the trait definition, though the underlying docker commands are blocking.
|
||||
info!("Starting OCI image build and push for '{}'", self.name);
|
||||
debug!("Starting OCI image build and push for '{}'", self.name);
|
||||
|
||||
// 1. Build the image by calling the synchronous helper function.
|
||||
let image_tag = self.image_name();
|
||||
self.build_docker_image(&image_tag)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to build Docker image: {}", e))?;
|
||||
info!("Successfully built Docker image: {}", image_tag);
|
||||
debug!("Successfully built Docker image: {}", image_tag);
|
||||
|
||||
// 2. Push the image to the registry.
|
||||
self.push_docker_image(&image_tag)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to push Docker image: {}", e))?;
|
||||
info!("Successfully pushed Docker image to: {}", image_tag);
|
||||
debug!("Successfully pushed Docker image to: {}", image_tag);
|
||||
|
||||
Ok(image_tag)
|
||||
}
|
||||
@@ -195,7 +195,7 @@ impl RustWebapp {
|
||||
);
|
||||
|
||||
while let Some(msg) = image_build_stream.next().await {
|
||||
debug!("Message: {msg:?}");
|
||||
println!("Message: {msg:?}");
|
||||
}
|
||||
|
||||
Ok(image_name.to_string())
|
||||
@@ -219,7 +219,7 @@ impl RustWebapp {
|
||||
);
|
||||
|
||||
while let Some(msg) = push_image_stream.next().await {
|
||||
debug!("Message: {msg:?}");
|
||||
println!("Message: {msg:?}");
|
||||
}
|
||||
|
||||
Ok(image_tag.to_string())
|
||||
@@ -288,8 +288,9 @@ impl RustWebapp {
|
||||
.unwrap(),
|
||||
);
|
||||
// Copy the compiled binary from the builder stage.
|
||||
// TODO: Should not be using score name here, instead should use name from Cargo.toml
|
||||
// https://git.nationtech.io/NationTech/harmony/issues/105
|
||||
error!(
|
||||
"FIXME Should not be using score name here, instead should use name from Cargo.toml"
|
||||
);
|
||||
let binary_path_in_builder = format!("/app/target/release/{}", self.name);
|
||||
let binary_path_in_final = format!("/home/appuser/{}", self.name);
|
||||
dockerfile.push(
|
||||
@@ -327,8 +328,9 @@ impl RustWebapp {
|
||||
));
|
||||
|
||||
// Copy only the compiled binary from the builder stage.
|
||||
// TODO: Should not be using score name here, instead should use name from Cargo.toml
|
||||
// https://git.nationtech.io/NationTech/harmony/issues/105
|
||||
error!(
|
||||
"FIXME Should not be using score name here, instead should use name from Cargo.toml"
|
||||
);
|
||||
let binary_path_in_builder = format!("/app/target/release/{}", self.name);
|
||||
let binary_path_in_final = format!("/usr/local/bin/{}", self.name);
|
||||
dockerfile.push(
|
||||
|
||||
@@ -29,7 +29,7 @@ impl Default for K3DInstallationScore {
|
||||
}
|
||||
|
||||
impl<T: Topology> Score<T> for K3DInstallationScore {
|
||||
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||
fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
|
||||
Box::new(K3dInstallationInterpret {
|
||||
score: self.clone(),
|
||||
})
|
||||
|
||||
@@ -1,25 +1,9 @@
|
||||
use non_blank_string_rs::NonBlankString;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{modules::helm::chart::HelmChartScore, topology::DeploymentTarget};
|
||||
|
||||
pub fn ntfy_helm_chart_score(
|
||||
namespace: String,
|
||||
host: String,
|
||||
target: DeploymentTarget,
|
||||
) -> HelmChartScore {
|
||||
// TODO not actually the correct logic, this should be fixed by using an ingresss which is the
|
||||
// correct k8s standard.
|
||||
//
|
||||
// Another option is to delegate to the topology the ingress technology it wants to use Route,
|
||||
// Ingress or other
|
||||
let route_enabled = match target {
|
||||
DeploymentTarget::LocalDev => false,
|
||||
DeploymentTarget::Staging => true,
|
||||
DeploymentTarget::Production => true,
|
||||
};
|
||||
let ingress_enabled = !route_enabled;
|
||||
use crate::modules::helm::chart::{HelmChartScore, HelmRepository};
|
||||
|
||||
pub fn ntfy_helm_chart_score(namespace: String, host: String) -> HelmChartScore {
|
||||
let values = format!(
|
||||
r#"
|
||||
replicaCount: 1
|
||||
@@ -41,14 +25,23 @@ serviceAccount:
|
||||
|
||||
service:
|
||||
type: ClusterIP
|
||||
port: 8080
|
||||
port: 80
|
||||
|
||||
ingress:
|
||||
enabled: {ingress_enabled}
|
||||
enabled: true
|
||||
# annotations:
|
||||
# kubernetes.io/ingress.class: nginx
|
||||
# kubernetes.io/tls-acme: "true"
|
||||
hosts:
|
||||
- host: {host}
|
||||
paths:
|
||||
- path: /
|
||||
pathType: ImplementationSpecific
|
||||
tls: []
|
||||
# - secretName: chart-example-tls
|
||||
# hosts:
|
||||
# - chart-example.local
|
||||
|
||||
route:
|
||||
enabled: {route_enabled}
|
||||
host: {host}
|
||||
|
||||
autoscaling:
|
||||
enabled: false
|
||||
@@ -56,7 +49,7 @@ autoscaling:
|
||||
config:
|
||||
enabled: true
|
||||
data:
|
||||
base-url: "https://{host}"
|
||||
# base-url: "https://ntfy.something.com"
|
||||
auth-file: "/var/cache/ntfy/user.db"
|
||||
auth-default-access: "deny-all"
|
||||
cache-file: "/var/cache/ntfy/cache.db"
|
||||
@@ -66,7 +59,6 @@ config:
|
||||
enable-signup: false
|
||||
enable-login: "true"
|
||||
enable-metrics: "true"
|
||||
listen-http: ":8080"
|
||||
|
||||
persistence:
|
||||
enabled: true
|
||||
@@ -77,12 +69,16 @@ persistence:
|
||||
HelmChartScore {
|
||||
namespace: Some(NonBlankString::from_str(&namespace).unwrap()),
|
||||
release_name: NonBlankString::from_str("ntfy").unwrap(),
|
||||
chart_name: NonBlankString::from_str("oci://hub.nationtech.io/harmony/ntfy").unwrap(),
|
||||
chart_version: Some(NonBlankString::from_str("0.1.7-nationtech.1").unwrap()),
|
||||
chart_name: NonBlankString::from_str("sarab97/ntfy").unwrap(),
|
||||
chart_version: Some(NonBlankString::from_str("0.1.7").unwrap()),
|
||||
values_overrides: None,
|
||||
values_yaml: Some(values.to_string()),
|
||||
create_namespace: true,
|
||||
install_only: false,
|
||||
repository: None,
|
||||
repository: Some(HelmRepository::new(
|
||||
"sarab97".to_string(),
|
||||
url::Url::parse("https://charts.sarabsingh.com").unwrap(),
|
||||
true,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use log::info;
|
||||
use log::debug;
|
||||
use serde::Serialize;
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
inventory::Inventory,
|
||||
modules::monitoring::ntfy::helm::ntfy_helm_chart::ntfy_helm_chart_score,
|
||||
score::Score,
|
||||
topology::{HelmCommand, K8sclient, MultiTargetTopology, Topology, k8s::K8sClient},
|
||||
topology::{HelmCommand, K8sclient, Topology, k8s::K8sClient},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
@@ -20,7 +20,7 @@ pub struct NtfyScore {
|
||||
pub host: String,
|
||||
}
|
||||
|
||||
impl<T: Topology + HelmCommand + K8sclient + MultiTargetTopology> Score<T> for NtfyScore {
|
||||
impl<T: Topology + HelmCommand + K8sclient> Score<T> for NtfyScore {
|
||||
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||
Box::new(NtfyInterpret {
|
||||
score: self.clone(),
|
||||
@@ -77,7 +77,7 @@ impl NtfyInterpret {
|
||||
vec![
|
||||
"sh",
|
||||
"-c",
|
||||
format!("NTFY_PASSWORD={password} ntfy user add --role={role} --ignore-exists {username}")
|
||||
format!("NTFY_PASSWORD={password} ntfy user add --role={role} {username}")
|
||||
.as_str(),
|
||||
],
|
||||
)
|
||||
@@ -89,27 +89,22 @@ impl NtfyInterpret {
|
||||
|
||||
/// We need a ntfy interpret to wrap the HelmChartScore in order to run the score, and then bootstrap the config inside ntfy
|
||||
#[async_trait]
|
||||
impl<T: Topology + HelmCommand + K8sclient + MultiTargetTopology> Interpret<T> for NtfyInterpret {
|
||||
impl<T: Topology + HelmCommand + K8sclient> Interpret<T> for NtfyInterpret {
|
||||
async fn execute(
|
||||
&self,
|
||||
inventory: &Inventory,
|
||||
topology: &T,
|
||||
) -> Result<Outcome, InterpretError> {
|
||||
ntfy_helm_chart_score(
|
||||
self.score.namespace.clone(),
|
||||
self.score.host.clone(),
|
||||
topology.current_target(),
|
||||
)
|
||||
.interpret(inventory, topology)
|
||||
.await?;
|
||||
ntfy_helm_chart_score(self.score.namespace.clone(), self.score.host.clone())
|
||||
.interpret(inventory, topology)
|
||||
.await?;
|
||||
|
||||
info!("installed ntfy helm chart");
|
||||
debug!("installed ntfy helm chart");
|
||||
let client = topology
|
||||
.k8s_client()
|
||||
.await
|
||||
.expect("couldn't get k8s client");
|
||||
|
||||
info!("deploying ntfy...");
|
||||
client
|
||||
.wait_until_deployment_ready(
|
||||
"ntfy".to_string(),
|
||||
@@ -117,12 +112,12 @@ impl<T: Topology + HelmCommand + K8sclient + MultiTargetTopology> Interpret<T> f
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
info!("ntfy deployed");
|
||||
debug!("created k8s client");
|
||||
|
||||
info!("adding user harmony");
|
||||
self.add_user(client, "harmony", "harmony", Some(NtfyRole::Admin))
|
||||
.await?;
|
||||
info!("user added");
|
||||
|
||||
debug!("exec into pod done");
|
||||
|
||||
Ok(Outcome::success("Ntfy installed".to_string()))
|
||||
}
|
||||
|
||||
@@ -166,8 +166,7 @@ impl K8sPrometheusCRDAlertingInterpret {
|
||||
|
||||
let install_output = Command::new("helm")
|
||||
.args([
|
||||
"upgrade",
|
||||
"--install",
|
||||
"install",
|
||||
&chart_name,
|
||||
tgz_path.to_str().unwrap(),
|
||||
"--namespace",
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::{interpret::InterpretError, score::Score, topology::Topology};
|
||||
|
||||
/// Create and manage Tenant Credentials.
|
||||
///
|
||||
/// This is meant to be used by cluster administrators who need to provide their tenant users and
|
||||
/// services with credentials to access their resources.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct TenantCredentialScore;
|
||||
|
||||
impl<T: Topology + TenantCredentialManager> Score<T> for TenantCredentialScore {
|
||||
fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn name(&self) -> String {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait TenantCredentialManager {
|
||||
async fn create_user(&self) -> Result<TenantCredentialBundle, InterpretError>;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CredentialMetadata {
|
||||
pub tenant_id: String,
|
||||
pub credential_id: String,
|
||||
pub description: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub expires_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CredentialData {
|
||||
/// Used to store login instructions destined to a human. Akin to AWS login instructions email
|
||||
/// upon new console user creation.
|
||||
PlainText(String),
|
||||
}
|
||||
|
||||
|
||||
pub struct TenantCredentialBundle {
|
||||
_metadata: CredentialMetadata,
|
||||
_content: CredentialData,
|
||||
}
|
||||
|
||||
impl TenantCredentialBundle {}
|
||||
@@ -5,10 +5,6 @@ version.workspace = true
|
||||
readme.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["tui"]
|
||||
tui = ["dep:harmony_tui"]
|
||||
|
||||
[dependencies]
|
||||
assert_cmd = "2.0.17"
|
||||
clap = { version = "4.5.35", features = ["derive"] }
|
||||
@@ -23,5 +19,7 @@ lazy_static = "1.5.0"
|
||||
log.workspace = true
|
||||
indicatif-log-bridge = "0.2.3"
|
||||
|
||||
[dev-dependencies]
|
||||
harmony = { path = "../harmony", features = ["testing"] }
|
||||
|
||||
[features]
|
||||
default = ["tui"]
|
||||
tui = ["dep:harmony_tui"]
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
use harmony::{
|
||||
instrumentation::{self, HarmonyEvent},
|
||||
modules::application::ApplicationFeatureStatus,
|
||||
topology::TopologyStatus,
|
||||
};
|
||||
use indicatif::MultiProgress;
|
||||
use indicatif_log_bridge::LogWrapper;
|
||||
use log::error;
|
||||
use std::{
|
||||
sync::{Arc, Mutex},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::progress::{IndicatifProgressTracker, ProgressTracker};
|
||||
|
||||
@@ -64,7 +58,6 @@ async fn handle_events(base_progress: MultiProgress) {
|
||||
&format!("\n{} Harmony completed\n\n", crate::theme::EMOJI_HARMONY),
|
||||
);
|
||||
progress_tracker.add_section("harmony-finished", "\n\n");
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
return false;
|
||||
}
|
||||
HarmonyEvent::TopologyStateChanged {
|
||||
@@ -163,40 +156,10 @@ async fn handle_events(base_progress: MultiProgress) {
|
||||
_ => progress_tracker.fail_task(&task_key, &outcome.message),
|
||||
},
|
||||
Err(err) => {
|
||||
error!("Interpret error: {err}");
|
||||
progress_tracker.fail_task(&task_key, &err.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
HarmonyEvent::ApplicationFeatureStateChanged {
|
||||
topology: _,
|
||||
application,
|
||||
feature,
|
||||
status,
|
||||
} => {
|
||||
if let Some(score) = &(*current_score) {
|
||||
let section_key = score_key(score);
|
||||
let task_key = app_feature_key(&application, &feature);
|
||||
|
||||
match status {
|
||||
ApplicationFeatureStatus::Installing => {
|
||||
let message = format!("Feature '{}' installing...", feature);
|
||||
progress_tracker.add_task(§ion_key, &task_key, &message);
|
||||
}
|
||||
ApplicationFeatureStatus::Installed => {
|
||||
let message = format!("Feature '{}' installed", feature);
|
||||
progress_tracker.finish_task(&task_key, &message);
|
||||
}
|
||||
ApplicationFeatureStatus::Failed { details } => {
|
||||
let message = format!(
|
||||
"Feature '{}' installation failed: {}",
|
||||
feature, details
|
||||
);
|
||||
progress_tracker.fail_task(&task_key, &message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
@@ -212,7 +175,3 @@ fn topology_key(topology: &str) -> String {
|
||||
fn score_key(score: &str) -> String {
|
||||
format!("score-{score}")
|
||||
}
|
||||
|
||||
fn app_feature_key(application: &str, feature: &str) -> String {
|
||||
format!("app-{application}-{feature}")
|
||||
}
|
||||
|
||||
@@ -132,9 +132,8 @@ async fn init<T: Topology + Send + Sync + 'static>(
|
||||
|
||||
// if list option is specified, print filtered list and exit
|
||||
if args.list {
|
||||
let num_scores = scores_vec.len();
|
||||
println!("Available scores {num_scores}:");
|
||||
println!("{}\n\n", list_scores_with_index(&scores_vec));
|
||||
println!("Available scores:");
|
||||
println!("{}", list_scores_with_index(&scores_vec));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -166,7 +165,7 @@ async fn init<T: Topology + Send + Sync + 'static>(
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
mod test {
|
||||
use harmony::{
|
||||
inventory::Inventory,
|
||||
maestro::Maestro,
|
||||
|
||||
@@ -33,13 +33,29 @@ pub struct IndicatifProgressTracker {
|
||||
|
||||
impl IndicatifProgressTracker {
|
||||
pub fn new(base: MultiProgress) -> Self {
|
||||
let sections = HashMap::new();
|
||||
let tasks = HashMap::new();
|
||||
// The indicatif log bridge will insert a progress bar at the top.
|
||||
// To prevent our first section from being erased, we need to create
|
||||
// a dummy progress bar as our first progress bar.
|
||||
let _ = base.clear();
|
||||
let log_pb = base.add(ProgressBar::new(1));
|
||||
|
||||
let mut sections = HashMap::new();
|
||||
sections.insert(
|
||||
"__log__".into(),
|
||||
Section {
|
||||
header_index: 0,
|
||||
task_count: 0,
|
||||
pb: log_pb.clone(),
|
||||
},
|
||||
);
|
||||
|
||||
let mut tasks = HashMap::new();
|
||||
tasks.insert("__log__".into(), log_pb);
|
||||
|
||||
let state = Arc::new(Mutex::new(IndicatifProgressTrackerState {
|
||||
sections,
|
||||
tasks,
|
||||
pb_count: 0,
|
||||
pb_count: 1,
|
||||
}));
|
||||
|
||||
Self { mp: base, state }
|
||||
|
||||
@@ -21,14 +21,10 @@ lazy_static! {
|
||||
pub static ref SUCCESS_SPINNER_STYLE: ProgressStyle = SPINNER_STYLE
|
||||
.clone()
|
||||
.tick_strings(&[format!("{}", EMOJI_SUCCESS).as_str()]);
|
||||
pub static ref SKIP_SPINNER_STYLE: ProgressStyle = ProgressStyle::default_spinner()
|
||||
.template(" {spinner:.orange} {wide_msg}")
|
||||
.unwrap()
|
||||
pub static ref SKIP_SPINNER_STYLE: ProgressStyle = SPINNER_STYLE
|
||||
.clone()
|
||||
.tick_strings(&[format!("{}", EMOJI_SKIP).as_str()]);
|
||||
pub static ref ERROR_SPINNER_STYLE: ProgressStyle = ProgressStyle::default_spinner()
|
||||
.template(" {spinner:.red} {wide_msg}")
|
||||
.unwrap()
|
||||
pub static ref ERROR_SPINNER_STYLE: ProgressStyle = SPINNER_STYLE
|
||||
.clone()
|
||||
.tick_strings(&[format!("{}", EMOJI_ERROR).as_str()]);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use harmony_cli::progress::{IndicatifProgressTracker, ProgressTracker};
|
||||
use indicatif::MultiProgress;
|
||||
use log::error;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::instrumentation::{self, HarmonyComposerEvent};
|
||||
@@ -52,13 +53,15 @@ pub async fn handle_events() {
|
||||
progress_tracker.finish_task(COMPILTATION_TASK, "project compiled");
|
||||
}
|
||||
HarmonyComposerEvent::ProjectCompilationFailed { details } => {
|
||||
progress_tracker.fail_task(COMPILTATION_TASK, &format!("failed to compile project:\n{details}"));
|
||||
progress_tracker.fail_task(COMPILTATION_TASK, "failed to compile project");
|
||||
|
||||
error!("{details}");
|
||||
}
|
||||
HarmonyComposerEvent::DeploymentStarted { target, profile } => {
|
||||
HarmonyComposerEvent::DeploymentStarted { target } => {
|
||||
progress_tracker.add_section(
|
||||
PROGRESS_DEPLOYMENT,
|
||||
&format!(
|
||||
"\n{} Deploying project on target '{target}' with profile '{profile}'...\n",
|
||||
"\n{} Deploying project to {target}...\n",
|
||||
harmony_cli::theme::EMOJI_DEPLOY,
|
||||
),
|
||||
);
|
||||
@@ -66,10 +69,6 @@ pub async fn handle_events() {
|
||||
HarmonyComposerEvent::DeploymentCompleted => {
|
||||
progress_tracker.clear();
|
||||
}
|
||||
HarmonyComposerEvent::DeploymentFailed { details } => {
|
||||
progress_tracker.add_task(PROGRESS_DEPLOYMENT, "deployment-failed", "");
|
||||
progress_tracker.fail_task("deployment-failed", &details);
|
||||
},
|
||||
HarmonyComposerEvent::Shutdown => {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2,28 +2,16 @@ use log::debug;
|
||||
use once_cell::sync::Lazy;
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
use crate::{HarmonyProfile, HarmonyTarget};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum HarmonyComposerEvent {
|
||||
HarmonyComposerStarted,
|
||||
ProjectInitializationStarted,
|
||||
ProjectInitialized,
|
||||
ProjectCompilationStarted {
|
||||
details: String,
|
||||
},
|
||||
ProjectCompilationStarted { details: String },
|
||||
ProjectCompiled,
|
||||
ProjectCompilationFailed {
|
||||
details: String,
|
||||
},
|
||||
DeploymentStarted {
|
||||
target: HarmonyTarget,
|
||||
profile: HarmonyProfile,
|
||||
},
|
||||
ProjectCompilationFailed { details: String },
|
||||
DeploymentStarted { target: String },
|
||||
DeploymentCompleted,
|
||||
DeploymentFailed {
|
||||
details: String,
|
||||
},
|
||||
Shutdown,
|
||||
}
|
||||
|
||||
@@ -35,18 +23,9 @@ static HARMONY_COMPOSER_EVENT_BUS: Lazy<broadcast::Sender<HarmonyComposerEvent>>
|
||||
});
|
||||
|
||||
pub fn instrument(event: HarmonyComposerEvent) -> Result<(), &'static str> {
|
||||
#[cfg(not(test))]
|
||||
{
|
||||
match HARMONY_COMPOSER_EVENT_BUS.send(event) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("send error: no subscribers"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
{
|
||||
let _ = event; // Suppress the "unused variable" warning for `event`
|
||||
Ok(())
|
||||
match HARMONY_COMPOSER_EVENT_BUS.send(event) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("send error: no subscribers"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,11 +49,14 @@ struct CheckArgs {
|
||||
|
||||
#[derive(Args, Clone, Debug)]
|
||||
struct DeployArgs {
|
||||
#[arg(long = "target", short = 't', default_value = "local")]
|
||||
harmony_target: HarmonyTarget,
|
||||
#[arg(long, default_value_t = false)]
|
||||
staging: bool,
|
||||
|
||||
#[arg(long = "profile", short = 'p', default_value = "dev")]
|
||||
harmony_profile: HarmonyProfile,
|
||||
#[arg(long, default_value_t = false)]
|
||||
prod: bool,
|
||||
|
||||
#[arg(long, default_value_t = false)]
|
||||
smoke_test: bool,
|
||||
}
|
||||
|
||||
#[derive(Args, Clone, Debug)]
|
||||
@@ -65,38 +68,6 @@ struct AllArgs {
|
||||
deploy: DeployArgs,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, clap::ValueEnum)]
|
||||
enum HarmonyTarget {
|
||||
Local,
|
||||
Remote,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for HarmonyTarget {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
HarmonyTarget::Local => f.write_str("local"),
|
||||
HarmonyTarget::Remote => f.write_str("remote"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, clap::ValueEnum)]
|
||||
enum HarmonyProfile {
|
||||
Dev,
|
||||
Staging,
|
||||
Production,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for HarmonyProfile {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
HarmonyProfile::Dev => f.write_str("dev"),
|
||||
HarmonyProfile::Staging => f.write_str("staging"),
|
||||
HarmonyProfile::Production => f.write_str("production"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let hc_logger_handle = harmony_composer_logger::init();
|
||||
@@ -151,39 +122,26 @@ async fn main() {
|
||||
);
|
||||
}
|
||||
Commands::Deploy(args) => {
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentStarted {
|
||||
target: args.harmony_target.clone(),
|
||||
profile: args.harmony_profile.clone(),
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
if matches!(args.harmony_profile, HarmonyProfile::Dev)
|
||||
&& !matches!(args.harmony_target, HarmonyTarget::Local)
|
||||
{
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentFailed {
|
||||
details: format!(
|
||||
"Cannot run profile '{}' on target '{}'. Profile '{}' can run locally only.",
|
||||
args.harmony_profile, args.harmony_target, args.harmony_profile
|
||||
),
|
||||
}).unwrap();
|
||||
return;
|
||||
let deploy = if args.staging {
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentStarted {
|
||||
target: "staging".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
todo!("implement staging deployment")
|
||||
} else if args.prod {
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentStarted {
|
||||
target: "prod".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
todo!("implement prod deployment")
|
||||
} else {
|
||||
instrumentation::instrument(HarmonyComposerEvent::DeploymentStarted {
|
||||
target: "dev".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
Command::new(harmony_bin_path).arg("-y").arg("-a").spawn()
|
||||
}
|
||||
|
||||
let use_local_k3d = match args.harmony_target {
|
||||
HarmonyTarget::Local => true,
|
||||
HarmonyTarget::Remote => false,
|
||||
};
|
||||
|
||||
let mut command = Command::new(harmony_bin_path);
|
||||
command
|
||||
.env("HARMONY_USE_LOCAL_K3D", format!("{use_local_k3d}"))
|
||||
.env("HARMONY_PROFILE", format!("{}", args.harmony_profile))
|
||||
.arg("-y")
|
||||
.arg("-a");
|
||||
|
||||
info!("{:?}", command);
|
||||
|
||||
let deploy = command.spawn().expect("failed to run harmony deploy");
|
||||
.expect("failed to run harmony deploy");
|
||||
|
||||
let deploy_output = deploy.wait_with_output().unwrap();
|
||||
debug!("{}", String::from_utf8(deploy_output.stdout).unwrap());
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
[package]
|
||||
name = "harmony-secret"
|
||||
edition = "2024"
|
||||
version.workspace = true
|
||||
readme.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
harmony-secret-derive = { version = "0.1.0", path = "../harmony_secret_derive" }
|
||||
serde = { version = "1.0.209", features = ["derive", "rc"] }
|
||||
serde_json = "1.0.127"
|
||||
thiserror.workspace = true
|
||||
lazy_static.workspace = true
|
||||
directories.workspace = true
|
||||
log.workspace = true
|
||||
infisical = "0.0.2"
|
||||
tokio.workspace = true
|
||||
async-trait.workspace = true
|
||||
http.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions.workspace = true
|
||||
tempfile.workspace = true
|
||||
@@ -1,18 +0,0 @@
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref SECRET_NAMESPACE: String =
|
||||
std::env::var("HARMONY_SECRET_NAMESPACE").expect("HARMONY_SECRET_NAMESPACE environment variable is required, it should contain the name of the project you are working on to access its secrets");
|
||||
pub static ref SECRET_STORE: Option<String> =
|
||||
std::env::var("HARMONY_SECRET_STORE").ok();
|
||||
pub static ref INFISICAL_URL: Option<String> =
|
||||
std::env::var("HARMONY_SECRET_INFISICAL_URL").ok();
|
||||
pub static ref INFISICAL_PROJECT_ID: Option<String> =
|
||||
std::env::var("HARMONY_SECRET_INFISICAL_PROJECT_ID").ok();
|
||||
pub static ref INFISICAL_ENVIRONMENT: Option<String> =
|
||||
std::env::var("HARMONY_SECRET_INFISICAL_ENVIRONMENT").ok();
|
||||
pub static ref INFISICAL_CLIENT_ID: Option<String> =
|
||||
std::env::var("HARMONY_SECRET_INFISICAL_CLIENT_ID").ok();
|
||||
pub static ref INFISICAL_CLIENT_SECRET: Option<String> =
|
||||
std::env::var("HARMONY_SECRET_INFISICAL_CLIENT_SECRET").ok();
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
pub mod config;
|
||||
mod store;
|
||||
|
||||
use crate::config::SECRET_NAMESPACE;
|
||||
use async_trait::async_trait;
|
||||
use config::INFISICAL_CLIENT_ID;
|
||||
use config::INFISICAL_CLIENT_SECRET;
|
||||
use config::INFISICAL_ENVIRONMENT;
|
||||
use config::INFISICAL_PROJECT_ID;
|
||||
use config::INFISICAL_URL;
|
||||
use config::SECRET_STORE;
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use std::fmt;
|
||||
use store::InfisicalSecretStore;
|
||||
use store::LocalFileSecretStore;
|
||||
use thiserror::Error;
|
||||
use tokio::sync::OnceCell;
|
||||
|
||||
pub use harmony_secret_derive::Secret;
|
||||
|
||||
// The Secret trait remains the same.
|
||||
pub trait Secret: Serialize + DeserializeOwned + Sized {
|
||||
const KEY: &'static str;
|
||||
}
|
||||
|
||||
// The error enum remains the same.
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SecretStoreError {
|
||||
#[error("Secret not found for key '{key}' in namespace '{namespace}'")]
|
||||
NotFound { namespace: String, key: String },
|
||||
#[error("Failed to deserialize secret for key '{key}': {source}")]
|
||||
Deserialization {
|
||||
key: String,
|
||||
source: serde_json::Error,
|
||||
},
|
||||
#[error("Failed to serialize secret for key '{key}': {source}")]
|
||||
Serialization {
|
||||
key: String,
|
||||
source: serde_json::Error,
|
||||
},
|
||||
#[error("Underlying storage error: {0}")]
|
||||
Store(#[from] Box<dyn std::error::Error + Send + Sync>),
|
||||
}
|
||||
|
||||
// The trait is now async!
|
||||
#[async_trait]
|
||||
pub trait SecretStore: fmt::Debug + Send + Sync {
|
||||
async fn get_raw(&self, namespace: &str, key: &str) -> Result<Vec<u8>, SecretStoreError>;
|
||||
async fn set_raw(
|
||||
&self,
|
||||
namespace: &str,
|
||||
key: &str,
|
||||
value: &[u8],
|
||||
) -> Result<(), SecretStoreError>;
|
||||
}
|
||||
|
||||
// Use OnceCell for async-friendly, one-time initialization.
|
||||
static SECRET_MANAGER: OnceCell<SecretManager> = OnceCell::const_new();
|
||||
|
||||
/// Initializes and returns a reference to the global SecretManager.
|
||||
async fn get_secret_manager() -> &'static SecretManager {
|
||||
SECRET_MANAGER.get_or_init(init_secret_manager).await
|
||||
}
|
||||
|
||||
/// The async initialization function for the SecretManager.
|
||||
async fn init_secret_manager() -> SecretManager {
|
||||
let default_secret_score = "infisical".to_string();
|
||||
let store_type = SECRET_STORE.as_ref().unwrap_or(&default_secret_score);
|
||||
|
||||
let store: Box<dyn SecretStore> = match store_type.as_str() {
|
||||
"file" => Box::new(LocalFileSecretStore::default()),
|
||||
"infisical" | _ => {
|
||||
let store = InfisicalSecretStore::new(
|
||||
INFISICAL_URL.clone().expect("Infisical url must be set, see harmony_secret config for ways to provide it. You can try with HARMONY_SECRET_INFISICAL_URL"),
|
||||
INFISICAL_PROJECT_ID.clone().expect("Infisical project id must be set, see harmony_secret config for ways to provide it. You can try with HARMONY_SECRET_INFISICAL_PROJECT_ID"),
|
||||
INFISICAL_ENVIRONMENT.clone().expect("Infisical environment must be set, see harmony_secret config for ways to provide it. You can try with HARMONY_SECRET_INFISICAL_ENVIRONMENT"),
|
||||
INFISICAL_CLIENT_ID.clone().expect("Infisical client id must be set, see harmony_secret config for ways to provide it. You can try with HARMONY_SECRET_INFISICAL_CLIENT_ID"),
|
||||
INFISICAL_CLIENT_SECRET.clone().expect("Infisical client secret must be set, see harmony_secret config for ways to provide it. You can try with HARMONY_SECRET_INFISICAL_CLIENT_SECRET"),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to initialize Infisical secret store");
|
||||
Box::new(store)
|
||||
}
|
||||
};
|
||||
|
||||
SecretManager::new(SECRET_NAMESPACE.clone(), store)
|
||||
}
|
||||
|
||||
/// Manages the lifecycle of secrets, providing a simple static API.
|
||||
#[derive(Debug)]
|
||||
pub struct SecretManager {
|
||||
namespace: String,
|
||||
store: Box<dyn SecretStore>,
|
||||
}
|
||||
|
||||
impl SecretManager {
|
||||
fn new(namespace: String, store: Box<dyn SecretStore>) -> Self {
|
||||
Self { namespace, store }
|
||||
}
|
||||
|
||||
/// Retrieves and deserializes a secret.
|
||||
pub async fn get<T: Secret>() -> Result<T, SecretStoreError> {
|
||||
let manager = get_secret_manager().await;
|
||||
let raw_value = manager.store.get_raw(&manager.namespace, T::KEY).await?;
|
||||
serde_json::from_slice(&raw_value).map_err(|e| SecretStoreError::Deserialization {
|
||||
key: T::KEY.to_string(),
|
||||
source: e,
|
||||
})
|
||||
}
|
||||
|
||||
/// Serializes and stores a secret.
|
||||
pub async fn set<T: Secret>(secret: &T) -> Result<(), SecretStoreError> {
|
||||
let manager = get_secret_manager().await;
|
||||
let raw_value =
|
||||
serde_json::to_vec(secret).map_err(|e| SecretStoreError::Serialization {
|
||||
key: T::KEY.to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
manager
|
||||
.store
|
||||
.set_raw(&manager.namespace, T::KEY, &raw_value)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||
struct TestUserMeta {
|
||||
labels: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Secret, Serialize, Deserialize, Debug, PartialEq)]
|
||||
struct TestSecret {
|
||||
user: String,
|
||||
password: String,
|
||||
metadata: TestUserMeta,
|
||||
}
|
||||
|
||||
#[cfg(secrete2etest)]
|
||||
#[tokio::test]
|
||||
async fn set_and_retrieve_secret() {
|
||||
let secret = TestSecret {
|
||||
user: String::from("user"),
|
||||
password: String::from("password"),
|
||||
metadata: TestUserMeta {
|
||||
labels: vec![
|
||||
String::from("label1"),
|
||||
String::from("label2"),
|
||||
String::from(
|
||||
"some longet label with \" special @#%$)(udiojcia[]]] \"'asdij'' characters Nдs はにほへとちり าฟันพัฒนา yağız şoföre ç <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> 👩👩👧👦 /span> 👩👧👦 and why not emojis ",
|
||||
),
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
SecretManager::set(&secret).await.unwrap();
|
||||
let value = SecretManager::get::<TestSecret>().await.unwrap();
|
||||
|
||||
assert_eq!(value, secret);
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
use crate::{SecretStore, SecretStoreError};
|
||||
use async_trait::async_trait;
|
||||
use infisical::{
|
||||
AuthMethod, InfisicalError,
|
||||
client::Client,
|
||||
secrets::{CreateSecretRequest, GetSecretRequest, UpdateSecretRequest},
|
||||
};
|
||||
use log::{info, warn};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InfisicalSecretStore {
|
||||
client: Client,
|
||||
project_id: String,
|
||||
environment: String,
|
||||
}
|
||||
|
||||
impl InfisicalSecretStore {
|
||||
/// Creates a new, authenticated Infisical client.
|
||||
pub async fn new(
|
||||
base_url: String,
|
||||
project_id: String,
|
||||
environment: String,
|
||||
client_id: String,
|
||||
client_secret: String,
|
||||
) -> Result<Self, InfisicalError> {
|
||||
info!("INFISICAL_STORE: Initializing client for URL: {base_url}");
|
||||
|
||||
// The builder and login logic remains the same.
|
||||
let mut client = Client::builder().base_url(base_url).build().await?;
|
||||
let auth_method = AuthMethod::new_universal_auth(client_id, client_secret);
|
||||
client.login(auth_method).await?;
|
||||
|
||||
info!("INFISICAL_STORE: Client authenticated successfully.");
|
||||
Ok(Self {
|
||||
client,
|
||||
project_id,
|
||||
environment,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl SecretStore for InfisicalSecretStore {
|
||||
async fn get_raw(&self, _environment: &str, key: &str) -> Result<Vec<u8>, SecretStoreError> {
|
||||
let environment = &self.environment;
|
||||
info!("INFISICAL_STORE: Getting key '{key}' from environment '{environment}'");
|
||||
|
||||
let request = GetSecretRequest::builder(key, &self.project_id, environment).build();
|
||||
|
||||
match self.client.secrets().get(request).await {
|
||||
Ok(secret) => Ok(secret.secret_value.into_bytes()),
|
||||
Err(e) => {
|
||||
// Correctly match against the actual InfisicalError enum.
|
||||
match e {
|
||||
// The specific case for a 404 Not Found error.
|
||||
InfisicalError::HttpError { status, .. }
|
||||
if status == http::StatusCode::NOT_FOUND =>
|
||||
{
|
||||
Err(SecretStoreError::NotFound {
|
||||
namespace: environment.to_string(),
|
||||
key: key.to_string(),
|
||||
})
|
||||
}
|
||||
// For all other errors, wrap them in our generic Store error.
|
||||
_ => Err(SecretStoreError::Store(Box::new(e))),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn set_raw(
|
||||
&self,
|
||||
_environment: &str,
|
||||
key: &str,
|
||||
val: &[u8],
|
||||
) -> Result<(), SecretStoreError> {
|
||||
info!(
|
||||
"INFISICAL_STORE: Setting key '{key}' in environment '{}'",
|
||||
self.environment
|
||||
);
|
||||
let value_str =
|
||||
String::from_utf8(val.to_vec()).map_err(|e| SecretStoreError::Store(Box::new(e)))?;
|
||||
|
||||
// --- Upsert Logic ---
|
||||
// First, attempt to update the secret.
|
||||
let update_req = UpdateSecretRequest::builder(key, &self.project_id, &self.environment)
|
||||
.secret_value(&value_str)
|
||||
.build();
|
||||
|
||||
match self.client.secrets().update(update_req).await {
|
||||
Ok(_) => {
|
||||
info!("INFISICAL_STORE: Successfully updated secret '{key}'.");
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => {
|
||||
// If the update failed, check if it was because the secret doesn't exist.
|
||||
match e {
|
||||
InfisicalError::HttpError { status, .. }
|
||||
if status == http::StatusCode::NOT_FOUND =>
|
||||
{
|
||||
// The secret was not found, so we create it instead.
|
||||
warn!(
|
||||
"INFISICAL_STORE: Secret '{key}' not found for update, attempting to create it."
|
||||
);
|
||||
let create_req = CreateSecretRequest::builder(
|
||||
key,
|
||||
&value_str,
|
||||
&self.project_id,
|
||||
&self.environment,
|
||||
)
|
||||
.build();
|
||||
|
||||
// Handle potential errors during creation.
|
||||
self.client
|
||||
.secrets()
|
||||
.create(create_req)
|
||||
.await
|
||||
.map_err(|create_err| SecretStoreError::Store(Box::new(create_err)))?;
|
||||
|
||||
info!("INFISICAL_STORE: Successfully created secret '{key}'.");
|
||||
Ok(())
|
||||
}
|
||||
// Any other error during update is a genuine failure.
|
||||
_ => Err(SecretStoreError::Store(Box::new(e))),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
use async_trait::async_trait;
|
||||
use log::info;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::{SecretStore, SecretStoreError};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct LocalFileSecretStore;
|
||||
|
||||
impl LocalFileSecretStore {
|
||||
/// Helper to consistently generate the secret file path.
|
||||
fn get_file_path(base_dir: &Path, ns: &str, key: &str) -> PathBuf {
|
||||
base_dir.join(format!("{ns}_{key}.json"))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl SecretStore for LocalFileSecretStore {
|
||||
async fn get_raw(&self, ns: &str, key: &str) -> Result<Vec<u8>, SecretStoreError> {
|
||||
let data_dir = directories::BaseDirs::new()
|
||||
.expect("Could not find a valid home directory")
|
||||
.data_dir()
|
||||
.join("harmony")
|
||||
.join("secrets");
|
||||
|
||||
let file_path = Self::get_file_path(&data_dir, ns, key);
|
||||
info!(
|
||||
"LOCAL_STORE: Getting key '{key}' from namespace '{ns}' at {}",
|
||||
file_path.display()
|
||||
);
|
||||
|
||||
tokio::fs::read(&file_path)
|
||||
.await
|
||||
.map_err(|_| SecretStoreError::NotFound {
|
||||
namespace: ns.to_string(),
|
||||
key: key.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
async fn set_raw(&self, ns: &str, key: &str, val: &[u8]) -> Result<(), SecretStoreError> {
|
||||
let data_dir = directories::BaseDirs::new()
|
||||
.expect("Could not find a valid home directory")
|
||||
.data_dir()
|
||||
.join("harmony")
|
||||
.join("secrets");
|
||||
|
||||
let file_path = Self::get_file_path(&data_dir, ns, key);
|
||||
info!(
|
||||
"LOCAL_STORE: Setting key '{key}' in namespace '{ns}' at {}",
|
||||
file_path.display()
|
||||
);
|
||||
|
||||
if let Some(parent_dir) = file_path.parent() {
|
||||
tokio::fs::create_dir_all(parent_dir)
|
||||
.await
|
||||
.map_err(|e| SecretStoreError::Store(Box::new(e)))?;
|
||||
}
|
||||
|
||||
tokio::fs::write(&file_path, val)
|
||||
.await
|
||||
.map_err(|e| SecretStoreError::Store(Box::new(e)))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_set_and_get_raw_successfully() {
|
||||
let dir = tempdir().unwrap();
|
||||
let store = LocalFileSecretStore::default();
|
||||
let ns = "test-ns";
|
||||
let key = "test-key";
|
||||
let value = b"{\"data\":\"test-value\"}";
|
||||
|
||||
// To test the store directly, we override the base directory logic.
|
||||
// For this test, we'll manually construct the path within our temp dir.
|
||||
let file_path = LocalFileSecretStore::get_file_path(dir.path(), ns, key);
|
||||
|
||||
// Manually write to the temp path to simulate the store's behavior
|
||||
tokio::fs::create_dir_all(file_path.parent().unwrap())
|
||||
.await
|
||||
.unwrap();
|
||||
tokio::fs::write(&file_path, value).await.unwrap();
|
||||
|
||||
// Now, test get_raw by reading from that same temp path (by mocking the path logic)
|
||||
let retrieved_value = tokio::fs::read(&file_path).await.unwrap();
|
||||
assert_eq!(retrieved_value, value);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_get_raw_not_found() {
|
||||
let dir = tempdir().unwrap();
|
||||
let ns = "test-ns";
|
||||
let key = "non-existent-key";
|
||||
|
||||
// We need to check if reading a non-existent file gives the correct error
|
||||
let file_path = LocalFileSecretStore::get_file_path(dir.path(), ns, key);
|
||||
let result = tokio::fs::read(&file_path).await;
|
||||
|
||||
assert!(matches!(result, Err(_)));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
mod infisical;
|
||||
mod local_file;
|
||||
pub use infisical::*;
|
||||
pub use local_file::*;
|
||||
@@ -1,8 +0,0 @@
|
||||
export HARMONY_SECRET_NAMESPACE=harmony_test_secrets
|
||||
export HARMONY_SECRET_INFISICAL_URL=http://localhost
|
||||
export HARMONY_SECRET_INFISICAL_PROJECT_ID=eb4723dc-eede-44d7-98cc-c8e0caf29ccb
|
||||
export HARMONY_SECRET_INFISICAL_ENVIRONMENT=dev
|
||||
export HARMONY_SECRET_INFISICAL_CLIENT_ID=dd16b07f-0e38-4090-a1d0-922de9f44d91
|
||||
export HARMONY_SECRET_INFISICAL_CLIENT_SECRET=bd2ae054e7759b11ca2e908494196337cc800bab138cb1f59e8d9b15ca3f286f
|
||||
|
||||
cargo test
|
||||
@@ -1,13 +0,0 @@
|
||||
[package]
|
||||
name = "harmony-secret-derive"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
quote = "1.0"
|
||||
proc-macro2 = "1.0"
|
||||
proc-macro-crate = "3.3"
|
||||
syn = "2.0"
|
||||
@@ -1,38 +0,0 @@
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro_crate::{FoundCrate, crate_name};
|
||||
use quote::quote;
|
||||
use syn::{DeriveInput, Ident, parse_macro_input};
|
||||
|
||||
#[proc_macro_derive(Secret)]
|
||||
pub fn derive_secret(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
let struct_ident = &input.ident;
|
||||
|
||||
// The key for the secret will be the stringified name of the struct itself.
|
||||
// e.g., `struct OKDClusterSecret` becomes key `"OKDClusterSecret"`.
|
||||
let key = struct_ident.to_string();
|
||||
|
||||
// Find the path to the `harmony_secret` crate.
|
||||
let secret_crate_path = match crate_name("harmony-secret") {
|
||||
Ok(FoundCrate::Itself) => quote!(crate),
|
||||
Ok(FoundCrate::Name(name)) => {
|
||||
let ident = Ident::new(&name, proc_macro2::Span::call_site());
|
||||
quote!(::#ident)
|
||||
}
|
||||
Err(e) => {
|
||||
return syn::Error::new(proc_macro2::Span::call_site(), e.to_string())
|
||||
.to_compile_error()
|
||||
.into();
|
||||
}
|
||||
};
|
||||
|
||||
// The generated code now implements `Secret` for the struct itself.
|
||||
// The struct must also derive `Serialize` and `Deserialize` for this to be useful.
|
||||
let expanded = quote! {
|
||||
impl #secret_crate_path::Secret for #struct_ident {
|
||||
const KEY: &'static str = #key;
|
||||
}
|
||||
};
|
||||
|
||||
TokenStream::from(expanded)
|
||||
}
|
||||
@@ -12,7 +12,7 @@ env_logger = { workspace = true }
|
||||
yaserde = { git = "https://github.com/jggc/yaserde.git" }
|
||||
yaserde_derive = { git = "https://github.com/jggc/yaserde.git" }
|
||||
xml-rs = "0.8"
|
||||
thiserror.workspace = true
|
||||
thiserror = "1.0"
|
||||
async-trait = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
uuid = { workspace = true }
|
||||
|
||||
Reference in New Issue
Block a user