mirror of
https://github.com/getnora-io/nora.git
synced 2026-04-12 22:00:31 +00:00
Compare commits
25 Commits
docs/llms-
...
v0.2.12
| Author | SHA1 | Date | |
|---|---|---|---|
| 833b3e376d | |||
| 783464acac | |||
| 8ac1e2c0c3 | |||
| 8c525bb5c2 | |||
| 5c53611cfd | |||
| 73d28ea80b | |||
| 278275978c | |||
| c1019238cb | |||
| 73e7e525a3 | |||
| 0a5f267374 | |||
| 5353faef88 | |||
| a1c51e1b6b | |||
| 9cea0673da | |||
| 24f198e172 | |||
| 5eca1817af | |||
| 80a96527fa | |||
| 1abe0df25a | |||
| 38c727491b | |||
| d0a9459acd | |||
| 482a68637e | |||
| 61f8a39279 | |||
| 835a6f0b14 | |||
| 340c49bf12 | |||
| c84d13c26e | |||
| 7e8978533a |
20
.github/workflows/release.yml
vendored
20
.github/workflows/release.yml
vendored
@@ -9,25 +9,9 @@ env:
|
|||||||
IMAGE_NAME: ${{ github.repository }}
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
|
||||||
name: Test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install Rust
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
|
|
||||||
- name: Cache cargo
|
|
||||||
uses: Swatinem/rust-cache@v2
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: cargo test --package nora-registry
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
name: Build & Push
|
name: Build & Push
|
||||||
runs-on: ubuntu-latest
|
runs-on: self-hosted
|
||||||
needs: test
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
@@ -63,7 +47,7 @@ jobs:
|
|||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
|||||||
30
CHANGELOG.md
30
CHANGELOG.md
@@ -4,6 +4,36 @@ All notable changes to NORA will be documented in this file.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## [0.3.0] - 2026-01-30
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
#### Configurable Rate Limiting
|
||||||
|
- Rate limits now configurable via `config.toml` and environment variables
|
||||||
|
- New config section `[rate_limit]` with 6 parameters:
|
||||||
|
- `auth_rps` / `auth_burst` - Authentication endpoints (brute-force protection)
|
||||||
|
- `upload_rps` / `upload_burst` - Upload endpoints (Docker push, etc.)
|
||||||
|
- `general_rps` / `general_burst` - General API endpoints
|
||||||
|
- Environment variables: `NORA_RATE_LIMIT_{AUTH|UPLOAD|GENERAL}_{RPS|BURST}`
|
||||||
|
- Rate limit configuration logged at startup
|
||||||
|
|
||||||
|
#### Secrets Provider Architecture
|
||||||
|
- Trait-based secrets management (`SecretsProvider` trait)
|
||||||
|
- ENV provider as default (12-Factor App pattern)
|
||||||
|
- Protected secrets with `zeroize` (memory zeroed on drop)
|
||||||
|
- Redacted Debug impl prevents secret leakage in logs
|
||||||
|
- New config section `[secrets]` with `provider` and `clear_env` options
|
||||||
|
- Foundation for future AWS Secrets Manager, Vault, K8s integration
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Rate limiting functions now accept `&RateLimitConfig` parameter
|
||||||
|
- Improved error messages with `.expect()` instead of `.unwrap()`
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Rate limiting was hardcoded in v0.2.0, now user-configurable
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## [0.2.0] - 2026-01-25
|
## [0.2.0] - 2026-01-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
22
Cargo.lock
generated
22
Cargo.lock
generated
@@ -1185,7 +1185,7 @@ checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nora-cli"
|
name = "nora-cli"
|
||||||
version = "0.1.0"
|
version = "0.2.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"flate2",
|
"flate2",
|
||||||
@@ -1199,7 +1199,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nora-registry"
|
name = "nora-registry"
|
||||||
version = "0.1.0"
|
version = "0.2.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"axum",
|
"axum",
|
||||||
@@ -1212,6 +1212,7 @@ dependencies = [
|
|||||||
"httpdate",
|
"httpdate",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"parking_lot",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -1229,11 +1230,12 @@ dependencies = [
|
|||||||
"utoipa-swagger-ui",
|
"utoipa-swagger-ui",
|
||||||
"uuid",
|
"uuid",
|
||||||
"wiremock",
|
"wiremock",
|
||||||
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nora-storage"
|
name = "nora-storage"
|
||||||
version = "0.1.0"
|
version = "0.2.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"base64",
|
"base64",
|
||||||
@@ -2954,6 +2956,20 @@ name = "zeroize"
|
|||||||
version = "1.8.2"
|
version = "1.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
|
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
|
||||||
|
dependencies = [
|
||||||
|
"zeroize_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zeroize_derive"
|
||||||
|
version = "1.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zerotrie"
|
name = "zerotrie"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.1.0"
|
version = "0.2.12"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["DevITWay <devitway@gmail.com>"]
|
authors = ["DevITWay <devitway@gmail.com>"]
|
||||||
|
|||||||
25
README.md
25
README.md
@@ -105,6 +105,14 @@ nora migrate --from local --to s3
|
|||||||
| `NORA_STORAGE_S3_URL` | - | S3 endpoint URL |
|
| `NORA_STORAGE_S3_URL` | - | S3 endpoint URL |
|
||||||
| `NORA_STORAGE_BUCKET` | registry | S3 bucket name |
|
| `NORA_STORAGE_BUCKET` | registry | S3 bucket name |
|
||||||
| `NORA_AUTH_ENABLED` | false | Enable authentication |
|
| `NORA_AUTH_ENABLED` | false | Enable authentication |
|
||||||
|
| `NORA_RATE_LIMIT_AUTH_RPS` | 1 | Auth requests per second |
|
||||||
|
| `NORA_RATE_LIMIT_AUTH_BURST` | 5 | Auth burst size |
|
||||||
|
| `NORA_RATE_LIMIT_UPLOAD_RPS` | 200 | Upload requests per second |
|
||||||
|
| `NORA_RATE_LIMIT_UPLOAD_BURST` | 500 | Upload burst size |
|
||||||
|
| `NORA_RATE_LIMIT_GENERAL_RPS` | 100 | General requests per second |
|
||||||
|
| `NORA_RATE_LIMIT_GENERAL_BURST` | 200 | General burst size |
|
||||||
|
| `NORA_SECRETS_PROVIDER` | env | Secrets provider (`env`) |
|
||||||
|
| `NORA_SECRETS_CLEAR_ENV` | false | Clear env vars after reading |
|
||||||
|
|
||||||
### config.toml
|
### config.toml
|
||||||
|
|
||||||
@@ -120,6 +128,23 @@ path = "data/storage"
|
|||||||
[auth]
|
[auth]
|
||||||
enabled = false
|
enabled = false
|
||||||
htpasswd_file = "users.htpasswd"
|
htpasswd_file = "users.htpasswd"
|
||||||
|
|
||||||
|
[rate_limit]
|
||||||
|
# Strict limits for authentication (brute-force protection)
|
||||||
|
auth_rps = 1
|
||||||
|
auth_burst = 5
|
||||||
|
# High limits for CI/CD upload workloads
|
||||||
|
upload_rps = 200
|
||||||
|
upload_burst = 500
|
||||||
|
# Balanced limits for general API endpoints
|
||||||
|
general_rps = 100
|
||||||
|
general_burst = 200
|
||||||
|
|
||||||
|
[secrets]
|
||||||
|
# Provider: env (default), aws-secrets, vault, k8s (coming soon)
|
||||||
|
provider = "env"
|
||||||
|
# Clear environment variables after reading (security hardening)
|
||||||
|
clear_env = false
|
||||||
```
|
```
|
||||||
|
|
||||||
## Endpoints
|
## Endpoints
|
||||||
|
|||||||
152
SESSION_NOTES.md
Normal file
152
SESSION_NOTES.md
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
# NORA Development Session Notes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2026-01-26 - Dashboard Expansion
|
||||||
|
|
||||||
|
### Iteration 1: Planning & Exploration
|
||||||
|
- Received detailed implementation plan for dashboard expansion
|
||||||
|
- Explored codebase structure using Task agent
|
||||||
|
- Identified key files to modify:
|
||||||
|
- `main.rs` - AppState
|
||||||
|
- `ui/api.rs`, `ui/mod.rs`, `ui/components.rs`, `ui/templates.rs`
|
||||||
|
- `registry/docker.rs`, `npm.rs`, `maven.rs`, `cargo_registry.rs`
|
||||||
|
|
||||||
|
### Iteration 2: Infrastructure (Phase 1)
|
||||||
|
- Created `src/dashboard_metrics.rs`:
|
||||||
|
- `DashboardMetrics` struct with AtomicU64 counters
|
||||||
|
- Per-registry tracking (docker, npm, maven, cargo, pypi)
|
||||||
|
- `record_download()`, `record_upload()`, `record_cache_hit/miss()`
|
||||||
|
- `cache_hit_rate()` calculation
|
||||||
|
|
||||||
|
- Created `src/activity_log.rs`:
|
||||||
|
- `ActionType` enum: Pull, Push, CacheHit, ProxyFetch
|
||||||
|
- `ActivityEntry` struct with timestamp, action, artifact, registry, source
|
||||||
|
- `ActivityLog` with RwLock<VecDeque> (bounded to 50 entries)
|
||||||
|
|
||||||
|
### Iteration 3: AppState Update (Phase 2)
|
||||||
|
- Updated `main.rs`:
|
||||||
|
- Added `mod activity_log` and `mod dashboard_metrics`
|
||||||
|
- Extended `AppState` with `metrics: DashboardMetrics` and `activity: ActivityLog`
|
||||||
|
- Initialized in `run_server()`
|
||||||
|
|
||||||
|
### Iteration 4: API Endpoint (Phase 3)
|
||||||
|
- Updated `ui/api.rs`:
|
||||||
|
- Added structs: `DashboardResponse`, `GlobalStats`, `RegistryCardStats`, `MountPoint`
|
||||||
|
- Implemented `api_dashboard()` - aggregates all metrics, storage stats, activity
|
||||||
|
|
||||||
|
- Updated `ui/mod.rs`:
|
||||||
|
- Added route `/api/ui/dashboard`
|
||||||
|
- Modified `dashboard()` handler to use new response
|
||||||
|
|
||||||
|
### Iteration 5: Dark Theme UI (Phase 4)
|
||||||
|
- Updated `ui/components.rs` with ~400 new lines:
|
||||||
|
- `layout_dark()` - dark theme wrapper (#0f172a background)
|
||||||
|
- `sidebar_dark()`, `header_dark()` - dark theme navigation
|
||||||
|
- `render_global_stats()` - 5-column stats grid
|
||||||
|
- `render_registry_card()` - extended card with metrics
|
||||||
|
- `render_mount_points_table()` - registry paths and proxies
|
||||||
|
- `render_activity_row()`, `render_activity_log()` - activity display
|
||||||
|
- `render_polling_script()` - 5-second auto-refresh JS
|
||||||
|
|
||||||
|
### Iteration 6: Dashboard Template (Phase 5)
|
||||||
|
- Updated `ui/templates.rs`:
|
||||||
|
- Refactored `render_dashboard()` to accept `DashboardResponse`
|
||||||
|
- Added uptime display, global stats, registry cards grid
|
||||||
|
- Added mount points table and activity log
|
||||||
|
- Added `format_relative_time()` helper
|
||||||
|
|
||||||
|
### Iteration 7: Registry Instrumentation (Phase 6)
|
||||||
|
- `registry/docker.rs`:
|
||||||
|
- `download_blob()` - record download + cache hit + activity
|
||||||
|
- `get_manifest()` - record download + cache hit + activity
|
||||||
|
- `upload_blob()` - record upload + activity
|
||||||
|
- `put_manifest()` - record upload + activity
|
||||||
|
|
||||||
|
- `registry/npm.rs`:
|
||||||
|
- Cache hit tracking for local storage
|
||||||
|
- Cache miss + proxy fetch tracking
|
||||||
|
|
||||||
|
- `registry/maven.rs`:
|
||||||
|
- `download()` - cache hit/miss + activity
|
||||||
|
- `upload()` - record upload + activity
|
||||||
|
|
||||||
|
- `registry/cargo_registry.rs`:
|
||||||
|
- `download()` - record download + activity
|
||||||
|
|
||||||
|
### Iteration 8: Build & Test
|
||||||
|
- `cargo build` - compiled successfully with minor warnings
|
||||||
|
- Fixed warnings:
|
||||||
|
- Removed unused `RegistryStats` import
|
||||||
|
- Added `#[allow(dead_code)]` to `stat_card()`
|
||||||
|
- `cargo test` - all 75 tests passed
|
||||||
|
|
||||||
|
### Iteration 9: Server Testing
|
||||||
|
- Started server: `cargo run --release --bin nora`
|
||||||
|
- Tested endpoints:
|
||||||
|
```
|
||||||
|
GET /health - OK
|
||||||
|
GET /api/ui/dashboard - returns full metrics JSON
|
||||||
|
GET /ui/ - dark theme dashboard HTML
|
||||||
|
GET /v2/test/manifests/v1 - triggered Docker metrics
|
||||||
|
GET /npm/lodash/-/lodash-4.17.21.tgz - triggered npm proxy metrics
|
||||||
|
```
|
||||||
|
- Verified metrics tracking:
|
||||||
|
- Downloads: 3 (2 Docker + 1 npm)
|
||||||
|
- Cache hit rate: 66.67%
|
||||||
|
- Activity log populated with Pull, ProxyFetch events
|
||||||
|
|
||||||
|
### Iteration 10: Git Commit & Push
|
||||||
|
- Staged 11 files (2 new, 9 modified)
|
||||||
|
- Commit: `93f9655 Add dashboard metrics, activity log, and dark theme`
|
||||||
|
- Pushed to `origin/main`
|
||||||
|
|
||||||
|
### Iteration 11: Documentation
|
||||||
|
- Updated `TODO.md` with v0.2.1 section
|
||||||
|
- Created this `SESSION_NOTES.md`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Key Decisions Made
|
||||||
|
1. **In-memory metrics** - AtomicU64 for thread-safety, reset on restart
|
||||||
|
2. **Bounded activity log** - 50 entries max, oldest evicted
|
||||||
|
3. **Polling over WebSocket** - simpler, 5-second interval sufficient
|
||||||
|
4. **Dark theme only for dashboard** - registry list pages keep light theme
|
||||||
|
|
||||||
|
### Files Changed Summary
|
||||||
|
```
|
||||||
|
New:
|
||||||
|
nora-registry/src/activity_log.rs
|
||||||
|
nora-registry/src/dashboard_metrics.rs
|
||||||
|
|
||||||
|
Modified:
|
||||||
|
nora-registry/src/main.rs (+8 lines)
|
||||||
|
nora-registry/src/registry/cargo_registry.rs (+13 lines)
|
||||||
|
nora-registry/src/registry/docker.rs (+47 lines)
|
||||||
|
nora-registry/src/registry/maven.rs (+36 lines)
|
||||||
|
nora-registry/src/registry/npm.rs (+29 lines)
|
||||||
|
nora-registry/src/ui/api.rs (+154 lines)
|
||||||
|
nora-registry/src/ui/components.rs (+394 lines)
|
||||||
|
nora-registry/src/ui/mod.rs (+5 lines)
|
||||||
|
nora-registry/src/ui/templates.rs (+180/-79 lines)
|
||||||
|
|
||||||
|
Total: ~1004 insertions, 79 deletions
|
||||||
|
```
|
||||||
|
|
||||||
|
### Useful Commands
|
||||||
|
```bash
|
||||||
|
# Start server
|
||||||
|
cargo run --release --bin nora
|
||||||
|
|
||||||
|
# Test dashboard
|
||||||
|
curl http://127.0.0.1:4000/api/ui/dashboard
|
||||||
|
|
||||||
|
# View UI
|
||||||
|
open http://127.0.0.1:4000/ui/
|
||||||
|
|
||||||
|
# Trigger metrics
|
||||||
|
curl http://127.0.0.1:4000/v2/test/manifests/v1
|
||||||
|
curl http://127.0.0.1:4000/npm/lodash/-/lodash-4.17.21.tgz -o /dev/null
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
503
TODO.md
Normal file
503
TODO.md
Normal file
@@ -0,0 +1,503 @@
|
|||||||
|
# NORA Roadmap / TODO
|
||||||
|
|
||||||
|
## v0.2.0 - DONE
|
||||||
|
- [x] Unit tests (75 tests passing)
|
||||||
|
- [x] Input validation (path traversal protection)
|
||||||
|
- [x] Rate limiting (brute-force protection)
|
||||||
|
- [x] Request ID tracking
|
||||||
|
- [x] Migrate command (local <-> S3)
|
||||||
|
- [x] Error handling (thiserror)
|
||||||
|
- [x] SVG brand icons
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v0.2.1 - Dashboard Expansion (2026-01-26) - DONE
|
||||||
|
|
||||||
|
### Commit: 93f9655
|
||||||
|
|
||||||
|
### New Files
|
||||||
|
- `nora-registry/src/dashboard_metrics.rs` - AtomicU64 counters for metrics
|
||||||
|
- `nora-registry/src/activity_log.rs` - Bounded activity log (50 entries)
|
||||||
|
|
||||||
|
### Modified Files
|
||||||
|
- `nora-registry/src/main.rs` - Added modules, updated AppState
|
||||||
|
- `nora-registry/src/ui/api.rs` - Added DashboardResponse, api_dashboard()
|
||||||
|
- `nora-registry/src/ui/mod.rs` - Added /api/ui/dashboard route
|
||||||
|
- `nora-registry/src/ui/components.rs` - Dark theme components
|
||||||
|
- `nora-registry/src/ui/templates.rs` - New render_dashboard()
|
||||||
|
- `nora-registry/src/registry/docker.rs` - Instrumented handlers
|
||||||
|
- `nora-registry/src/registry/npm.rs` - Instrumented with cache tracking
|
||||||
|
- `nora-registry/src/registry/maven.rs` - Instrumented download/upload
|
||||||
|
- `nora-registry/src/registry/cargo_registry.rs` - Instrumented download
|
||||||
|
|
||||||
|
### Features Implemented
|
||||||
|
- [x] Global stats panel (downloads, uploads, artifacts, cache hit %, storage)
|
||||||
|
- [x] Per-registry metrics (Docker, Maven, npm, Cargo, PyPI)
|
||||||
|
- [x] Mount points table with proxy upstreams
|
||||||
|
- [x] Activity log (last 20 events)
|
||||||
|
- [x] Dark theme (#0f172a background, #1e293b cards)
|
||||||
|
- [x] Auto-refresh polling (5 seconds)
|
||||||
|
- [x] Cache hit/miss tracking
|
||||||
|
|
||||||
|
### API Endpoints
|
||||||
|
- `GET /api/ui/dashboard` - Full dashboard data as JSON
|
||||||
|
|
||||||
|
### Dark Theme Colors
|
||||||
|
```
|
||||||
|
Background: #0f172a (slate-950)
|
||||||
|
Cards: #1e293b (slate-800)
|
||||||
|
Borders: slate-700
|
||||||
|
Text primary: slate-200
|
||||||
|
Text secondary: slate-400
|
||||||
|
Accent: blue-400
|
||||||
|
```
|
||||||
|
|
||||||
|
### Testing Commands
|
||||||
|
```bash
|
||||||
|
# Test dashboard API
|
||||||
|
curl http://127.0.0.1:4000/api/ui/dashboard
|
||||||
|
|
||||||
|
# Test Docker pull (triggers metrics)
|
||||||
|
curl http://127.0.0.1:4000/v2/test/manifests/v1
|
||||||
|
|
||||||
|
# Test npm proxy (triggers cache miss)
|
||||||
|
curl http://127.0.0.1:4000/npm/lodash/-/lodash-4.17.21.tgz -o /dev/null
|
||||||
|
```
|
||||||
|
|
||||||
|
### Future Improvements (Dashboard)
|
||||||
|
- [ ] Add PyPI download instrumentation
|
||||||
|
- [ ] Persist metrics to disk (currently reset on restart)
|
||||||
|
- [ ] Add WebSocket for real-time updates (instead of polling)
|
||||||
|
- [ ] Add graphs/charts for metrics over time
|
||||||
|
- [ ] Add user/client tracking in activity log
|
||||||
|
- [ ] Dark/light theme toggle
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v0.3.0 - OIDC / Workload Identity Federation
|
||||||
|
|
||||||
|
### Killer Feature: OIDC for CI/CD
|
||||||
|
Zero-secret authentication for GitHub Actions, GitLab CI, etc.
|
||||||
|
|
||||||
|
**Goal:** Replace manual `ROBOT_TOKEN` rotation with federated identity.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# GitHub Actions example
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
steps:
|
||||||
|
- name: Login to NORA
|
||||||
|
uses: nora/login-action@v1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config Structure (draft)
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[auth.oidc]
|
||||||
|
enabled = true
|
||||||
|
|
||||||
|
# GitHub Actions
|
||||||
|
[[auth.oidc.providers]]
|
||||||
|
name = "github-actions"
|
||||||
|
issuer = "https://token.actions.githubusercontent.com"
|
||||||
|
audience = "https://nora.example.com"
|
||||||
|
|
||||||
|
[[auth.oidc.providers.rules]]
|
||||||
|
# Claim matching (supports glob)
|
||||||
|
match = { repository = "my-org/*", ref = "refs/heads/main" }
|
||||||
|
# Granted permissions
|
||||||
|
permissions = ["push:my-org/*", "pull:*"]
|
||||||
|
|
||||||
|
[[auth.oidc.providers.rules]]
|
||||||
|
match = { repository = "my-org/*", ref = "refs/heads/*" }
|
||||||
|
permissions = ["pull:*"]
|
||||||
|
|
||||||
|
# GitLab CI
|
||||||
|
[[auth.oidc.providers]]
|
||||||
|
name = "gitlab-ci"
|
||||||
|
issuer = "https://gitlab.com"
|
||||||
|
audience = "https://nora.example.com"
|
||||||
|
|
||||||
|
[[auth.oidc.providers.rules]]
|
||||||
|
match = { project_path = "my-group/*" }
|
||||||
|
permissions = ["push:my-group/*", "pull:*"]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementation Tasks
|
||||||
|
- [ ] JWT validation library (jsonwebtoken crate)
|
||||||
|
- [ ] OIDC discovery (/.well-known/openid-configuration)
|
||||||
|
- [ ] JWKS fetching and caching
|
||||||
|
- [ ] Claims extraction and glob matching
|
||||||
|
- [ ] Permission resolution from rules
|
||||||
|
- [ ] Token exchange endpoint (POST /auth/oidc/token)
|
||||||
|
- [ ] GitHub Action: `nora/login-action`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v0.4.0 - Transparent Docker Hub Proxy
|
||||||
|
|
||||||
|
### Pain Point
|
||||||
|
Harbor forces tag changes: `docker pull my-harbor/proxy-cache/library/nginx`
|
||||||
|
This breaks Helm charts hardcoded to `nginx`.
|
||||||
|
|
||||||
|
### Goal
|
||||||
|
Transparent pull-through cache:
|
||||||
|
```bash
|
||||||
|
docker pull nora.example.com/nginx # -> proxies to Docker Hub
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementation Tasks
|
||||||
|
- [ ] Registry v2 API interception
|
||||||
|
- [ ] Upstream registry configuration
|
||||||
|
- [ ] Cache layer management
|
||||||
|
- [ ] Rate limit handling (Docker Hub limits)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v0.5.0 - Repo-level RBAC
|
||||||
|
|
||||||
|
### Challenge
|
||||||
|
Per-repository permissions need fast lookup (100 layers per push).
|
||||||
|
|
||||||
|
### Solution
|
||||||
|
Glob patterns for 90% of cases:
|
||||||
|
```toml
|
||||||
|
[[auth.rules]]
|
||||||
|
subject = "team-frontend"
|
||||||
|
permissions = ["push:frontend/*", "pull:*"]
|
||||||
|
|
||||||
|
[[auth.rules]]
|
||||||
|
subject = "ci-bot"
|
||||||
|
permissions = ["push:*/release-*", "pull:*"]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementation Tasks
|
||||||
|
- [ ] In-memory permission cache
|
||||||
|
- [ ] Glob pattern matcher (globset crate)
|
||||||
|
- [ ] Permission inheritance (org -> project -> repo)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Target Audience
|
||||||
|
|
||||||
|
1. DevOps engineers tired of Java/Go monsters
|
||||||
|
2. Edge/IoT installations (Raspberry Pi, branch offices)
|
||||||
|
3. Educational platforms (student labs)
|
||||||
|
4. CI/CD pipelines (GitHub Actions, GitLab CI)
|
||||||
|
|
||||||
|
## Competitive Advantages
|
||||||
|
|
||||||
|
| Feature | NORA | Harbor | Nexus |
|
||||||
|
|---------|------|--------|-------|
|
||||||
|
| Memory | <100MB | 2GB+ | 4GB+ |
|
||||||
|
| OIDC for CI | v0.3.0 | No | No |
|
||||||
|
| Transparent proxy | v0.4.0 | No (tag rewrite) | Partial |
|
||||||
|
| Single binary | Yes | No (microservices) | No (Java) |
|
||||||
|
| Zero-config upgrade | Yes | Complex | Complex |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v0.6.0 - Online Garbage Collection
|
||||||
|
|
||||||
|
### Pain Point
|
||||||
|
Harbor GC blocks registry for hours. Can't push during cleanup.
|
||||||
|
|
||||||
|
### Goal
|
||||||
|
Non-blocking garbage collection with zero downtime.
|
||||||
|
|
||||||
|
### Implementation Tasks
|
||||||
|
- [ ] Mark-and-sweep without locking
|
||||||
|
- [ ] Background blob cleanup
|
||||||
|
- [ ] Progress reporting via API/CLI
|
||||||
|
- [ ] `nora gc --dry-run` preview
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v0.7.0 - Retention Policies
|
||||||
|
|
||||||
|
### Pain Point
|
||||||
|
"Keep last 10 tags" sounds simple, works poorly everywhere.
|
||||||
|
|
||||||
|
### Goal
|
||||||
|
Declarative retention rules in config:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[retention]]
|
||||||
|
match = "*/dev-*"
|
||||||
|
keep_last = 5
|
||||||
|
|
||||||
|
[[retention]]
|
||||||
|
match = "*/release-*"
|
||||||
|
keep_last = 20
|
||||||
|
older_than = "90d"
|
||||||
|
|
||||||
|
[[retention]]
|
||||||
|
match = "**/pr-*"
|
||||||
|
older_than = "7d"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementation Tasks
|
||||||
|
- [ ] Glob pattern matching for repos/tags
|
||||||
|
- [ ] Age-based and count-based rules
|
||||||
|
- [ ] Dry-run mode
|
||||||
|
- [ ] Scheduled execution (cron-style)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v0.8.0 - Multi-tenancy & Quotas
|
||||||
|
|
||||||
|
### Pain Point
|
||||||
|
Harbor projects have quotas but configuration is painful. Nexus has no real isolation.
|
||||||
|
|
||||||
|
### Goal
|
||||||
|
Simple namespaces with limits:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[[tenants]]
|
||||||
|
name = "team-frontend"
|
||||||
|
storage_quota = "50GB"
|
||||||
|
rate_limit = { push = 100, pull = 1000 } # per hour
|
||||||
|
|
||||||
|
[[tenants]]
|
||||||
|
name = "team-backend"
|
||||||
|
storage_quota = "100GB"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementation Tasks
|
||||||
|
- [ ] Tenant isolation (namespace prefix)
|
||||||
|
- [ ] Storage quota tracking
|
||||||
|
- [ ] Per-tenant rate limiting
|
||||||
|
- [ ] Usage reporting API
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v0.9.0 - Smart Replication
|
||||||
|
|
||||||
|
### Pain Point
|
||||||
|
Harbor replication rules are complex, errors silently swallowed.
|
||||||
|
|
||||||
|
### Goal
|
||||||
|
Simple CLI-driven replication with clear feedback:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nora replicate --to remote-dc --filter "prod/*" --dry-run
|
||||||
|
nora replicate --from gcr.io/my-project/* --to local/imported/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementation Tasks
|
||||||
|
- [ ] Push-based replication to remote NORA
|
||||||
|
- [ ] Pull-based import from external registries (Docker Hub, GCR, ECR, Quay)
|
||||||
|
- [ ] Filter by glob patterns
|
||||||
|
- [ ] Progress bar and detailed logs
|
||||||
|
- [ ] Retry logic with exponential backoff
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v1.0.0 - Production Ready
|
||||||
|
|
||||||
|
### Features to polish
|
||||||
|
- [ ] Full CLI (`nora images ls`, `nora tag`, `nora delete`)
|
||||||
|
- [ ] Webhooks with filters and retry logic
|
||||||
|
- [ ] Enhanced Prometheus metrics (per-repo stats, cache hit ratio, bandwidth per tenant)
|
||||||
|
- [ ] TUI dashboard (optional)
|
||||||
|
- [ ] Helm chart for Kubernetes deployment
|
||||||
|
- [ ] Official Docker image on ghcr.io
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Future Ideas (v1.x+)
|
||||||
|
|
||||||
|
### Cold Storage Tiering
|
||||||
|
Auto-move old tags to S3 Glacier:
|
||||||
|
```toml
|
||||||
|
[[storage.tiering]]
|
||||||
|
match = "*"
|
||||||
|
older_than = "180d"
|
||||||
|
move_to = "s3-glacier"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Vulnerability Scanning Integration
|
||||||
|
Not built-in (use Trivy), but:
|
||||||
|
- [ ] Webhook on push -> trigger external scan
|
||||||
|
- [ ] Store scan results as OCI artifacts
|
||||||
|
- [ ] Block pull if critical CVEs (policy)
|
||||||
|
|
||||||
|
### Image Signing (Cosign/Notation)
|
||||||
|
- [ ] Signature storage (OCI artifacts)
|
||||||
|
- [ ] Policy enforcement (reject unsigned)
|
||||||
|
|
||||||
|
### P2P Distribution (Dragonfly/Kraken style)
|
||||||
|
For large clusters pulling same image simultaneously.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Architecture / DDD
|
||||||
|
|
||||||
|
### Current State (v0.2.0)
|
||||||
|
Monolithic structure, all in `nora-registry/src/`:
|
||||||
|
```
|
||||||
|
src/
|
||||||
|
├── main.rs # CLI + server setup
|
||||||
|
├── auth.rs # htpasswd + basic auth
|
||||||
|
├── tokens.rs # API tokens
|
||||||
|
├── storage/ # Storage backends (local, s3)
|
||||||
|
├── registry/ # Protocol handlers (docker, maven, npm, cargo, pypi)
|
||||||
|
├── ui/ # Web dashboard
|
||||||
|
└── ...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Target Architecture (v1.0+)
|
||||||
|
|
||||||
|
#### Domain-Driven Design Boundaries
|
||||||
|
|
||||||
|
```
|
||||||
|
nora/
|
||||||
|
├── nora-core/ # Domain layer (no dependencies)
|
||||||
|
│ ├── src/
|
||||||
|
│ │ ├── artifact.rs # Artifact, Digest, Tag, Manifest
|
||||||
|
│ │ ├── repository.rs # Repository, Namespace
|
||||||
|
│ │ ├── identity.rs # User, ServiceAccount, Token
|
||||||
|
│ │ ├── policy.rs # Permission, Rule, Quota
|
||||||
|
│ │ └── events.rs # DomainEvent (ArtifactPushed, etc.)
|
||||||
|
│
|
||||||
|
├── nora-auth/ # Authentication bounded context
|
||||||
|
│ ├── src/
|
||||||
|
│ │ ├── htpasswd.rs # Basic auth provider
|
||||||
|
│ │ ├── oidc.rs # OIDC/JWT provider
|
||||||
|
│ │ ├── token.rs # API token provider
|
||||||
|
│ │ └── rbac.rs # Permission resolver
|
||||||
|
│
|
||||||
|
├── nora-storage/ # Storage bounded context
|
||||||
|
│ ├── src/
|
||||||
|
│ │ ├── backend.rs # StorageBackend trait
|
||||||
|
│ │ ├── local.rs # Filesystem
|
||||||
|
│ │ ├── s3.rs # S3-compatible
|
||||||
|
│ │ ├── tiered.rs # Hot/cold tiering
|
||||||
|
│ │ └── gc.rs # Garbage collection
|
||||||
|
│
|
||||||
|
├── nora-registry/ # Application layer (HTTP API)
|
||||||
|
│ ├── src/
|
||||||
|
│ │ ├── api/
|
||||||
|
│ │ │ ├── oci.rs # OCI Distribution API (/v2/)
|
||||||
|
│ │ │ ├── maven.rs # Maven repository
|
||||||
|
│ │ │ ├── npm.rs # npm registry
|
||||||
|
│ │ │ ├── cargo.rs # Cargo registry
|
||||||
|
│ │ │ └── pypi.rs # PyPI (simple API)
|
||||||
|
│ │ ├── proxy/ # Upstream proxy/cache
|
||||||
|
│ │ ├── webhook/ # Event webhooks
|
||||||
|
│ │ └── ui/ # Web dashboard
|
||||||
|
│
|
||||||
|
├── nora-cli/ # CLI application
|
||||||
|
│ ├── src/
|
||||||
|
│ │ ├── commands/
|
||||||
|
│ │ │ ├── serve.rs
|
||||||
|
│ │ │ ├── images.rs # nora images ls/delete/tag
|
||||||
|
│ │ │ ├── gc.rs # nora gc
|
||||||
|
│ │ │ ├── backup.rs # nora backup/restore
|
||||||
|
│ │ │ ├── migrate.rs # nora migrate
|
||||||
|
│ │ │ └── replicate.rs
|
||||||
|
│ │ └── tui/ # Optional TUI dashboard
|
||||||
|
│
|
||||||
|
└── nora-sdk/ # Client SDK (for nora/login-action)
|
||||||
|
└── src/
|
||||||
|
├── client.rs # HTTP client
|
||||||
|
└── oidc.rs # Token exchange
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Key Principles
|
||||||
|
|
||||||
|
1. **Hexagonal Architecture**
|
||||||
|
- Core domain has no external dependencies
|
||||||
|
- Ports (traits) define boundaries
|
||||||
|
- Adapters implement ports (S3, filesystem, OIDC providers)
|
||||||
|
|
||||||
|
2. **Event-Driven**
|
||||||
|
- Domain events: `ArtifactPushed`, `ArtifactDeleted`, `TagCreated`
|
||||||
|
- Webhooks subscribe to events
|
||||||
|
- Async processing for GC, replication
|
||||||
|
|
||||||
|
3. **CQRS-lite**
|
||||||
|
- Commands: Push, Delete, CreateToken
|
||||||
|
- Queries: List, Get, Search
|
||||||
|
- Separate read/write paths for hot endpoints
|
||||||
|
|
||||||
|
4. **Configuration as Code**
|
||||||
|
- All policies in `nora.toml`
|
||||||
|
- No database for config (file-based)
|
||||||
|
- GitOps friendly
|
||||||
|
|
||||||
|
#### Trait Boundaries (Ports)
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// nora-core/src/ports.rs
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait ArtifactStore {
|
||||||
|
async fn push_blob(&self, digest: &Digest, data: Bytes) -> Result<()>;
|
||||||
|
async fn get_blob(&self, digest: &Digest) -> Result<Bytes>;
|
||||||
|
async fn push_manifest(&self, repo: &Repository, tag: &Tag, manifest: &Manifest) -> Result<()>;
|
||||||
|
async fn get_manifest(&self, repo: &Repository, reference: &Reference) -> Result<Manifest>;
|
||||||
|
async fn list_tags(&self, repo: &Repository) -> Result<Vec<Tag>>;
|
||||||
|
async fn delete(&self, repo: &Repository, reference: &Reference) -> Result<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait IdentityProvider {
|
||||||
|
async fn authenticate(&self, credentials: &Credentials) -> Result<Identity>;
|
||||||
|
async fn authorize(&self, identity: &Identity, action: &Action, resource: &Resource) -> Result<bool>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait EventPublisher {
|
||||||
|
async fn publish(&self, event: DomainEvent) -> Result<()>;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Migration Path
|
||||||
|
|
||||||
|
| Phase | Action |
|
||||||
|
|-------|--------|
|
||||||
|
| v0.3 | Extract `nora-auth` crate (OIDC work) |
|
||||||
|
| v0.4 | Extract `nora-core` domain types |
|
||||||
|
| v0.5 | Extract `nora-storage` with trait boundaries |
|
||||||
|
| v0.6+ | Refactor registry handlers to use ports |
|
||||||
|
| v1.0 | Full hexagonal architecture |
|
||||||
|
|
||||||
|
### Technical Debt to Address
|
||||||
|
|
||||||
|
- [ ] Remove `unwrap()` in non-test code (started in e9984cf)
|
||||||
|
- [ ] Add tracing spans to all handlers
|
||||||
|
- [ ] Consistent error types across modules
|
||||||
|
- [ ] Extract hardcoded limits to config
|
||||||
|
- [ ] Add OpenTelemetry support (traces, not just metrics)
|
||||||
|
|
||||||
|
### Performance Requirements
|
||||||
|
|
||||||
|
| Metric | Target |
|
||||||
|
|--------|--------|
|
||||||
|
| Memory (idle) | <50MB |
|
||||||
|
| Memory (under load) | <100MB |
|
||||||
|
| Startup time | <1s |
|
||||||
|
| Blob throughput | Wire speed (no processing overhead) |
|
||||||
|
| Manifest latency | <10ms p99 |
|
||||||
|
| Auth check | <1ms (cached) |
|
||||||
|
|
||||||
|
### Security Requirements
|
||||||
|
|
||||||
|
- [ ] No secrets in logs (already redacting)
|
||||||
|
- [ ] TLS termination (or trust reverse proxy)
|
||||||
|
- [ ] Content-addressable storage (immutable blobs)
|
||||||
|
- [ ] Audit log for all mutations
|
||||||
|
- [ ] SBOM generation for NORA itself
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- S3 storage: already implemented
|
||||||
|
- Web UI: minimalist read-only dashboard (done)
|
||||||
|
- TUI: consider for v1.0
|
||||||
|
- Vulnerability scanning: out of scope (use Trivy externally)
|
||||||
|
- Image signing: out of scope for now (use cosign externally)
|
||||||
190
deploy/README.md
190
deploy/README.md
@@ -1,57 +1,187 @@
|
|||||||
# NORA Demo Deployment
|
# NORA Demo Deployment
|
||||||
|
|
||||||
## DNS Setup
|
[English](#english) | [Русский](#russian)
|
||||||
|
|
||||||
Add A record:
|
---
|
||||||
```
|
|
||||||
demo.getnora.io → <VPS_IP>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Deploy
|
<a name="english"></a>
|
||||||
|
## English
|
||||||
|
|
||||||
|
### Quick Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run NORA with Docker
|
||||||
|
docker run -d \
|
||||||
|
--name nora \
|
||||||
|
-p 4000:4000 \
|
||||||
|
-v nora-data:/data \
|
||||||
|
ghcr.io/getnora-io/nora:latest
|
||||||
|
|
||||||
|
# Check health
|
||||||
|
curl http://localhost:4000/health
|
||||||
|
```
|
||||||
|
|
||||||
|
### Push Docker Images
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Tag your image
|
||||||
|
docker tag myapp:v1 localhost:4000/myapp:v1
|
||||||
|
|
||||||
|
# Push to NORA
|
||||||
|
docker push localhost:4000/myapp:v1
|
||||||
|
|
||||||
|
# Pull from NORA
|
||||||
|
docker pull localhost:4000/myapp:v1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use as Maven Repository
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<!-- pom.xml -->
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>nora</id>
|
||||||
|
<url>http://localhost:4000/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use as npm Registry
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm config set registry http://localhost:4000/npm/
|
||||||
|
npm install lodash
|
||||||
|
```
|
||||||
|
|
||||||
|
### Use as PyPI Index
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install --index-url http://localhost:4000/simple/ requests
|
||||||
|
```
|
||||||
|
|
||||||
|
### Production Deployment with HTTPS
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Clone repo
|
|
||||||
git clone https://github.com/getnora-io/nora.git
|
git clone https://github.com/getnora-io/nora.git
|
||||||
cd nora/deploy
|
cd nora/deploy
|
||||||
|
|
||||||
# Start
|
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
|
|
||||||
# Check logs
|
|
||||||
docker compose logs -f
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## URLs
|
### URLs
|
||||||
|
|
||||||
- **Web UI:** https://demo.getnora.io/ui/
|
| URL | Description |
|
||||||
- **API Docs:** https://demo.getnora.io/api-docs
|
|-----|-------------|
|
||||||
- **Health:** https://demo.getnora.io/health
|
| `/ui/` | Web UI |
|
||||||
|
| `/api-docs` | Swagger API Docs |
|
||||||
|
| `/health` | Health Check |
|
||||||
|
| `/metrics` | Prometheus Metrics |
|
||||||
|
|
||||||
## Docker Usage
|
### Environment Variables
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| `NORA_HOST` | 127.0.0.1 | Bind address |
|
||||||
|
| `NORA_PORT` | 4000 | Port |
|
||||||
|
| `NORA_STORAGE_PATH` | data/storage | Storage path |
|
||||||
|
| `NORA_AUTH_ENABLED` | false | Enable auth |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<a name="russian"></a>
|
||||||
|
## Русский
|
||||||
|
|
||||||
|
### Быстрый старт
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Tag and push
|
# Запуск NORA в Docker
|
||||||
docker tag myimage:latest demo.getnora.io/myimage:latest
|
docker run -d \
|
||||||
docker push demo.getnora.io/myimage:latest
|
--name nora \
|
||||||
|
-p 4000:4000 \
|
||||||
|
-v nora-data:/data \
|
||||||
|
ghcr.io/getnora-io/nora:latest
|
||||||
|
|
||||||
# Pull
|
# Проверка работоспособности
|
||||||
docker pull demo.getnora.io/myimage:latest
|
curl http://localhost:4000/health
|
||||||
```
|
```
|
||||||
|
|
||||||
## Management
|
### Загрузка Docker образов
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Stop
|
# Тегируем образ
|
||||||
|
docker tag myapp:v1 localhost:4000/myapp:v1
|
||||||
|
|
||||||
|
# Пушим в NORA
|
||||||
|
docker push localhost:4000/myapp:v1
|
||||||
|
|
||||||
|
# Скачиваем из NORA
|
||||||
|
docker pull localhost:4000/myapp:v1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Использование как Maven репозиторий
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<!-- pom.xml -->
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>nora</id>
|
||||||
|
<url>http://localhost:4000/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Использование как npm реестр
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm config set registry http://localhost:4000/npm/
|
||||||
|
npm install lodash
|
||||||
|
```
|
||||||
|
|
||||||
|
### Использование как PyPI индекс
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pip install --index-url http://localhost:4000/simple/ requests
|
||||||
|
```
|
||||||
|
|
||||||
|
### Продакшен с HTTPS
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/getnora-io/nora.git
|
||||||
|
cd nora/deploy
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### Эндпоинты
|
||||||
|
|
||||||
|
| URL | Описание |
|
||||||
|
|-----|----------|
|
||||||
|
| `/ui/` | Веб-интерфейс |
|
||||||
|
| `/api-docs` | Swagger документация |
|
||||||
|
| `/health` | Проверка здоровья |
|
||||||
|
| `/metrics` | Метрики Prometheus |
|
||||||
|
|
||||||
|
### Переменные окружения
|
||||||
|
|
||||||
|
| Переменная | По умолчанию | Описание |
|
||||||
|
|------------|--------------|----------|
|
||||||
|
| `NORA_HOST` | 127.0.0.1 | Адрес привязки |
|
||||||
|
| `NORA_PORT` | 4000 | Порт |
|
||||||
|
| `NORA_STORAGE_PATH` | data/storage | Путь хранилища |
|
||||||
|
| `NORA_AUTH_ENABLED` | false | Включить авторизацию |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Management / Управление
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop / Остановить
|
||||||
docker compose down
|
docker compose down
|
||||||
|
|
||||||
# Restart
|
# Restart / Перезапустить
|
||||||
docker compose restart
|
docker compose restart
|
||||||
|
|
||||||
# View logs
|
# Logs / Логи
|
||||||
docker compose logs -f nora
|
docker compose logs -f nora
|
||||||
docker compose logs -f caddy
|
|
||||||
|
|
||||||
# Update
|
# Update / Обновить
|
||||||
docker compose pull
|
docker compose pull && docker compose up -d
|
||||||
docker compose up -d
|
|
||||||
```
|
```
|
||||||
|
|||||||
83
deploy/demo-traffic.sh
Normal file
83
deploy/demo-traffic.sh
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Demo traffic simulator for NORA registry
|
||||||
|
# Generates random registry activity for dashboard demo
|
||||||
|
|
||||||
|
REGISTRY="http://localhost:4000"
|
||||||
|
LOG_FILE="/var/log/nora-demo-traffic.log"
|
||||||
|
|
||||||
|
# Sample packages to fetch
|
||||||
|
NPM_PACKAGES=("lodash" "express" "react" "axios" "moment" "underscore" "chalk" "debug")
|
||||||
|
MAVEN_ARTIFACTS=(
|
||||||
|
"org/apache/commons/commons-lang3/3.12.0/commons-lang3-3.12.0.pom"
|
||||||
|
"com/google/guava/guava/31.1-jre/guava-31.1-jre.pom"
|
||||||
|
"org/slf4j/slf4j-api/2.0.0/slf4j-api-2.0.0.pom"
|
||||||
|
)
|
||||||
|
DOCKER_IMAGES=("alpine" "busybox" "hello-world")
|
||||||
|
|
||||||
|
log() {
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Random sleep between min and max seconds
|
||||||
|
random_sleep() {
|
||||||
|
local min=$1
|
||||||
|
local max=$2
|
||||||
|
local delay=$((RANDOM % (max - min + 1) + min))
|
||||||
|
sleep $delay
|
||||||
|
}
|
||||||
|
|
||||||
|
# Fetch random npm package
|
||||||
|
fetch_npm() {
|
||||||
|
local pkg=${NPM_PACKAGES[$RANDOM % ${#NPM_PACKAGES[@]}]}
|
||||||
|
log "NPM: fetching $pkg"
|
||||||
|
curl -s "$REGISTRY/npm/$pkg" > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Fetch random maven artifact
|
||||||
|
fetch_maven() {
|
||||||
|
local artifact=${MAVEN_ARTIFACTS[$RANDOM % ${#MAVEN_ARTIFACTS[@]}]}
|
||||||
|
log "MAVEN: fetching $artifact"
|
||||||
|
curl -s "$REGISTRY/maven2/$artifact" > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Docker push/pull cycle
|
||||||
|
docker_cycle() {
|
||||||
|
local img=${DOCKER_IMAGES[$RANDOM % ${#DOCKER_IMAGES[@]}]}
|
||||||
|
local tag="demo-$(date +%s)"
|
||||||
|
|
||||||
|
log "DOCKER: push/pull cycle for $img"
|
||||||
|
|
||||||
|
# Tag and push
|
||||||
|
docker tag "$img:latest" "localhost:4000/demo/$img:$tag" 2>/dev/null
|
||||||
|
docker push "localhost:4000/demo/$img:$tag" > /dev/null 2>&1
|
||||||
|
|
||||||
|
# Pull back
|
||||||
|
docker rmi "localhost:4000/demo/$img:$tag" > /dev/null 2>&1
|
||||||
|
docker pull "localhost:4000/demo/$img:$tag" > /dev/null 2>&1
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
docker rmi "localhost:4000/demo/$img:$tag" > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main loop
|
||||||
|
log "Starting demo traffic simulator"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
# Random operation
|
||||||
|
op=$((RANDOM % 10))
|
||||||
|
|
||||||
|
case $op in
|
||||||
|
0|1|2|3) # 40% npm
|
||||||
|
fetch_npm
|
||||||
|
;;
|
||||||
|
4|5|6) # 30% maven
|
||||||
|
fetch_maven
|
||||||
|
;;
|
||||||
|
7|8|9) # 30% docker
|
||||||
|
docker_cycle
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Random delay: 30-120 seconds
|
||||||
|
random_sleep 30 120
|
||||||
|
done
|
||||||
15
deploy/nora-demo-traffic.service
Normal file
15
deploy/nora-demo-traffic.service
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=NORA Demo Traffic Simulator
|
||||||
|
After=docker.service
|
||||||
|
Requires=docker.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/opt/nora/demo-traffic.sh
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
StandardOutput=journal
|
||||||
|
StandardError=journal
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -41,6 +41,8 @@ chrono = { version = "0.4", features = ["serde"] }
|
|||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
tower_governor = "0.8"
|
tower_governor = "0.8"
|
||||||
governor = "0.10"
|
governor = "0.10"
|
||||||
|
parking_lot = "0.12"
|
||||||
|
zeroize = { version = "1.8", features = ["derive"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
|||||||
98
nora-registry/src/activity_log.rs
Normal file
98
nora-registry/src/activity_log.rs
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use parking_lot::RwLock;
|
||||||
|
use serde::Serialize;
|
||||||
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
/// Type of action that was performed
|
||||||
|
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||||
|
pub enum ActionType {
|
||||||
|
Pull,
|
||||||
|
Push,
|
||||||
|
CacheHit,
|
||||||
|
ProxyFetch,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for ActionType {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
ActionType::Pull => write!(f, "PULL"),
|
||||||
|
ActionType::Push => write!(f, "PUSH"),
|
||||||
|
ActionType::CacheHit => write!(f, "CACHE"),
|
||||||
|
ActionType::ProxyFetch => write!(f, "PROXY"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A single activity log entry
|
||||||
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
pub struct ActivityEntry {
|
||||||
|
pub timestamp: DateTime<Utc>,
|
||||||
|
pub action: ActionType,
|
||||||
|
pub artifact: String,
|
||||||
|
pub registry: String,
|
||||||
|
pub source: String, // "LOCAL", "PROXY", "CACHE"
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActivityEntry {
|
||||||
|
pub fn new(action: ActionType, artifact: String, registry: &str, source: &str) -> Self {
|
||||||
|
Self {
|
||||||
|
timestamp: Utc::now(),
|
||||||
|
action,
|
||||||
|
artifact,
|
||||||
|
registry: registry.to_string(),
|
||||||
|
source: source.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Thread-safe activity log with bounded size
|
||||||
|
pub struct ActivityLog {
|
||||||
|
entries: RwLock<VecDeque<ActivityEntry>>,
|
||||||
|
max_entries: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActivityLog {
|
||||||
|
pub fn new(max: usize) -> Self {
|
||||||
|
Self {
|
||||||
|
entries: RwLock::new(VecDeque::with_capacity(max)),
|
||||||
|
max_entries: max,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a new entry to the log, removing oldest if at capacity
|
||||||
|
pub fn push(&self, entry: ActivityEntry) {
|
||||||
|
let mut entries = self.entries.write();
|
||||||
|
if entries.len() >= self.max_entries {
|
||||||
|
entries.pop_front();
|
||||||
|
}
|
||||||
|
entries.push_back(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the most recent N entries (newest first)
|
||||||
|
pub fn recent(&self, count: usize) -> Vec<ActivityEntry> {
|
||||||
|
let entries = self.entries.read();
|
||||||
|
entries.iter().rev().take(count).cloned().collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get all entries (newest first)
|
||||||
|
pub fn all(&self) -> Vec<ActivityEntry> {
|
||||||
|
let entries = self.entries.read();
|
||||||
|
entries.iter().rev().cloned().collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the total number of entries
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.entries.read().len()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if the log is empty
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.entries.read().is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ActivityLog {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new(50)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -405,7 +405,9 @@ mod tests {
|
|||||||
// Protected paths
|
// Protected paths
|
||||||
assert!(!is_public_path("/v2/myimage/blobs/sha256:abc"));
|
assert!(!is_public_path("/v2/myimage/blobs/sha256:abc"));
|
||||||
assert!(!is_public_path("/v2/library/nginx/manifests/latest"));
|
assert!(!is_public_path("/v2/library/nginx/manifests/latest"));
|
||||||
assert!(!is_public_path("/maven2/com/example/artifact/1.0/artifact.jar"));
|
assert!(!is_public_path(
|
||||||
|
"/maven2/com/example/artifact/1.0/artifact.jar"
|
||||||
|
));
|
||||||
assert!(!is_public_path("/npm/lodash"));
|
assert!(!is_public_path("/npm/lodash"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
pub use crate::secrets::SecretsConfig;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub server: ServerConfig,
|
pub server: ServerConfig,
|
||||||
@@ -11,13 +13,26 @@ pub struct Config {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub npm: NpmConfig,
|
pub npm: NpmConfig,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
pub pypi: PypiConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub docker: DockerConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub raw: RawConfig,
|
||||||
|
#[serde(default)]
|
||||||
pub auth: AuthConfig,
|
pub auth: AuthConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub rate_limit: RateLimitConfig,
|
||||||
|
#[serde(default)]
|
||||||
|
pub secrets: SecretsConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ServerConfig {
|
pub struct ServerConfig {
|
||||||
pub host: String,
|
pub host: String,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
|
/// Public URL for generating pull commands (e.g., "registry.example.com")
|
||||||
|
#[serde(default)]
|
||||||
|
pub public_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
|
||||||
@@ -68,6 +83,52 @@ pub struct NpmConfig {
|
|||||||
pub proxy_timeout: u64,
|
pub proxy_timeout: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct PypiConfig {
|
||||||
|
#[serde(default)]
|
||||||
|
pub proxy: Option<String>,
|
||||||
|
#[serde(default = "default_timeout")]
|
||||||
|
pub proxy_timeout: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Docker registry configuration with upstream proxy support
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct DockerConfig {
|
||||||
|
#[serde(default = "default_docker_timeout")]
|
||||||
|
pub proxy_timeout: u64,
|
||||||
|
#[serde(default)]
|
||||||
|
pub upstreams: Vec<DockerUpstream>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Docker upstream registry configuration
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct DockerUpstream {
|
||||||
|
pub url: String,
|
||||||
|
#[serde(default)]
|
||||||
|
pub auth: Option<String>, // "user:pass" for basic auth
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Raw repository configuration for simple file storage
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct RawConfig {
|
||||||
|
#[serde(default = "default_raw_enabled")]
|
||||||
|
pub enabled: bool,
|
||||||
|
#[serde(default = "default_max_file_size")]
|
||||||
|
pub max_file_size: u64, // in bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_docker_timeout() -> u64 {
|
||||||
|
60
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_raw_enabled() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_max_file_size() -> u64 {
|
||||||
|
104_857_600 // 100MB
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct AuthConfig {
|
pub struct AuthConfig {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@@ -108,6 +169,36 @@ impl Default for NpmConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for PypiConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
proxy: Some("https://pypi.org/simple/".to_string()),
|
||||||
|
proxy_timeout: 30,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DockerConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
proxy_timeout: 60,
|
||||||
|
upstreams: vec![DockerUpstream {
|
||||||
|
url: "https://registry-1.docker.io".to_string(),
|
||||||
|
auth: None,
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for RawConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
enabled: true,
|
||||||
|
max_file_size: 104_857_600, // 100MB
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for AuthConfig {
|
impl Default for AuthConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -118,6 +209,76 @@ impl Default for AuthConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Rate limiting configuration
|
||||||
|
///
|
||||||
|
/// Controls request rate limits for different endpoint types.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
/// ```toml
|
||||||
|
/// [rate_limit]
|
||||||
|
/// auth_rps = 1
|
||||||
|
/// auth_burst = 5
|
||||||
|
/// upload_rps = 500
|
||||||
|
/// upload_burst = 1000
|
||||||
|
/// general_rps = 100
|
||||||
|
/// general_burst = 200
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// # Environment Variables
|
||||||
|
/// - `NORA_RATE_LIMIT_AUTH_RPS` - Auth requests per second
|
||||||
|
/// - `NORA_RATE_LIMIT_AUTH_BURST` - Auth burst size
|
||||||
|
/// - `NORA_RATE_LIMIT_UPLOAD_RPS` - Upload requests per second
|
||||||
|
/// - `NORA_RATE_LIMIT_UPLOAD_BURST` - Upload burst size
|
||||||
|
/// - `NORA_RATE_LIMIT_GENERAL_RPS` - General requests per second
|
||||||
|
/// - `NORA_RATE_LIMIT_GENERAL_BURST` - General burst size
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct RateLimitConfig {
|
||||||
|
#[serde(default = "default_auth_rps")]
|
||||||
|
pub auth_rps: u64,
|
||||||
|
#[serde(default = "default_auth_burst")]
|
||||||
|
pub auth_burst: u32,
|
||||||
|
#[serde(default = "default_upload_rps")]
|
||||||
|
pub upload_rps: u64,
|
||||||
|
#[serde(default = "default_upload_burst")]
|
||||||
|
pub upload_burst: u32,
|
||||||
|
#[serde(default = "default_general_rps")]
|
||||||
|
pub general_rps: u64,
|
||||||
|
#[serde(default = "default_general_burst")]
|
||||||
|
pub general_burst: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_auth_rps() -> u64 {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
fn default_auth_burst() -> u32 {
|
||||||
|
5
|
||||||
|
}
|
||||||
|
fn default_upload_rps() -> u64 {
|
||||||
|
200
|
||||||
|
}
|
||||||
|
fn default_upload_burst() -> u32 {
|
||||||
|
500
|
||||||
|
}
|
||||||
|
fn default_general_rps() -> u64 {
|
||||||
|
100
|
||||||
|
}
|
||||||
|
fn default_general_burst() -> u32 {
|
||||||
|
200
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for RateLimitConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
auth_rps: default_auth_rps(),
|
||||||
|
auth_burst: default_auth_burst(),
|
||||||
|
upload_rps: default_upload_rps(),
|
||||||
|
upload_burst: default_upload_burst(),
|
||||||
|
general_rps: default_general_rps(),
|
||||||
|
general_burst: default_general_burst(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
/// Load configuration with priority: ENV > config.toml > defaults
|
/// Load configuration with priority: ENV > config.toml > defaults
|
||||||
pub fn load() -> Self {
|
pub fn load() -> Self {
|
||||||
@@ -144,6 +305,9 @@ impl Config {
|
|||||||
self.server.port = port;
|
self.server.port = port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Ok(val) = env::var("NORA_PUBLIC_URL") {
|
||||||
|
self.server.public_url = if val.is_empty() { None } else { Some(val) };
|
||||||
|
}
|
||||||
|
|
||||||
// Storage config
|
// Storage config
|
||||||
if let Ok(val) = env::var("NORA_STORAGE_MODE") {
|
if let Ok(val) = env::var("NORA_STORAGE_MODE") {
|
||||||
@@ -190,10 +354,91 @@ impl Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PyPI config
|
||||||
|
if let Ok(val) = env::var("NORA_PYPI_PROXY") {
|
||||||
|
self.pypi.proxy = if val.is_empty() { None } else { Some(val) };
|
||||||
|
}
|
||||||
|
if let Ok(val) = env::var("NORA_PYPI_PROXY_TIMEOUT") {
|
||||||
|
if let Ok(timeout) = val.parse() {
|
||||||
|
self.pypi.proxy_timeout = timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Docker config
|
||||||
|
if let Ok(val) = env::var("NORA_DOCKER_PROXY_TIMEOUT") {
|
||||||
|
if let Ok(timeout) = val.parse() {
|
||||||
|
self.docker.proxy_timeout = timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// NORA_DOCKER_UPSTREAMS format: "url1,url2" or "url1|auth1,url2|auth2"
|
||||||
|
if let Ok(val) = env::var("NORA_DOCKER_UPSTREAMS") {
|
||||||
|
self.docker.upstreams = val
|
||||||
|
.split(',')
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.map(|s| {
|
||||||
|
let parts: Vec<&str> = s.trim().splitn(2, '|').collect();
|
||||||
|
DockerUpstream {
|
||||||
|
url: parts[0].to_string(),
|
||||||
|
auth: parts.get(1).map(|a| a.to_string()),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw config
|
||||||
|
if let Ok(val) = env::var("NORA_RAW_ENABLED") {
|
||||||
|
self.raw.enabled = val.to_lowercase() == "true" || val == "1";
|
||||||
|
}
|
||||||
|
if let Ok(val) = env::var("NORA_RAW_MAX_FILE_SIZE") {
|
||||||
|
if let Ok(size) = val.parse() {
|
||||||
|
self.raw.max_file_size = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Token storage
|
// Token storage
|
||||||
if let Ok(val) = env::var("NORA_AUTH_TOKEN_STORAGE") {
|
if let Ok(val) = env::var("NORA_AUTH_TOKEN_STORAGE") {
|
||||||
self.auth.token_storage = val;
|
self.auth.token_storage = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rate limit config
|
||||||
|
if let Ok(val) = env::var("NORA_RATE_LIMIT_AUTH_RPS") {
|
||||||
|
if let Ok(v) = val.parse::<u64>() {
|
||||||
|
self.rate_limit.auth_rps = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Ok(val) = env::var("NORA_RATE_LIMIT_AUTH_BURST") {
|
||||||
|
if let Ok(v) = val.parse::<u32>() {
|
||||||
|
self.rate_limit.auth_burst = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Ok(val) = env::var("NORA_RATE_LIMIT_UPLOAD_RPS") {
|
||||||
|
if let Ok(v) = val.parse::<u64>() {
|
||||||
|
self.rate_limit.upload_rps = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Ok(val) = env::var("NORA_RATE_LIMIT_UPLOAD_BURST") {
|
||||||
|
if let Ok(v) = val.parse::<u32>() {
|
||||||
|
self.rate_limit.upload_burst = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Ok(val) = env::var("NORA_RATE_LIMIT_GENERAL_RPS") {
|
||||||
|
if let Ok(v) = val.parse::<u64>() {
|
||||||
|
self.rate_limit.general_rps = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Ok(val) = env::var("NORA_RATE_LIMIT_GENERAL_BURST") {
|
||||||
|
if let Ok(v) = val.parse::<u32>() {
|
||||||
|
self.rate_limit.general_burst = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Secrets config
|
||||||
|
if let Ok(val) = env::var("NORA_SECRETS_PROVIDER") {
|
||||||
|
self.secrets.provider = val;
|
||||||
|
}
|
||||||
|
if let Ok(val) = env::var("NORA_SECRETS_CLEAR_ENV") {
|
||||||
|
self.secrets.clear_env = val.to_lowercase() == "true" || val == "1";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +448,7 @@ impl Default for Config {
|
|||||||
server: ServerConfig {
|
server: ServerConfig {
|
||||||
host: String::from("127.0.0.1"),
|
host: String::from("127.0.0.1"),
|
||||||
port: 4000,
|
port: 4000,
|
||||||
|
public_url: None,
|
||||||
},
|
},
|
||||||
storage: StorageConfig {
|
storage: StorageConfig {
|
||||||
mode: StorageMode::Local,
|
mode: StorageMode::Local,
|
||||||
@@ -212,7 +458,49 @@ impl Default for Config {
|
|||||||
},
|
},
|
||||||
maven: MavenConfig::default(),
|
maven: MavenConfig::default(),
|
||||||
npm: NpmConfig::default(),
|
npm: NpmConfig::default(),
|
||||||
|
pypi: PypiConfig::default(),
|
||||||
|
docker: DockerConfig::default(),
|
||||||
|
raw: RawConfig::default(),
|
||||||
auth: AuthConfig::default(),
|
auth: AuthConfig::default(),
|
||||||
|
rate_limit: RateLimitConfig::default(),
|
||||||
|
secrets: SecretsConfig::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rate_limit_default() {
|
||||||
|
let config = RateLimitConfig::default();
|
||||||
|
assert_eq!(config.auth_rps, 1);
|
||||||
|
assert_eq!(config.auth_burst, 5);
|
||||||
|
assert_eq!(config.upload_rps, 200);
|
||||||
|
assert_eq!(config.upload_burst, 500);
|
||||||
|
assert_eq!(config.general_rps, 100);
|
||||||
|
assert_eq!(config.general_burst, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_rate_limit_from_toml() {
|
||||||
|
let toml = r#"
|
||||||
|
[server]
|
||||||
|
host = "127.0.0.1"
|
||||||
|
port = 4000
|
||||||
|
|
||||||
|
[storage]
|
||||||
|
mode = "local"
|
||||||
|
|
||||||
|
[rate_limit]
|
||||||
|
auth_rps = 10
|
||||||
|
upload_burst = 1000
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let config: Config = toml::from_str(toml).unwrap();
|
||||||
|
assert_eq!(config.rate_limit.auth_rps, 10);
|
||||||
|
assert_eq!(config.rate_limit.upload_burst, 1000);
|
||||||
|
assert_eq!(config.rate_limit.auth_burst, 5); // default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
122
nora-registry/src/dashboard_metrics.rs
Normal file
122
nora-registry/src/dashboard_metrics.rs
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
use std::sync::atomic::{AtomicU64, Ordering};
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
/// Dashboard metrics for tracking registry activity
|
||||||
|
/// Uses atomic counters for thread-safe access without locks
|
||||||
|
pub struct DashboardMetrics {
|
||||||
|
// Global counters
|
||||||
|
pub downloads: AtomicU64,
|
||||||
|
pub uploads: AtomicU64,
|
||||||
|
pub cache_hits: AtomicU64,
|
||||||
|
pub cache_misses: AtomicU64,
|
||||||
|
|
||||||
|
// Per-registry download counters
|
||||||
|
pub docker_downloads: AtomicU64,
|
||||||
|
pub docker_uploads: AtomicU64,
|
||||||
|
pub npm_downloads: AtomicU64,
|
||||||
|
pub maven_downloads: AtomicU64,
|
||||||
|
pub maven_uploads: AtomicU64,
|
||||||
|
pub cargo_downloads: AtomicU64,
|
||||||
|
pub pypi_downloads: AtomicU64,
|
||||||
|
pub raw_downloads: AtomicU64,
|
||||||
|
pub raw_uploads: AtomicU64,
|
||||||
|
|
||||||
|
pub start_time: Instant,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DashboardMetrics {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
downloads: AtomicU64::new(0),
|
||||||
|
uploads: AtomicU64::new(0),
|
||||||
|
cache_hits: AtomicU64::new(0),
|
||||||
|
cache_misses: AtomicU64::new(0),
|
||||||
|
docker_downloads: AtomicU64::new(0),
|
||||||
|
docker_uploads: AtomicU64::new(0),
|
||||||
|
npm_downloads: AtomicU64::new(0),
|
||||||
|
maven_downloads: AtomicU64::new(0),
|
||||||
|
maven_uploads: AtomicU64::new(0),
|
||||||
|
cargo_downloads: AtomicU64::new(0),
|
||||||
|
pypi_downloads: AtomicU64::new(0),
|
||||||
|
raw_downloads: AtomicU64::new(0),
|
||||||
|
raw_uploads: AtomicU64::new(0),
|
||||||
|
start_time: Instant::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Record a download event for the specified registry
|
||||||
|
pub fn record_download(&self, registry: &str) {
|
||||||
|
self.downloads.fetch_add(1, Ordering::Relaxed);
|
||||||
|
match registry {
|
||||||
|
"docker" => self.docker_downloads.fetch_add(1, Ordering::Relaxed),
|
||||||
|
"npm" => self.npm_downloads.fetch_add(1, Ordering::Relaxed),
|
||||||
|
"maven" => self.maven_downloads.fetch_add(1, Ordering::Relaxed),
|
||||||
|
"cargo" => self.cargo_downloads.fetch_add(1, Ordering::Relaxed),
|
||||||
|
"pypi" => self.pypi_downloads.fetch_add(1, Ordering::Relaxed),
|
||||||
|
"raw" => self.raw_downloads.fetch_add(1, Ordering::Relaxed),
|
||||||
|
_ => 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Record an upload event for the specified registry
|
||||||
|
pub fn record_upload(&self, registry: &str) {
|
||||||
|
self.uploads.fetch_add(1, Ordering::Relaxed);
|
||||||
|
match registry {
|
||||||
|
"docker" => self.docker_uploads.fetch_add(1, Ordering::Relaxed),
|
||||||
|
"maven" => self.maven_uploads.fetch_add(1, Ordering::Relaxed),
|
||||||
|
"raw" => self.raw_uploads.fetch_add(1, Ordering::Relaxed),
|
||||||
|
_ => 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Record a cache hit
|
||||||
|
pub fn record_cache_hit(&self) {
|
||||||
|
self.cache_hits.fetch_add(1, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Record a cache miss
|
||||||
|
pub fn record_cache_miss(&self) {
|
||||||
|
self.cache_misses.fetch_add(1, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculate the cache hit rate as a percentage
|
||||||
|
pub fn cache_hit_rate(&self) -> f64 {
|
||||||
|
let hits = self.cache_hits.load(Ordering::Relaxed);
|
||||||
|
let misses = self.cache_misses.load(Ordering::Relaxed);
|
||||||
|
let total = hits + misses;
|
||||||
|
if total == 0 {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
(hits as f64 / total as f64) * 100.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get download count for a specific registry
|
||||||
|
pub fn get_registry_downloads(&self, registry: &str) -> u64 {
|
||||||
|
match registry {
|
||||||
|
"docker" => self.docker_downloads.load(Ordering::Relaxed),
|
||||||
|
"npm" => self.npm_downloads.load(Ordering::Relaxed),
|
||||||
|
"maven" => self.maven_downloads.load(Ordering::Relaxed),
|
||||||
|
"cargo" => self.cargo_downloads.load(Ordering::Relaxed),
|
||||||
|
"pypi" => self.pypi_downloads.load(Ordering::Relaxed),
|
||||||
|
"raw" => self.raw_downloads.load(Ordering::Relaxed),
|
||||||
|
_ => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get upload count for a specific registry
|
||||||
|
pub fn get_registry_uploads(&self, registry: &str) -> u64 {
|
||||||
|
match registry {
|
||||||
|
"docker" => self.docker_uploads.load(Ordering::Relaxed),
|
||||||
|
"maven" => self.maven_uploads.load(Ordering::Relaxed),
|
||||||
|
"raw" => self.raw_uploads.load(Ordering::Relaxed),
|
||||||
|
_ => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DashboardMetrics {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
//! Application error handling with HTTP response conversion
|
//! Application error handling with HTTP response conversion
|
||||||
//!
|
//!
|
||||||
//! Provides a unified error type that can be converted to HTTP responses
|
//! Provides a unified error type that can be converted to HTTP responses
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
mod activity_log;
|
||||||
mod auth;
|
mod auth;
|
||||||
mod backup;
|
mod backup;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod dashboard_metrics;
|
||||||
mod error;
|
mod error;
|
||||||
mod health;
|
mod health;
|
||||||
mod metrics;
|
mod metrics;
|
||||||
@@ -9,6 +11,7 @@ mod openapi;
|
|||||||
mod rate_limit;
|
mod rate_limit;
|
||||||
mod registry;
|
mod registry;
|
||||||
mod request_id;
|
mod request_id;
|
||||||
|
mod secrets;
|
||||||
mod storage;
|
mod storage;
|
||||||
mod tokens;
|
mod tokens;
|
||||||
mod ui;
|
mod ui;
|
||||||
@@ -23,17 +26,15 @@ use tokio::signal;
|
|||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
||||||
|
|
||||||
|
use activity_log::ActivityLog;
|
||||||
use auth::HtpasswdAuth;
|
use auth::HtpasswdAuth;
|
||||||
use config::{Config, StorageMode};
|
use config::{Config, StorageMode};
|
||||||
|
use dashboard_metrics::DashboardMetrics;
|
||||||
pub use storage::Storage;
|
pub use storage::Storage;
|
||||||
use tokens::TokenStore;
|
use tokens::TokenStore;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(
|
#[command(name = "nora", version, about = "Multi-protocol artifact registry")]
|
||||||
name = "nora",
|
|
||||||
version,
|
|
||||||
about = "Multi-protocol artifact registry"
|
|
||||||
)]
|
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Option<Commands>,
|
command: Option<Commands>,
|
||||||
@@ -75,6 +76,9 @@ pub struct AppState {
|
|||||||
pub start_time: Instant,
|
pub start_time: Instant,
|
||||||
pub auth: Option<HtpasswdAuth>,
|
pub auth: Option<HtpasswdAuth>,
|
||||||
pub tokens: Option<TokenStore>,
|
pub tokens: Option<TokenStore>,
|
||||||
|
pub metrics: DashboardMetrics,
|
||||||
|
pub activity: ActivityLog,
|
||||||
|
pub docker_auth: registry::DockerAuth,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -177,6 +181,36 @@ fn init_logging(json_format: bool) {
|
|||||||
async fn run_server(config: Config, storage: Storage) {
|
async fn run_server(config: Config, storage: Storage) {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
|
|
||||||
|
// Log rate limiting configuration
|
||||||
|
info!(
|
||||||
|
auth_rps = config.rate_limit.auth_rps,
|
||||||
|
auth_burst = config.rate_limit.auth_burst,
|
||||||
|
upload_rps = config.rate_limit.upload_rps,
|
||||||
|
upload_burst = config.rate_limit.upload_burst,
|
||||||
|
general_rps = config.rate_limit.general_rps,
|
||||||
|
general_burst = config.rate_limit.general_burst,
|
||||||
|
"Rate limiting configured"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Initialize secrets provider
|
||||||
|
let secrets_provider = match secrets::create_secrets_provider(&config.secrets) {
|
||||||
|
Ok(provider) => {
|
||||||
|
info!(
|
||||||
|
provider = provider.provider_name(),
|
||||||
|
clear_env = config.secrets.clear_env,
|
||||||
|
"Secrets provider initialized"
|
||||||
|
);
|
||||||
|
Some(provider)
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!(error = %e, "Failed to initialize secrets provider, using defaults");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Store secrets provider for future use (S3 credentials, etc.)
|
||||||
|
let _secrets = secrets_provider;
|
||||||
|
|
||||||
// Load auth if enabled
|
// Load auth if enabled
|
||||||
let auth = if config.auth.enabled {
|
let auth = if config.auth.enabled {
|
||||||
let path = Path::new(&config.auth.htpasswd_file);
|
let path = Path::new(&config.auth.htpasswd_file);
|
||||||
@@ -203,16 +237,27 @@ async fn run_server(config: Config, storage: Storage) {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Create rate limiters before moving config to state
|
||||||
|
let auth_limiter = rate_limit::auth_rate_limiter(&config.rate_limit);
|
||||||
|
let upload_limiter = rate_limit::upload_rate_limiter(&config.rate_limit);
|
||||||
|
let general_limiter = rate_limit::general_rate_limiter(&config.rate_limit);
|
||||||
|
|
||||||
|
// Initialize Docker auth with proxy timeout
|
||||||
|
let docker_auth = registry::DockerAuth::new(config.docker.proxy_timeout);
|
||||||
|
|
||||||
let state = Arc::new(AppState {
|
let state = Arc::new(AppState {
|
||||||
storage,
|
storage,
|
||||||
config,
|
config,
|
||||||
start_time,
|
start_time,
|
||||||
auth,
|
auth,
|
||||||
tokens,
|
tokens,
|
||||||
|
metrics: DashboardMetrics::new(),
|
||||||
|
activity: ActivityLog::new(50),
|
||||||
|
docker_auth,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Token routes with strict rate limiting (brute-force protection)
|
// Token routes with strict rate limiting (brute-force protection)
|
||||||
let auth_routes = auth::token_routes().layer(rate_limit::auth_rate_limiter());
|
let auth_routes = auth::token_routes().layer(auth_limiter);
|
||||||
|
|
||||||
// Registry routes with upload rate limiting
|
// Registry routes with upload rate limiting
|
||||||
let registry_routes = Router::new()
|
let registry_routes = Router::new()
|
||||||
@@ -221,16 +266,25 @@ async fn run_server(config: Config, storage: Storage) {
|
|||||||
.merge(registry::npm_routes())
|
.merge(registry::npm_routes())
|
||||||
.merge(registry::cargo_routes())
|
.merge(registry::cargo_routes())
|
||||||
.merge(registry::pypi_routes())
|
.merge(registry::pypi_routes())
|
||||||
.layer(rate_limit::upload_rate_limiter());
|
.merge(registry::raw_routes())
|
||||||
|
.layer(upload_limiter);
|
||||||
|
|
||||||
let app = Router::new()
|
// Routes WITHOUT rate limiting (health, metrics, UI)
|
||||||
|
let public_routes = Router::new()
|
||||||
.merge(health::routes())
|
.merge(health::routes())
|
||||||
.merge(metrics::routes())
|
.merge(metrics::routes())
|
||||||
.merge(ui::routes())
|
.merge(ui::routes())
|
||||||
.merge(openapi::routes())
|
.merge(openapi::routes());
|
||||||
|
|
||||||
|
// Routes WITH rate limiting
|
||||||
|
let rate_limited_routes = Router::new()
|
||||||
.merge(auth_routes)
|
.merge(auth_routes)
|
||||||
.merge(registry_routes)
|
.merge(registry_routes)
|
||||||
.layer(rate_limit::general_rate_limiter()) // General rate limit for all routes
|
.layer(general_limiter);
|
||||||
|
|
||||||
|
let app = Router::new()
|
||||||
|
.merge(public_routes)
|
||||||
|
.merge(rate_limited_routes)
|
||||||
.layer(DefaultBodyLimit::max(100 * 1024 * 1024)) // 100MB default body limit
|
.layer(DefaultBodyLimit::max(100 * 1024 * 1024)) // 100MB default body limit
|
||||||
.layer(middleware::from_fn(request_id::request_id_middleware))
|
.layer(middleware::from_fn(request_id::request_id_middleware))
|
||||||
.layer(middleware::from_fn(metrics::metrics_middleware))
|
.layer(middleware::from_fn(metrics::metrics_middleware))
|
||||||
@@ -264,6 +318,7 @@ async fn run_server(config: Config, storage: Storage) {
|
|||||||
npm = "/npm/",
|
npm = "/npm/",
|
||||||
cargo = "/cargo/",
|
cargo = "/cargo/",
|
||||||
pypi = "/simple/",
|
pypi = "/simple/",
|
||||||
|
raw = "/raw/",
|
||||||
"Available endpoints"
|
"Available endpoints"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -8,17 +8,12 @@ use indicatif::{ProgressBar, ProgressStyle};
|
|||||||
use tracing::{info, warn};
|
use tracing::{info, warn};
|
||||||
|
|
||||||
/// Migration options
|
/// Migration options
|
||||||
|
#[derive(Default)]
|
||||||
pub struct MigrateOptions {
|
pub struct MigrateOptions {
|
||||||
/// If true, show what would be migrated without copying
|
/// If true, show what would be migrated without copying
|
||||||
pub dry_run: bool,
|
pub dry_run: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MigrateOptions {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self { dry_run: false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Migration statistics
|
/// Migration statistics
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct MigrateStats {
|
pub struct MigrateStats {
|
||||||
@@ -64,7 +59,9 @@ pub async fn migrate(
|
|||||||
let pb = ProgressBar::new(keys.len() as u64);
|
let pb = ProgressBar::new(keys.len() as u64);
|
||||||
pb.set_style(
|
pb.set_style(
|
||||||
ProgressStyle::default_bar()
|
ProgressStyle::default_bar()
|
||||||
.template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})")
|
.template(
|
||||||
|
"{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})",
|
||||||
|
)
|
||||||
.expect("Invalid progress bar template")
|
.expect("Invalid progress bar template")
|
||||||
.progress_chars("#>-"),
|
.progress_chars("#>-"),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use crate::AppState;
|
|||||||
#[openapi(
|
#[openapi(
|
||||||
info(
|
info(
|
||||||
title = "Nora",
|
title = "Nora",
|
||||||
version = "0.1.0",
|
version = "0.2.10",
|
||||||
description = "Multi-protocol package registry supporting Docker, Maven, npm, Cargo, and PyPI",
|
description = "Multi-protocol package registry supporting Docker, Maven, npm, Cargo, and PyPI",
|
||||||
license(name = "MIT"),
|
license(name = "MIT"),
|
||||||
contact(name = "DevITWay", url = "https://github.com/getnora-io/nora")
|
contact(name = "DevITWay", url = "https://github.com/getnora-io/nora")
|
||||||
@@ -25,6 +25,7 @@ use crate::AppState;
|
|||||||
),
|
),
|
||||||
tags(
|
tags(
|
||||||
(name = "health", description = "Health check endpoints"),
|
(name = "health", description = "Health check endpoints"),
|
||||||
|
(name = "dashboard", description = "Dashboard & Metrics API"),
|
||||||
(name = "docker", description = "Docker Registry v2 API"),
|
(name = "docker", description = "Docker Registry v2 API"),
|
||||||
(name = "maven", description = "Maven Repository API"),
|
(name = "maven", description = "Maven Repository API"),
|
||||||
(name = "npm", description = "npm Registry API"),
|
(name = "npm", description = "npm Registry API"),
|
||||||
@@ -36,6 +37,8 @@ use crate::AppState;
|
|||||||
// Health
|
// Health
|
||||||
crate::openapi::health_check,
|
crate::openapi::health_check,
|
||||||
crate::openapi::readiness_check,
|
crate::openapi::readiness_check,
|
||||||
|
// Dashboard
|
||||||
|
crate::openapi::dashboard_metrics,
|
||||||
// Docker
|
// Docker
|
||||||
crate::openapi::docker_version,
|
crate::openapi::docker_version,
|
||||||
crate::openapi::docker_catalog,
|
crate::openapi::docker_catalog,
|
||||||
@@ -59,6 +62,11 @@ use crate::AppState;
|
|||||||
HealthResponse,
|
HealthResponse,
|
||||||
StorageHealth,
|
StorageHealth,
|
||||||
RegistriesHealth,
|
RegistriesHealth,
|
||||||
|
DashboardResponse,
|
||||||
|
GlobalStats,
|
||||||
|
RegistryCardStats,
|
||||||
|
MountPoint,
|
||||||
|
ActivityEntry,
|
||||||
DockerVersion,
|
DockerVersion,
|
||||||
DockerCatalog,
|
DockerCatalog,
|
||||||
DockerTags,
|
DockerTags,
|
||||||
@@ -182,6 +190,72 @@ pub struct ErrorResponse {
|
|||||||
pub error: String,
|
pub error: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, ToSchema)]
|
||||||
|
pub struct DashboardResponse {
|
||||||
|
/// Global statistics across all registries
|
||||||
|
pub global_stats: GlobalStats,
|
||||||
|
/// Per-registry statistics
|
||||||
|
pub registry_stats: Vec<RegistryCardStats>,
|
||||||
|
/// Registry mount points and proxy configuration
|
||||||
|
pub mount_points: Vec<MountPoint>,
|
||||||
|
/// Recent activity log entries
|
||||||
|
pub activity: Vec<ActivityEntry>,
|
||||||
|
/// Server uptime in seconds
|
||||||
|
pub uptime_seconds: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, ToSchema)]
|
||||||
|
pub struct GlobalStats {
|
||||||
|
/// Total downloads across all registries
|
||||||
|
pub downloads: u64,
|
||||||
|
/// Total uploads across all registries
|
||||||
|
pub uploads: u64,
|
||||||
|
/// Total artifact count
|
||||||
|
pub artifacts: u64,
|
||||||
|
/// Cache hit percentage (0-100)
|
||||||
|
pub cache_hit_percent: f64,
|
||||||
|
/// Total storage used in bytes
|
||||||
|
pub storage_bytes: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, ToSchema)]
|
||||||
|
pub struct RegistryCardStats {
|
||||||
|
/// Registry name (docker, maven, npm, cargo, pypi)
|
||||||
|
pub name: String,
|
||||||
|
/// Number of artifacts in this registry
|
||||||
|
pub artifact_count: usize,
|
||||||
|
/// Download count for this registry
|
||||||
|
pub downloads: u64,
|
||||||
|
/// Upload count for this registry
|
||||||
|
pub uploads: u64,
|
||||||
|
/// Storage used by this registry in bytes
|
||||||
|
pub size_bytes: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, ToSchema)]
|
||||||
|
pub struct MountPoint {
|
||||||
|
/// Registry display name
|
||||||
|
pub registry: String,
|
||||||
|
/// URL mount path (e.g., /v2/, /maven2/)
|
||||||
|
pub mount_path: String,
|
||||||
|
/// Upstream proxy URL if configured
|
||||||
|
pub proxy_upstream: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, ToSchema)]
|
||||||
|
pub struct ActivityEntry {
|
||||||
|
/// ISO 8601 timestamp
|
||||||
|
pub timestamp: String,
|
||||||
|
/// Action type (Pull, Push, CacheHit, ProxyFetch)
|
||||||
|
pub action: String,
|
||||||
|
/// Artifact name/identifier
|
||||||
|
pub artifact: String,
|
||||||
|
/// Registry type
|
||||||
|
pub registry: String,
|
||||||
|
/// Source (LOCAL, PROXY, CACHE)
|
||||||
|
pub source: String,
|
||||||
|
}
|
||||||
|
|
||||||
// ============ Path Operations (documentation only) ============
|
// ============ Path Operations (documentation only) ============
|
||||||
|
|
||||||
/// Health check endpoint
|
/// Health check endpoint
|
||||||
@@ -208,6 +282,20 @@ pub async fn health_check() {}
|
|||||||
)]
|
)]
|
||||||
pub async fn readiness_check() {}
|
pub async fn readiness_check() {}
|
||||||
|
|
||||||
|
/// Dashboard metrics and activity
|
||||||
|
///
|
||||||
|
/// Returns comprehensive metrics including downloads, uploads, cache statistics,
|
||||||
|
/// per-registry stats, mount points configuration, and recent activity log.
|
||||||
|
#[utoipa::path(
|
||||||
|
get,
|
||||||
|
path = "/api/ui/dashboard",
|
||||||
|
tag = "dashboard",
|
||||||
|
responses(
|
||||||
|
(status = 200, description = "Dashboard metrics", body = DashboardResponse)
|
||||||
|
)
|
||||||
|
)]
|
||||||
|
pub async fn dashboard_metrics() {}
|
||||||
|
|
||||||
/// Docker Registry version check
|
/// Docker Registry version check
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
get,
|
get,
|
||||||
|
|||||||
@@ -5,117 +5,109 @@
|
|||||||
//! - DoS attacks on upload endpoints
|
//! - DoS attacks on upload endpoints
|
||||||
//! - General API abuse
|
//! - General API abuse
|
||||||
|
|
||||||
|
use crate::config::RateLimitConfig;
|
||||||
use tower_governor::governor::GovernorConfigBuilder;
|
use tower_governor::governor::GovernorConfigBuilder;
|
||||||
|
|
||||||
/// Rate limit configuration
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct RateLimitConfig {
|
|
||||||
/// Requests per second for auth endpoints (strict)
|
|
||||||
pub auth_rps: u32,
|
|
||||||
/// Burst size for auth endpoints
|
|
||||||
pub auth_burst: u32,
|
|
||||||
/// Requests per second for upload endpoints
|
|
||||||
pub upload_rps: u32,
|
|
||||||
/// Burst size for upload endpoints
|
|
||||||
pub upload_burst: u32,
|
|
||||||
/// Requests per second for general endpoints (lenient)
|
|
||||||
pub general_rps: u32,
|
|
||||||
/// Burst size for general endpoints
|
|
||||||
pub general_burst: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RateLimitConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
auth_rps: 1, // 1 req/sec for auth (strict)
|
|
||||||
auth_burst: 5, // Allow burst of 5
|
|
||||||
upload_rps: 10, // 10 req/sec for uploads
|
|
||||||
upload_burst: 20, // Allow burst of 20
|
|
||||||
general_rps: 100, // 100 req/sec general
|
|
||||||
general_burst: 200, // Allow burst of 200
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create rate limiter layer for auth endpoints (strict protection against brute-force)
|
/// Create rate limiter layer for auth endpoints (strict protection against brute-force)
|
||||||
///
|
pub fn auth_rate_limiter(
|
||||||
/// Default: 1 request per second, burst of 5
|
config: &RateLimitConfig,
|
||||||
pub fn auth_rate_limiter() -> tower_governor::GovernorLayer<
|
) -> tower_governor::GovernorLayer<
|
||||||
tower_governor::key_extractor::PeerIpKeyExtractor,
|
tower_governor::key_extractor::PeerIpKeyExtractor,
|
||||||
governor::middleware::StateInformationMiddleware,
|
governor::middleware::StateInformationMiddleware,
|
||||||
axum::body::Body,
|
axum::body::Body,
|
||||||
> {
|
> {
|
||||||
let config = GovernorConfigBuilder::default()
|
let gov_config = GovernorConfigBuilder::default()
|
||||||
.per_second(1)
|
.per_second(config.auth_rps)
|
||||||
.burst_size(5)
|
.burst_size(config.auth_burst)
|
||||||
.use_headers()
|
.use_headers()
|
||||||
.finish()
|
.finish()
|
||||||
.unwrap();
|
.expect("Failed to build auth rate limiter");
|
||||||
|
|
||||||
tower_governor::GovernorLayer::new(config)
|
tower_governor::GovernorLayer::new(gov_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create rate limiter layer for upload endpoints
|
/// Create rate limiter layer for upload endpoints
|
||||||
///
|
///
|
||||||
/// Default: 10 requests per second, burst of 20
|
/// High limits to accommodate Docker client's aggressive parallel layer uploads
|
||||||
pub fn upload_rate_limiter() -> tower_governor::GovernorLayer<
|
pub fn upload_rate_limiter(
|
||||||
|
config: &RateLimitConfig,
|
||||||
|
) -> tower_governor::GovernorLayer<
|
||||||
tower_governor::key_extractor::PeerIpKeyExtractor,
|
tower_governor::key_extractor::PeerIpKeyExtractor,
|
||||||
governor::middleware::StateInformationMiddleware,
|
governor::middleware::StateInformationMiddleware,
|
||||||
axum::body::Body,
|
axum::body::Body,
|
||||||
> {
|
> {
|
||||||
let config = GovernorConfigBuilder::default()
|
let gov_config = GovernorConfigBuilder::default()
|
||||||
.per_second(10)
|
.per_second(config.upload_rps)
|
||||||
.burst_size(20)
|
.burst_size(config.upload_burst)
|
||||||
.use_headers()
|
.use_headers()
|
||||||
.finish()
|
.finish()
|
||||||
.unwrap();
|
.expect("Failed to build upload rate limiter");
|
||||||
|
|
||||||
tower_governor::GovernorLayer::new(config)
|
tower_governor::GovernorLayer::new(gov_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create rate limiter layer for general endpoints (lenient)
|
/// Create rate limiter layer for general endpoints (lenient)
|
||||||
///
|
pub fn general_rate_limiter(
|
||||||
/// Default: 100 requests per second, burst of 200
|
config: &RateLimitConfig,
|
||||||
pub fn general_rate_limiter() -> tower_governor::GovernorLayer<
|
) -> tower_governor::GovernorLayer<
|
||||||
tower_governor::key_extractor::PeerIpKeyExtractor,
|
tower_governor::key_extractor::PeerIpKeyExtractor,
|
||||||
governor::middleware::StateInformationMiddleware,
|
governor::middleware::StateInformationMiddleware,
|
||||||
axum::body::Body,
|
axum::body::Body,
|
||||||
> {
|
> {
|
||||||
let config = GovernorConfigBuilder::default()
|
let gov_config = GovernorConfigBuilder::default()
|
||||||
.per_second(100)
|
.per_second(config.general_rps)
|
||||||
.burst_size(200)
|
.burst_size(config.general_burst)
|
||||||
.use_headers()
|
.use_headers()
|
||||||
.finish()
|
.finish()
|
||||||
.unwrap();
|
.expect("Failed to build general rate limiter");
|
||||||
|
|
||||||
tower_governor::GovernorLayer::new(config)
|
tower_governor::GovernorLayer::new(gov_config)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::config::RateLimitConfig;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_default_config() {
|
fn test_default_config() {
|
||||||
let config = RateLimitConfig::default();
|
let config = RateLimitConfig::default();
|
||||||
assert_eq!(config.auth_rps, 1);
|
assert_eq!(config.auth_rps, 1);
|
||||||
assert_eq!(config.auth_burst, 5);
|
assert_eq!(config.auth_burst, 5);
|
||||||
assert_eq!(config.upload_rps, 10);
|
assert_eq!(config.upload_rps, 200);
|
||||||
assert_eq!(config.general_rps, 100);
|
assert_eq!(config.general_rps, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_auth_rate_limiter_creation() {
|
fn test_auth_rate_limiter_creation() {
|
||||||
let _limiter = auth_rate_limiter();
|
let config = RateLimitConfig::default();
|
||||||
|
let _limiter = auth_rate_limiter(&config);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_upload_rate_limiter_creation() {
|
fn test_upload_rate_limiter_creation() {
|
||||||
let _limiter = upload_rate_limiter();
|
let config = RateLimitConfig::default();
|
||||||
|
let _limiter = upload_rate_limiter(&config);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_general_rate_limiter_creation() {
|
fn test_general_rate_limiter_creation() {
|
||||||
let _limiter = general_rate_limiter();
|
let config = RateLimitConfig::default();
|
||||||
|
let _limiter = general_rate_limiter(&config);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_custom_config() {
|
||||||
|
let config = RateLimitConfig {
|
||||||
|
auth_rps: 10,
|
||||||
|
auth_burst: 20,
|
||||||
|
upload_rps: 500,
|
||||||
|
upload_burst: 1000,
|
||||||
|
general_rps: 200,
|
||||||
|
general_burst: 400,
|
||||||
|
};
|
||||||
|
let _auth = auth_rate_limiter(&config);
|
||||||
|
let _upload = upload_rate_limiter(&config);
|
||||||
|
let _general = general_rate_limiter(&config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::activity_log::{ActionType, ActivityEntry};
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
@@ -37,7 +38,17 @@ async fn download(
|
|||||||
crate_name, version, crate_name, version
|
crate_name, version, crate_name, version
|
||||||
);
|
);
|
||||||
match state.storage.get(&key).await {
|
match state.storage.get(&key).await {
|
||||||
Ok(data) => (StatusCode::OK, data).into_response(),
|
Ok(data) => {
|
||||||
|
state.metrics.record_download("cargo");
|
||||||
|
state.metrics.record_cache_hit();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::Pull,
|
||||||
|
format!("{}@{}", crate_name, version),
|
||||||
|
"cargo",
|
||||||
|
"LOCAL",
|
||||||
|
));
|
||||||
|
(StatusCode::OK, data).into_response()
|
||||||
|
}
|
||||||
Err(_) => StatusCode::NOT_FOUND.into_response(),
|
Err(_) => StatusCode::NOT_FOUND.into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
use crate::activity_log::{ActionType, ActivityEntry};
|
||||||
|
use crate::registry::docker_auth::DockerAuth;
|
||||||
|
use crate::storage::Storage;
|
||||||
use crate::validation::{validate_digest, validate_docker_name, validate_docker_reference};
|
use crate::validation::{validate_digest, validate_docker_name, validate_docker_reference};
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use axum::{
|
use axum::{
|
||||||
@@ -5,11 +8,41 @@ use axum::{
|
|||||||
extract::{Path, State},
|
extract::{Path, State},
|
||||||
http::{header, HeaderName, StatusCode},
|
http::{header, HeaderName, StatusCode},
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
routing::{get, head, put},
|
routing::{get, head, patch, put},
|
||||||
Json, Router,
|
Json, Router,
|
||||||
};
|
};
|
||||||
|
use parking_lot::RwLock;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
/// Metadata for a Docker image stored alongside manifests
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
|
pub struct ImageMetadata {
|
||||||
|
pub push_timestamp: u64,
|
||||||
|
pub last_pulled: u64,
|
||||||
|
pub downloads: u64,
|
||||||
|
pub size_bytes: u64,
|
||||||
|
pub os: String,
|
||||||
|
pub arch: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub variant: Option<String>,
|
||||||
|
pub layers: Vec<LayerInfo>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Information about a single layer in a Docker image
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct LayerInfo {
|
||||||
|
pub digest: String,
|
||||||
|
pub size: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// In-progress upload sessions for chunked uploads
|
||||||
|
/// Maps UUID -> accumulated data
|
||||||
|
static UPLOAD_SESSIONS: std::sync::LazyLock<RwLock<HashMap<String, Vec<u8>>>> =
|
||||||
|
std::sync::LazyLock::new(|| RwLock::new(HashMap::new()));
|
||||||
|
|
||||||
pub fn routes() -> Router<Arc<AppState>> {
|
pub fn routes() -> Router<Arc<AppState>> {
|
||||||
Router::new()
|
Router::new()
|
||||||
@@ -20,7 +53,10 @@ pub fn routes() -> Router<Arc<AppState>> {
|
|||||||
"/v2/{name}/blobs/uploads/",
|
"/v2/{name}/blobs/uploads/",
|
||||||
axum::routing::post(start_upload),
|
axum::routing::post(start_upload),
|
||||||
)
|
)
|
||||||
.route("/v2/{name}/blobs/uploads/{uuid}", put(upload_blob))
|
.route(
|
||||||
|
"/v2/{name}/blobs/uploads/{uuid}",
|
||||||
|
patch(patch_blob).put(upload_blob),
|
||||||
|
)
|
||||||
.route("/v2/{name}/manifests/{reference}", get(get_manifest))
|
.route("/v2/{name}/manifests/{reference}", get(get_manifest))
|
||||||
.route("/v2/{name}/manifests/{reference}", put(put_manifest))
|
.route("/v2/{name}/manifests/{reference}", put(put_manifest))
|
||||||
.route("/v2/{name}/tags/list", get(list_tags))
|
.route("/v2/{name}/tags/list", get(list_tags))
|
||||||
@@ -64,15 +100,63 @@ async fn download_blob(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let key = format!("docker/{}/blobs/{}", name, digest);
|
let key = format!("docker/{}/blobs/{}", name, digest);
|
||||||
match state.storage.get(&key).await {
|
|
||||||
Ok(data) => (
|
// Try local storage first
|
||||||
|
if let Ok(data) = state.storage.get(&key).await {
|
||||||
|
state.metrics.record_download("docker");
|
||||||
|
state.metrics.record_cache_hit();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::Pull,
|
||||||
|
format!("{}@{}", name, &digest[..19.min(digest.len())]),
|
||||||
|
"docker",
|
||||||
|
"LOCAL",
|
||||||
|
));
|
||||||
|
return (
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[(header::CONTENT_TYPE, "application/octet-stream")],
|
[(header::CONTENT_TYPE, "application/octet-stream")],
|
||||||
data,
|
data,
|
||||||
)
|
)
|
||||||
.into_response(),
|
.into_response();
|
||||||
Err(_) => StatusCode::NOT_FOUND.into_response(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try upstream proxies
|
||||||
|
for upstream in &state.config.docker.upstreams {
|
||||||
|
if let Ok(data) = fetch_blob_from_upstream(
|
||||||
|
&upstream.url,
|
||||||
|
&name,
|
||||||
|
&digest,
|
||||||
|
&state.docker_auth,
|
||||||
|
state.config.docker.proxy_timeout,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
state.metrics.record_download("docker");
|
||||||
|
state.metrics.record_cache_miss();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::ProxyFetch,
|
||||||
|
format!("{}@{}", name, &digest[..19.min(digest.len())]),
|
||||||
|
"docker",
|
||||||
|
"PROXY",
|
||||||
|
));
|
||||||
|
|
||||||
|
// Cache in storage (fire and forget)
|
||||||
|
let storage = state.storage.clone();
|
||||||
|
let key_clone = key.clone();
|
||||||
|
let data_clone = data.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let _ = storage.put(&key_clone, &data_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
StatusCode::OK,
|
||||||
|
[(header::CONTENT_TYPE, "application/octet-stream")],
|
||||||
|
Bytes::from(data),
|
||||||
|
)
|
||||||
|
.into_response();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusCode::NOT_FOUND.into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_upload(Path(name): Path<String>) -> Response {
|
async fn start_upload(Path(name): Path<String>) -> Response {
|
||||||
@@ -92,9 +176,46 @@ async fn start_upload(Path(name): Path<String>) -> Response {
|
|||||||
.into_response()
|
.into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// PATCH handler for chunked blob uploads
|
||||||
|
/// Docker client sends data chunks via PATCH, then finalizes with PUT
|
||||||
|
async fn patch_blob(Path((name, uuid)): Path<(String, String)>, body: Bytes) -> Response {
|
||||||
|
if let Err(e) = validate_docker_name(&name) {
|
||||||
|
return (StatusCode::BAD_REQUEST, e.to_string()).into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append data to the upload session and get total size
|
||||||
|
let total_size = {
|
||||||
|
let mut sessions = UPLOAD_SESSIONS.write();
|
||||||
|
let session = sessions.entry(uuid.clone()).or_default();
|
||||||
|
session.extend_from_slice(&body);
|
||||||
|
session.len()
|
||||||
|
};
|
||||||
|
|
||||||
|
let location = format!("/v2/{}/blobs/uploads/{}", name, uuid);
|
||||||
|
// Range header indicates bytes 0 to (total_size - 1) have been received
|
||||||
|
let range = if total_size > 0 {
|
||||||
|
format!("0-{}", total_size - 1)
|
||||||
|
} else {
|
||||||
|
"0-0".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
(
|
||||||
|
StatusCode::ACCEPTED,
|
||||||
|
[
|
||||||
|
(header::LOCATION, location),
|
||||||
|
(header::RANGE, range),
|
||||||
|
(HeaderName::from_static("docker-upload-uuid"), uuid),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.into_response()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PUT handler for completing blob uploads
|
||||||
|
/// Handles both monolithic uploads (body contains all data) and
|
||||||
|
/// chunked upload finalization (body may be empty, data in session)
|
||||||
async fn upload_blob(
|
async fn upload_blob(
|
||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
Path((name, _uuid)): Path<(String, String)>,
|
Path((name, uuid)): Path<(String, String)>,
|
||||||
axum::extract::Query(params): axum::extract::Query<std::collections::HashMap<String, String>>,
|
axum::extract::Query(params): axum::extract::Query<std::collections::HashMap<String, String>>,
|
||||||
body: Bytes,
|
body: Bytes,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
@@ -111,9 +232,31 @@ async fn upload_blob(
|
|||||||
return (StatusCode::BAD_REQUEST, e.to_string()).into_response();
|
return (StatusCode::BAD_REQUEST, e.to_string()).into_response();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get data from chunked session if exists, otherwise use body directly
|
||||||
|
let data = {
|
||||||
|
let mut sessions = UPLOAD_SESSIONS.write();
|
||||||
|
if let Some(mut session_data) = sessions.remove(&uuid) {
|
||||||
|
// Chunked upload: append any final body data and use session
|
||||||
|
if !body.is_empty() {
|
||||||
|
session_data.extend_from_slice(&body);
|
||||||
|
}
|
||||||
|
session_data
|
||||||
|
} else {
|
||||||
|
// Monolithic upload: use body directly
|
||||||
|
body.to_vec()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let key = format!("docker/{}/blobs/{}", name, digest);
|
let key = format!("docker/{}/blobs/{}", name, digest);
|
||||||
match state.storage.put(&key, &body).await {
|
match state.storage.put(&key, &data).await {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
|
state.metrics.record_upload("docker");
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::Push,
|
||||||
|
format!("{}@{}", name, &digest[..19.min(digest.len())]),
|
||||||
|
"docker",
|
||||||
|
"LOCAL",
|
||||||
|
));
|
||||||
let location = format!("/v2/{}/blobs/{}", name, digest);
|
let location = format!("/v2/{}/blobs/{}", name, digest);
|
||||||
(StatusCode::CREATED, [(header::LOCATION, location)]).into_response()
|
(StatusCode::CREATED, [(header::LOCATION, location)]).into_response()
|
||||||
}
|
}
|
||||||
@@ -133,18 +276,106 @@ async fn get_manifest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let key = format!("docker/{}/manifests/{}.json", name, reference);
|
let key = format!("docker/{}/manifests/{}.json", name, reference);
|
||||||
match state.storage.get(&key).await {
|
|
||||||
Ok(data) => (
|
// Try local storage first
|
||||||
|
if let Ok(data) = state.storage.get(&key).await {
|
||||||
|
state.metrics.record_download("docker");
|
||||||
|
state.metrics.record_cache_hit();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::Pull,
|
||||||
|
format!("{}:{}", name, reference),
|
||||||
|
"docker",
|
||||||
|
"LOCAL",
|
||||||
|
));
|
||||||
|
|
||||||
|
// Calculate digest for Docker-Content-Digest header
|
||||||
|
use sha2::Digest;
|
||||||
|
let digest = format!("sha256:{:x}", sha2::Sha256::digest(&data));
|
||||||
|
|
||||||
|
// Detect manifest media type from content
|
||||||
|
let content_type = detect_manifest_media_type(&data);
|
||||||
|
|
||||||
|
// Update metadata (downloads, last_pulled) in background
|
||||||
|
let meta_key = format!("docker/{}/manifests/{}.meta.json", name, reference);
|
||||||
|
let storage_clone = state.storage.clone();
|
||||||
|
tokio::spawn(update_metadata_on_pull(storage_clone, meta_key));
|
||||||
|
|
||||||
|
return (
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
[(
|
[
|
||||||
header::CONTENT_TYPE,
|
(header::CONTENT_TYPE, content_type),
|
||||||
"application/vnd.docker.distribution.manifest.v2+json",
|
(HeaderName::from_static("docker-content-digest"), digest),
|
||||||
)],
|
],
|
||||||
data,
|
data,
|
||||||
)
|
)
|
||||||
.into_response(),
|
.into_response();
|
||||||
Err(_) => StatusCode::NOT_FOUND.into_response(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try upstream proxies
|
||||||
|
for upstream in &state.config.docker.upstreams {
|
||||||
|
if let Ok((data, content_type)) = fetch_manifest_from_upstream(
|
||||||
|
&upstream.url,
|
||||||
|
&name,
|
||||||
|
&reference,
|
||||||
|
&state.docker_auth,
|
||||||
|
state.config.docker.proxy_timeout,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
state.metrics.record_download("docker");
|
||||||
|
state.metrics.record_cache_miss();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::ProxyFetch,
|
||||||
|
format!("{}:{}", name, reference),
|
||||||
|
"docker",
|
||||||
|
"PROXY",
|
||||||
|
));
|
||||||
|
|
||||||
|
// Calculate digest for Docker-Content-Digest header
|
||||||
|
use sha2::Digest;
|
||||||
|
let digest = format!("sha256:{:x}", sha2::Sha256::digest(&data));
|
||||||
|
|
||||||
|
// Cache manifest and create metadata (fire and forget)
|
||||||
|
let storage = state.storage.clone();
|
||||||
|
let key_clone = key.clone();
|
||||||
|
let data_clone = data.clone();
|
||||||
|
let name_clone = name.clone();
|
||||||
|
let reference_clone = reference.clone();
|
||||||
|
let digest_clone = digest.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
// Store manifest by tag and digest
|
||||||
|
let _ = storage.put(&key_clone, &data_clone).await;
|
||||||
|
let digest_key = format!("docker/{}/manifests/{}.json", name_clone, digest_clone);
|
||||||
|
let _ = storage.put(&digest_key, &data_clone).await;
|
||||||
|
|
||||||
|
// Extract and save metadata
|
||||||
|
let metadata = extract_metadata(&data_clone, &storage, &name_clone).await;
|
||||||
|
if let Ok(meta_json) = serde_json::to_vec(&metadata) {
|
||||||
|
let meta_key = format!(
|
||||||
|
"docker/{}/manifests/{}.meta.json",
|
||||||
|
name_clone, reference_clone
|
||||||
|
);
|
||||||
|
let _ = storage.put(&meta_key, &meta_json).await;
|
||||||
|
|
||||||
|
let digest_meta_key =
|
||||||
|
format!("docker/{}/manifests/{}.meta.json", name_clone, digest_clone);
|
||||||
|
let _ = storage.put(&digest_meta_key, &meta_json).await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
StatusCode::OK,
|
||||||
|
[
|
||||||
|
(header::CONTENT_TYPE, content_type),
|
||||||
|
(HeaderName::from_static("docker-content-digest"), digest),
|
||||||
|
],
|
||||||
|
Bytes::from(data),
|
||||||
|
)
|
||||||
|
.into_response();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusCode::NOT_FOUND.into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn put_manifest(
|
async fn put_manifest(
|
||||||
@@ -159,11 +390,41 @@ async fn put_manifest(
|
|||||||
return (StatusCode::BAD_REQUEST, e.to_string()).into_response();
|
return (StatusCode::BAD_REQUEST, e.to_string()).into_response();
|
||||||
}
|
}
|
||||||
|
|
||||||
let key = format!("docker/{}/manifests/{}.json", name, reference);
|
// Calculate digest
|
||||||
match state.storage.put(&key, &body).await {
|
|
||||||
Ok(()) => {
|
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
let digest = format!("sha256:{:x}", sha2::Sha256::digest(&body));
|
let digest = format!("sha256:{:x}", sha2::Sha256::digest(&body));
|
||||||
|
|
||||||
|
// Store by tag/reference
|
||||||
|
let key = format!("docker/{}/manifests/{}.json", name, reference);
|
||||||
|
if state.storage.put(&key, &body).await.is_err() {
|
||||||
|
return StatusCode::INTERNAL_SERVER_ERROR.into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Also store by digest for direct digest lookups
|
||||||
|
let digest_key = format!("docker/{}/manifests/{}.json", name, digest);
|
||||||
|
if state.storage.put(&digest_key, &body).await.is_err() {
|
||||||
|
return StatusCode::INTERNAL_SERVER_ERROR.into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract and save metadata
|
||||||
|
let metadata = extract_metadata(&body, &state.storage, &name).await;
|
||||||
|
let meta_key = format!("docker/{}/manifests/{}.meta.json", name, reference);
|
||||||
|
if let Ok(meta_json) = serde_json::to_vec(&metadata) {
|
||||||
|
let _ = state.storage.put(&meta_key, &meta_json).await;
|
||||||
|
|
||||||
|
// Also save metadata by digest
|
||||||
|
let digest_meta_key = format!("docker/{}/manifests/{}.meta.json", name, digest);
|
||||||
|
let _ = state.storage.put(&digest_meta_key, &meta_json).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.metrics.record_upload("docker");
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::Push,
|
||||||
|
format!("{}:{}", name, reference),
|
||||||
|
"docker",
|
||||||
|
"LOCAL",
|
||||||
|
));
|
||||||
|
|
||||||
let location = format!("/v2/{}/manifests/{}", name, reference);
|
let location = format!("/v2/{}/manifests/{}", name, reference);
|
||||||
(
|
(
|
||||||
StatusCode::CREATED,
|
StatusCode::CREATED,
|
||||||
@@ -173,15 +434,9 @@ async fn put_manifest(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
.into_response()
|
.into_response()
|
||||||
}
|
|
||||||
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_tags(
|
async fn list_tags(State(state): State<Arc<AppState>>, Path(name): Path<String>) -> Response {
|
||||||
State(state): State<Arc<AppState>>,
|
|
||||||
Path(name): Path<String>,
|
|
||||||
) -> Response {
|
|
||||||
if let Err(e) = validate_docker_name(&name) {
|
if let Err(e) = validate_docker_name(&name) {
|
||||||
return (StatusCode::BAD_REQUEST, e.to_string()).into_response();
|
return (StatusCode::BAD_REQUEST, e.to_string()).into_response();
|
||||||
}
|
}
|
||||||
@@ -198,3 +453,314 @@ async fn list_tags(
|
|||||||
.collect();
|
.collect();
|
||||||
(StatusCode::OK, Json(json!({"name": name, "tags": tags}))).into_response()
|
(StatusCode::OK, Json(json!({"name": name, "tags": tags}))).into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Fetch a blob from an upstream Docker registry
|
||||||
|
async fn fetch_blob_from_upstream(
|
||||||
|
upstream_url: &str,
|
||||||
|
name: &str,
|
||||||
|
digest: &str,
|
||||||
|
docker_auth: &DockerAuth,
|
||||||
|
timeout: u64,
|
||||||
|
) -> Result<Vec<u8>, ()> {
|
||||||
|
let url = format!(
|
||||||
|
"{}/v2/{}/blobs/{}",
|
||||||
|
upstream_url.trim_end_matches('/'),
|
||||||
|
name,
|
||||||
|
digest
|
||||||
|
);
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.timeout(Duration::from_secs(timeout))
|
||||||
|
.build()
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
|
// First try without auth
|
||||||
|
let response = client.get(&url).send().await.map_err(|_| ())?;
|
||||||
|
|
||||||
|
let response = if response.status() == reqwest::StatusCode::UNAUTHORIZED {
|
||||||
|
// Get Www-Authenticate header and fetch token
|
||||||
|
let www_auth = response
|
||||||
|
.headers()
|
||||||
|
.get("www-authenticate")
|
||||||
|
.and_then(|v| v.to_str().ok())
|
||||||
|
.map(String::from);
|
||||||
|
|
||||||
|
if let Some(token) = docker_auth
|
||||||
|
.get_token(upstream_url, name, www_auth.as_deref())
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
client
|
||||||
|
.get(&url)
|
||||||
|
.header("Authorization", format!("Bearer {}", token))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|_| ())?
|
||||||
|
} else {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
response
|
||||||
|
};
|
||||||
|
|
||||||
|
if !response.status().is_success() {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
response.bytes().await.map(|b| b.to_vec()).map_err(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch a manifest from an upstream Docker registry
|
||||||
|
/// Returns (manifest_bytes, content_type)
|
||||||
|
async fn fetch_manifest_from_upstream(
|
||||||
|
upstream_url: &str,
|
||||||
|
name: &str,
|
||||||
|
reference: &str,
|
||||||
|
docker_auth: &DockerAuth,
|
||||||
|
timeout: u64,
|
||||||
|
) -> Result<(Vec<u8>, String), ()> {
|
||||||
|
let url = format!(
|
||||||
|
"{}/v2/{}/manifests/{}",
|
||||||
|
upstream_url.trim_end_matches('/'),
|
||||||
|
name,
|
||||||
|
reference
|
||||||
|
);
|
||||||
|
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.timeout(Duration::from_secs(timeout))
|
||||||
|
.build()
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
|
// Request with Accept header for manifest types
|
||||||
|
let accept_header = "application/vnd.docker.distribution.manifest.v2+json, \
|
||||||
|
application/vnd.docker.distribution.manifest.list.v2+json, \
|
||||||
|
application/vnd.oci.image.manifest.v1+json, \
|
||||||
|
application/vnd.oci.image.index.v1+json";
|
||||||
|
|
||||||
|
// First try without auth
|
||||||
|
let response = client
|
||||||
|
.get(&url)
|
||||||
|
.header("Accept", accept_header)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
|
let response = if response.status() == reqwest::StatusCode::UNAUTHORIZED {
|
||||||
|
// Get Www-Authenticate header and fetch token
|
||||||
|
let www_auth = response
|
||||||
|
.headers()
|
||||||
|
.get("www-authenticate")
|
||||||
|
.and_then(|v| v.to_str().ok())
|
||||||
|
.map(String::from);
|
||||||
|
|
||||||
|
if let Some(token) = docker_auth
|
||||||
|
.get_token(upstream_url, name, www_auth.as_deref())
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
client
|
||||||
|
.get(&url)
|
||||||
|
.header("Accept", accept_header)
|
||||||
|
.header("Authorization", format!("Bearer {}", token))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|_| ())?
|
||||||
|
} else {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
response
|
||||||
|
};
|
||||||
|
|
||||||
|
if !response.status().is_success() {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let content_type = response
|
||||||
|
.headers()
|
||||||
|
.get("content-type")
|
||||||
|
.and_then(|v| v.to_str().ok())
|
||||||
|
.unwrap_or("application/vnd.docker.distribution.manifest.v2+json")
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
let bytes = response.bytes().await.map_err(|_| ())?;
|
||||||
|
|
||||||
|
Ok((bytes.to_vec(), content_type))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Detect manifest media type from its JSON content
|
||||||
|
fn detect_manifest_media_type(data: &[u8]) -> String {
|
||||||
|
// Try to parse as JSON and extract mediaType
|
||||||
|
if let Ok(json) = serde_json::from_slice::<Value>(data) {
|
||||||
|
if let Some(media_type) = json.get("mediaType").and_then(|v| v.as_str()) {
|
||||||
|
return media_type.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check schemaVersion for older manifests
|
||||||
|
if let Some(schema_version) = json.get("schemaVersion").and_then(|v| v.as_u64()) {
|
||||||
|
if schema_version == 1 {
|
||||||
|
return "application/vnd.docker.distribution.manifest.v1+json".to_string();
|
||||||
|
}
|
||||||
|
// schemaVersion 2 without mediaType is likely docker manifest v2
|
||||||
|
if json.get("config").is_some() {
|
||||||
|
return "application/vnd.docker.distribution.manifest.v2+json".to_string();
|
||||||
|
}
|
||||||
|
// If it has "manifests" array, it's an index/list
|
||||||
|
if json.get("manifests").is_some() {
|
||||||
|
return "application/vnd.oci.image.index.v1+json".to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default fallback
|
||||||
|
"application/vnd.docker.distribution.manifest.v2+json".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extract metadata from a Docker manifest
|
||||||
|
/// Handles both single-arch manifests and multi-arch indexes
|
||||||
|
async fn extract_metadata(manifest: &[u8], storage: &Storage, name: &str) -> ImageMetadata {
|
||||||
|
let now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_secs();
|
||||||
|
|
||||||
|
let mut metadata = ImageMetadata {
|
||||||
|
push_timestamp: now,
|
||||||
|
last_pulled: 0,
|
||||||
|
downloads: 0,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let Ok(json) = serde_json::from_slice::<Value>(manifest) else {
|
||||||
|
return metadata;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if this is a manifest list/index (multi-arch)
|
||||||
|
if json.get("manifests").is_some() {
|
||||||
|
// For multi-arch, extract info from the first platform manifest
|
||||||
|
if let Some(manifests) = json.get("manifests").and_then(|m| m.as_array()) {
|
||||||
|
// Sum sizes from all platform manifests
|
||||||
|
let total_size: u64 = manifests
|
||||||
|
.iter()
|
||||||
|
.filter_map(|m| m.get("size").and_then(|s| s.as_u64()))
|
||||||
|
.sum();
|
||||||
|
metadata.size_bytes = total_size;
|
||||||
|
|
||||||
|
// Get OS/arch from first platform (usually linux/amd64)
|
||||||
|
if let Some(first) = manifests.first() {
|
||||||
|
if let Some(platform) = first.get("platform") {
|
||||||
|
metadata.os = platform
|
||||||
|
.get("os")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("multi-arch")
|
||||||
|
.to_string();
|
||||||
|
metadata.arch = platform
|
||||||
|
.get("architecture")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("multi")
|
||||||
|
.to_string();
|
||||||
|
metadata.variant = platform
|
||||||
|
.get("variant")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.map(String::from);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single-arch manifest - extract layers
|
||||||
|
if let Some(layers) = json.get("layers").and_then(|l| l.as_array()) {
|
||||||
|
let mut total_size: u64 = 0;
|
||||||
|
for layer in layers {
|
||||||
|
let digest = layer
|
||||||
|
.get("digest")
|
||||||
|
.and_then(|d| d.as_str())
|
||||||
|
.unwrap_or("")
|
||||||
|
.to_string();
|
||||||
|
let size = layer.get("size").and_then(|s| s.as_u64()).unwrap_or(0);
|
||||||
|
total_size += size;
|
||||||
|
metadata.layers.push(LayerInfo { digest, size });
|
||||||
|
}
|
||||||
|
metadata.size_bytes = total_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to get OS/arch from config blob
|
||||||
|
if let Some(config) = json.get("config") {
|
||||||
|
if let Some(config_digest) = config.get("digest").and_then(|d| d.as_str()) {
|
||||||
|
let (os, arch, variant) = get_config_info(storage, name, config_digest).await;
|
||||||
|
metadata.os = os;
|
||||||
|
metadata.arch = arch;
|
||||||
|
metadata.variant = variant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we couldn't get OS/arch, set defaults
|
||||||
|
if metadata.os.is_empty() {
|
||||||
|
metadata.os = "unknown".to_string();
|
||||||
|
}
|
||||||
|
if metadata.arch.is_empty() {
|
||||||
|
metadata.arch = "unknown".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get OS/arch information from a config blob
|
||||||
|
async fn get_config_info(
|
||||||
|
storage: &Storage,
|
||||||
|
name: &str,
|
||||||
|
config_digest: &str,
|
||||||
|
) -> (String, String, Option<String>) {
|
||||||
|
let key = format!("docker/{}/blobs/{}", name, config_digest);
|
||||||
|
|
||||||
|
let Ok(data) = storage.get(&key).await else {
|
||||||
|
return ("unknown".to_string(), "unknown".to_string(), None);
|
||||||
|
};
|
||||||
|
|
||||||
|
let Ok(config) = serde_json::from_slice::<Value>(&data) else {
|
||||||
|
return ("unknown".to_string(), "unknown".to_string(), None);
|
||||||
|
};
|
||||||
|
|
||||||
|
let os = config
|
||||||
|
.get("os")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("unknown")
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
let arch = config
|
||||||
|
.get("architecture")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.unwrap_or("unknown")
|
||||||
|
.to_string();
|
||||||
|
|
||||||
|
let variant = config
|
||||||
|
.get("variant")
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.map(String::from);
|
||||||
|
|
||||||
|
(os, arch, variant)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update metadata when a manifest is pulled
|
||||||
|
/// Increments download counter and updates last_pulled timestamp
|
||||||
|
async fn update_metadata_on_pull(storage: Storage, meta_key: String) {
|
||||||
|
let now = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_secs();
|
||||||
|
|
||||||
|
// Try to read existing metadata
|
||||||
|
let mut metadata = if let Ok(data) = storage.get(&meta_key).await {
|
||||||
|
serde_json::from_slice::<ImageMetadata>(&data).unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
ImageMetadata::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update pull stats
|
||||||
|
metadata.downloads += 1;
|
||||||
|
metadata.last_pulled = now;
|
||||||
|
|
||||||
|
// Save back
|
||||||
|
if let Ok(json) = serde_json::to_vec(&metadata) {
|
||||||
|
let _ = storage.put(&meta_key, &json).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
189
nora-registry/src/registry/docker_auth.rs
Normal file
189
nora-registry/src/registry/docker_auth.rs
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
use parking_lot::RwLock;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
/// Cached Docker registry token
|
||||||
|
struct CachedToken {
|
||||||
|
token: String,
|
||||||
|
expires_at: Instant,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Docker registry authentication handler
|
||||||
|
/// Manages Bearer token acquisition and caching for upstream registries
|
||||||
|
pub struct DockerAuth {
|
||||||
|
tokens: RwLock<HashMap<String, CachedToken>>,
|
||||||
|
client: reqwest::Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DockerAuth {
|
||||||
|
pub fn new(timeout: u64) -> Self {
|
||||||
|
Self {
|
||||||
|
tokens: RwLock::new(HashMap::new()),
|
||||||
|
client: reqwest::Client::builder()
|
||||||
|
.timeout(Duration::from_secs(timeout))
|
||||||
|
.build()
|
||||||
|
.unwrap_or_default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a valid token for the given registry and repository scope
|
||||||
|
/// Returns cached token if still valid, otherwise fetches a new one
|
||||||
|
pub async fn get_token(
|
||||||
|
&self,
|
||||||
|
registry_url: &str,
|
||||||
|
name: &str,
|
||||||
|
www_authenticate: Option<&str>,
|
||||||
|
) -> Option<String> {
|
||||||
|
let cache_key = format!("{}:{}", registry_url, name);
|
||||||
|
|
||||||
|
// Check cache first
|
||||||
|
{
|
||||||
|
let tokens = self.tokens.read();
|
||||||
|
if let Some(cached) = tokens.get(&cache_key) {
|
||||||
|
if cached.expires_at > Instant::now() {
|
||||||
|
return Some(cached.token.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need to fetch a new token
|
||||||
|
let www_auth = www_authenticate?;
|
||||||
|
let token = self.fetch_token(www_auth, name).await?;
|
||||||
|
|
||||||
|
// Cache the token (default 5 minute expiry)
|
||||||
|
{
|
||||||
|
let mut tokens = self.tokens.write();
|
||||||
|
tokens.insert(
|
||||||
|
cache_key,
|
||||||
|
CachedToken {
|
||||||
|
token: token.clone(),
|
||||||
|
expires_at: Instant::now() + Duration::from_secs(300),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse Www-Authenticate header and fetch token from auth server
|
||||||
|
/// Format: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/alpine:pull"
|
||||||
|
async fn fetch_token(&self, www_authenticate: &str, name: &str) -> Option<String> {
|
||||||
|
let params = parse_www_authenticate(www_authenticate)?;
|
||||||
|
|
||||||
|
let realm = params.get("realm")?;
|
||||||
|
let service = params.get("service").map(|s| s.as_str()).unwrap_or("");
|
||||||
|
|
||||||
|
// Build token request URL
|
||||||
|
let scope = format!("repository:{}:pull", name);
|
||||||
|
let url = format!("{}?service={}&scope={}", realm, service, scope);
|
||||||
|
|
||||||
|
let response = self.client.get(&url).send().await.ok()?;
|
||||||
|
|
||||||
|
if !response.status().is_success() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let json: serde_json::Value = response.json().await.ok()?;
|
||||||
|
|
||||||
|
// Docker Hub returns "token", some registries return "access_token"
|
||||||
|
json.get("token")
|
||||||
|
.or_else(|| json.get("access_token"))
|
||||||
|
.and_then(|v| v.as_str())
|
||||||
|
.map(String::from)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Make an authenticated request to an upstream registry
|
||||||
|
pub async fn fetch_with_auth(
|
||||||
|
&self,
|
||||||
|
url: &str,
|
||||||
|
registry_url: &str,
|
||||||
|
name: &str,
|
||||||
|
) -> Result<reqwest::Response, ()> {
|
||||||
|
// First try without auth
|
||||||
|
let response = self.client.get(url).send().await.map_err(|_| ())?;
|
||||||
|
|
||||||
|
if response.status() == reqwest::StatusCode::UNAUTHORIZED {
|
||||||
|
// Extract Www-Authenticate header
|
||||||
|
let www_auth = response
|
||||||
|
.headers()
|
||||||
|
.get("www-authenticate")
|
||||||
|
.and_then(|v| v.to_str().ok())
|
||||||
|
.map(String::from);
|
||||||
|
|
||||||
|
// Get token and retry
|
||||||
|
if let Some(token) = self
|
||||||
|
.get_token(registry_url, name, www_auth.as_deref())
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
return self
|
||||||
|
.client
|
||||||
|
.get(url)
|
||||||
|
.header("Authorization", format!("Bearer {}", token))
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|_| ());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DockerAuth {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new(60)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse Www-Authenticate header into key-value pairs
|
||||||
|
/// Example: Bearer realm="https://auth.docker.io/token",service="registry.docker.io"
|
||||||
|
fn parse_www_authenticate(header: &str) -> Option<HashMap<String, String>> {
|
||||||
|
let header = header
|
||||||
|
.strip_prefix("Bearer ")
|
||||||
|
.or_else(|| header.strip_prefix("bearer "))?;
|
||||||
|
|
||||||
|
let mut params = HashMap::new();
|
||||||
|
|
||||||
|
for part in header.split(',') {
|
||||||
|
let part = part.trim();
|
||||||
|
if let Some((key, value)) = part.split_once('=') {
|
||||||
|
let value = value.trim_matches('"');
|
||||||
|
params.insert(key.to_string(), value.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_www_authenticate() {
|
||||||
|
let header = r#"Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/alpine:pull""#;
|
||||||
|
let params = parse_www_authenticate(header).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
params.get("realm"),
|
||||||
|
Some(&"https://auth.docker.io/token".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
params.get("service"),
|
||||||
|
Some(&"registry.docker.io".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_www_authenticate_lowercase() {
|
||||||
|
let header = r#"bearer realm="https://ghcr.io/token",service="ghcr.io""#;
|
||||||
|
let params = parse_www_authenticate(header).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
params.get("realm"),
|
||||||
|
Some(&"https://ghcr.io/token".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::activity_log::{ActionType, ActivityEntry};
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use axum::{
|
use axum::{
|
||||||
body::Bytes,
|
body::Bytes,
|
||||||
@@ -19,8 +20,27 @@ pub fn routes() -> Router<Arc<AppState>> {
|
|||||||
async fn download(State(state): State<Arc<AppState>>, Path(path): Path<String>) -> Response {
|
async fn download(State(state): State<Arc<AppState>>, Path(path): Path<String>) -> Response {
|
||||||
let key = format!("maven/{}", path);
|
let key = format!("maven/{}", path);
|
||||||
|
|
||||||
|
// Extract artifact name for logging (last 2-3 path components)
|
||||||
|
let artifact_name = path
|
||||||
|
.split('/')
|
||||||
|
.rev()
|
||||||
|
.take(3)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.into_iter()
|
||||||
|
.rev()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("/");
|
||||||
|
|
||||||
// Try local storage first
|
// Try local storage first
|
||||||
if let Ok(data) = state.storage.get(&key).await {
|
if let Ok(data) = state.storage.get(&key).await {
|
||||||
|
state.metrics.record_download("maven");
|
||||||
|
state.metrics.record_cache_hit();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::CacheHit,
|
||||||
|
artifact_name,
|
||||||
|
"maven",
|
||||||
|
"CACHE",
|
||||||
|
));
|
||||||
return with_content_type(&path, data).into_response();
|
return with_content_type(&path, data).into_response();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,6 +50,15 @@ async fn download(State(state): State<Arc<AppState>>, Path(path): Path<String>)
|
|||||||
|
|
||||||
match fetch_from_proxy(&url, state.config.maven.proxy_timeout).await {
|
match fetch_from_proxy(&url, state.config.maven.proxy_timeout).await {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
|
state.metrics.record_download("maven");
|
||||||
|
state.metrics.record_cache_miss();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::ProxyFetch,
|
||||||
|
artifact_name,
|
||||||
|
"maven",
|
||||||
|
"PROXY",
|
||||||
|
));
|
||||||
|
|
||||||
// Cache in local storage (fire and forget)
|
// Cache in local storage (fire and forget)
|
||||||
let storage = state.storage.clone();
|
let storage = state.storage.clone();
|
||||||
let key_clone = key.clone();
|
let key_clone = key.clone();
|
||||||
@@ -53,8 +82,29 @@ async fn upload(
|
|||||||
body: Bytes,
|
body: Bytes,
|
||||||
) -> StatusCode {
|
) -> StatusCode {
|
||||||
let key = format!("maven/{}", path);
|
let key = format!("maven/{}", path);
|
||||||
|
|
||||||
|
// Extract artifact name for logging
|
||||||
|
let artifact_name = path
|
||||||
|
.split('/')
|
||||||
|
.rev()
|
||||||
|
.take(3)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.into_iter()
|
||||||
|
.rev()
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join("/");
|
||||||
|
|
||||||
match state.storage.put(&key, &body).await {
|
match state.storage.put(&key, &body).await {
|
||||||
Ok(()) => StatusCode::CREATED,
|
Ok(()) => {
|
||||||
|
state.metrics.record_upload("maven");
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::Push,
|
||||||
|
artifact_name,
|
||||||
|
"maven",
|
||||||
|
"LOCAL",
|
||||||
|
));
|
||||||
|
StatusCode::CREATED
|
||||||
|
}
|
||||||
Err(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
Err(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
mod cargo_registry;
|
mod cargo_registry;
|
||||||
mod docker;
|
pub mod docker;
|
||||||
|
pub mod docker_auth;
|
||||||
mod maven;
|
mod maven;
|
||||||
mod npm;
|
mod npm;
|
||||||
mod pypi;
|
mod pypi;
|
||||||
|
mod raw;
|
||||||
|
|
||||||
pub use cargo_registry::routes as cargo_routes;
|
pub use cargo_registry::routes as cargo_routes;
|
||||||
pub use docker::routes as docker_routes;
|
pub use docker::routes as docker_routes;
|
||||||
|
pub use docker_auth::DockerAuth;
|
||||||
pub use maven::routes as maven_routes;
|
pub use maven::routes as maven_routes;
|
||||||
pub use npm::routes as npm_routes;
|
pub use npm::routes as npm_routes;
|
||||||
pub use pypi::routes as pypi_routes;
|
pub use pypi::routes as pypi_routes;
|
||||||
|
pub use raw::routes as raw_routes;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::activity_log::{ActionType, ActivityEntry};
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use axum::{
|
use axum::{
|
||||||
body::Bytes,
|
body::Bytes,
|
||||||
@@ -29,8 +30,25 @@ async fn handle_request(State(state): State<Arc<AppState>>, Path(path): Path<Str
|
|||||||
format!("npm/{}/metadata.json", path)
|
format!("npm/{}/metadata.json", path)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Extract package name for logging
|
||||||
|
let package_name = if is_tarball {
|
||||||
|
path.split("/-/").next().unwrap_or(&path).to_string()
|
||||||
|
} else {
|
||||||
|
path.clone()
|
||||||
|
};
|
||||||
|
|
||||||
// Try local storage first
|
// Try local storage first
|
||||||
if let Ok(data) = state.storage.get(&key).await {
|
if let Ok(data) = state.storage.get(&key).await {
|
||||||
|
if is_tarball {
|
||||||
|
state.metrics.record_download("npm");
|
||||||
|
state.metrics.record_cache_hit();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::CacheHit,
|
||||||
|
package_name,
|
||||||
|
"npm",
|
||||||
|
"CACHE",
|
||||||
|
));
|
||||||
|
}
|
||||||
return with_content_type(is_tarball, data).into_response();
|
return with_content_type(is_tarball, data).into_response();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,6 +63,17 @@ async fn handle_request(State(state): State<Arc<AppState>>, Path(path): Path<Str
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Ok(data) = fetch_from_proxy(&url, state.config.npm.proxy_timeout).await {
|
if let Ok(data) = fetch_from_proxy(&url, state.config.npm.proxy_timeout).await {
|
||||||
|
if is_tarball {
|
||||||
|
state.metrics.record_download("npm");
|
||||||
|
state.metrics.record_cache_miss();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::ProxyFetch,
|
||||||
|
package_name,
|
||||||
|
"npm",
|
||||||
|
"PROXY",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// Cache in local storage (fire and forget)
|
// Cache in local storage (fire and forget)
|
||||||
let storage = state.storage.clone();
|
let storage = state.storage.clone();
|
||||||
let key_clone = key.clone();
|
let key_clone = key.clone();
|
||||||
|
|||||||
@@ -1,35 +1,309 @@
|
|||||||
|
use crate::activity_log::{ActionType, ActivityEntry};
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::State,
|
extract::{Path, State},
|
||||||
http::StatusCode,
|
http::{header, StatusCode},
|
||||||
response::{Html, IntoResponse},
|
response::{Html, IntoResponse, Response},
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
pub fn routes() -> Router<Arc<AppState>> {
|
pub fn routes() -> Router<Arc<AppState>> {
|
||||||
Router::new().route("/simple/", get(list_packages))
|
Router::new()
|
||||||
|
.route("/simple/", get(list_packages))
|
||||||
|
.route("/simple/{name}/", get(package_versions))
|
||||||
|
.route("/simple/{name}/{filename}", get(download_file))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// List all packages (Simple API index)
|
||||||
async fn list_packages(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
async fn list_packages(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
||||||
let keys = state.storage.list("pypi/").await;
|
let keys = state.storage.list("pypi/").await;
|
||||||
let mut packages = std::collections::HashSet::new();
|
let mut packages = std::collections::HashSet::new();
|
||||||
|
|
||||||
for key in keys {
|
for key in keys {
|
||||||
if let Some(pkg) = key.strip_prefix("pypi/").and_then(|k| k.split('/').next()) {
|
if let Some(pkg) = key.strip_prefix("pypi/").and_then(|k| k.split('/').next()) {
|
||||||
|
if !pkg.is_empty() {
|
||||||
packages.insert(pkg.to_string());
|
packages.insert(pkg.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut html = String::from("<html><body><h1>Simple Index</h1>");
|
let mut html = String::from(
|
||||||
|
"<!DOCTYPE html>\n<html><head><title>Simple Index</title></head><body><h1>Simple Index</h1>\n",
|
||||||
|
);
|
||||||
let mut pkg_list: Vec<_> = packages.into_iter().collect();
|
let mut pkg_list: Vec<_> = packages.into_iter().collect();
|
||||||
pkg_list.sort();
|
pkg_list.sort();
|
||||||
|
|
||||||
for pkg in pkg_list {
|
for pkg in pkg_list {
|
||||||
html.push_str(&format!("<a href=\"/simple/{}/\">{}</a><br>", pkg, pkg));
|
html.push_str(&format!("<a href=\"/simple/{}/\">{}</a><br>\n", pkg, pkg));
|
||||||
}
|
}
|
||||||
html.push_str("</body></html>");
|
html.push_str("</body></html>");
|
||||||
|
|
||||||
(StatusCode::OK, Html(html))
|
(StatusCode::OK, Html(html))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// List versions/files for a specific package
|
||||||
|
async fn package_versions(
|
||||||
|
State(state): State<Arc<AppState>>,
|
||||||
|
Path(name): Path<String>,
|
||||||
|
) -> Response {
|
||||||
|
// Normalize package name (PEP 503)
|
||||||
|
let normalized = normalize_name(&name);
|
||||||
|
|
||||||
|
// Try to get local files first
|
||||||
|
let prefix = format!("pypi/{}/", normalized);
|
||||||
|
let keys = state.storage.list(&prefix).await;
|
||||||
|
|
||||||
|
if !keys.is_empty() {
|
||||||
|
// We have local files
|
||||||
|
let mut html = format!(
|
||||||
|
"<!DOCTYPE html>\n<html><head><title>Links for {}</title></head><body><h1>Links for {}</h1>\n",
|
||||||
|
name, name
|
||||||
|
);
|
||||||
|
|
||||||
|
for key in &keys {
|
||||||
|
if let Some(filename) = key.strip_prefix(&prefix) {
|
||||||
|
if !filename.is_empty() {
|
||||||
|
html.push_str(&format!(
|
||||||
|
"<a href=\"/simple/{}/{}\">{}</a><br>\n",
|
||||||
|
normalized, filename, filename
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html.push_str("</body></html>");
|
||||||
|
|
||||||
|
return (StatusCode::OK, Html(html)).into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try proxy if configured
|
||||||
|
if let Some(proxy_url) = &state.config.pypi.proxy {
|
||||||
|
let url = format!("{}/{}/", proxy_url.trim_end_matches('/'), normalized);
|
||||||
|
|
||||||
|
if let Ok(html) = fetch_package_page(&url, state.config.pypi.proxy_timeout).await {
|
||||||
|
// Rewrite URLs in the HTML to point to our registry
|
||||||
|
let rewritten = rewrite_pypi_links(&html, &normalized);
|
||||||
|
return (StatusCode::OK, Html(rewritten)).into_response();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusCode::NOT_FOUND.into_response()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Download a specific file
|
||||||
|
async fn download_file(
|
||||||
|
State(state): State<Arc<AppState>>,
|
||||||
|
Path((name, filename)): Path<(String, String)>,
|
||||||
|
) -> Response {
|
||||||
|
let normalized = normalize_name(&name);
|
||||||
|
let key = format!("pypi/{}/{}", normalized, filename);
|
||||||
|
|
||||||
|
// Try local storage first
|
||||||
|
if let Ok(data) = state.storage.get(&key).await {
|
||||||
|
state.metrics.record_download("pypi");
|
||||||
|
state.metrics.record_cache_hit();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::CacheHit,
|
||||||
|
format!("{}/{}", name, filename),
|
||||||
|
"pypi",
|
||||||
|
"CACHE",
|
||||||
|
));
|
||||||
|
|
||||||
|
let content_type = if filename.ends_with(".whl") {
|
||||||
|
"application/zip"
|
||||||
|
} else if filename.ends_with(".tar.gz") || filename.ends_with(".tgz") {
|
||||||
|
"application/gzip"
|
||||||
|
} else {
|
||||||
|
"application/octet-stream"
|
||||||
|
};
|
||||||
|
|
||||||
|
return (StatusCode::OK, [(header::CONTENT_TYPE, content_type)], data).into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try proxy if configured
|
||||||
|
if let Some(proxy_url) = &state.config.pypi.proxy {
|
||||||
|
// First, fetch the package page to find the actual download URL
|
||||||
|
let page_url = format!("{}/{}/", proxy_url.trim_end_matches('/'), normalized);
|
||||||
|
|
||||||
|
if let Ok(html) = fetch_package_page(&page_url, state.config.pypi.proxy_timeout).await {
|
||||||
|
// Find the URL for this specific file
|
||||||
|
if let Some(file_url) = find_file_url(&html, &filename) {
|
||||||
|
if let Ok(data) = fetch_file(&file_url, state.config.pypi.proxy_timeout).await {
|
||||||
|
state.metrics.record_download("pypi");
|
||||||
|
state.metrics.record_cache_miss();
|
||||||
|
state.activity.push(ActivityEntry::new(
|
||||||
|
ActionType::ProxyFetch,
|
||||||
|
format!("{}/{}", name, filename),
|
||||||
|
"pypi",
|
||||||
|
"PROXY",
|
||||||
|
));
|
||||||
|
|
||||||
|
// Cache in local storage
|
||||||
|
let storage = state.storage.clone();
|
||||||
|
let key_clone = key.clone();
|
||||||
|
let data_clone = data.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let _ = storage.put(&key_clone, &data_clone).await;
|
||||||
|
});
|
||||||
|
|
||||||
|
let content_type = if filename.ends_with(".whl") {
|
||||||
|
"application/zip"
|
||||||
|
} else if filename.ends_with(".tar.gz") || filename.ends_with(".tgz") {
|
||||||
|
"application/gzip"
|
||||||
|
} else {
|
||||||
|
"application/octet-stream"
|
||||||
|
};
|
||||||
|
|
||||||
|
return (StatusCode::OK, [(header::CONTENT_TYPE, content_type)], data)
|
||||||
|
.into_response();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StatusCode::NOT_FOUND.into_response()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Normalize package name according to PEP 503
|
||||||
|
fn normalize_name(name: &str) -> String {
|
||||||
|
name.to_lowercase().replace(['-', '_', '.'], "-")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch package page from upstream
|
||||||
|
async fn fetch_package_page(url: &str, timeout_secs: u64) -> Result<String, ()> {
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.timeout(Duration::from_secs(timeout_secs))
|
||||||
|
.build()
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
|
let response = client
|
||||||
|
.get(url)
|
||||||
|
.header("Accept", "text/html")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
|
if !response.status().is_success() {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
response.text().await.map_err(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fetch file from upstream
|
||||||
|
async fn fetch_file(url: &str, timeout_secs: u64) -> Result<Vec<u8>, ()> {
|
||||||
|
let client = reqwest::Client::builder()
|
||||||
|
.timeout(Duration::from_secs(timeout_secs))
|
||||||
|
.build()
|
||||||
|
.map_err(|_| ())?;
|
||||||
|
|
||||||
|
let response = client.get(url).send().await.map_err(|_| ())?;
|
||||||
|
|
||||||
|
if !response.status().is_success() {
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
response.bytes().await.map(|b| b.to_vec()).map_err(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rewrite PyPI links to point to our registry
|
||||||
|
fn rewrite_pypi_links(html: &str, package_name: &str) -> String {
|
||||||
|
// Simple regex-free approach: find href="..." and rewrite
|
||||||
|
let mut result = String::with_capacity(html.len());
|
||||||
|
let mut remaining = html;
|
||||||
|
|
||||||
|
while let Some(href_start) = remaining.find("href=\"") {
|
||||||
|
result.push_str(&remaining[..href_start + 6]);
|
||||||
|
remaining = &remaining[href_start + 6..];
|
||||||
|
|
||||||
|
if let Some(href_end) = remaining.find('"') {
|
||||||
|
let url = &remaining[..href_end];
|
||||||
|
|
||||||
|
// Extract filename from URL
|
||||||
|
if let Some(filename) = extract_filename(url) {
|
||||||
|
// Rewrite to our local URL
|
||||||
|
result.push_str(&format!("/simple/{}/{}", package_name, filename));
|
||||||
|
} else {
|
||||||
|
result.push_str(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
remaining = &remaining[href_end..];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.push_str(remaining);
|
||||||
|
|
||||||
|
// Remove data-core-metadata and data-dist-info-metadata attributes
|
||||||
|
// as we don't serve .metadata files (PEP 658)
|
||||||
|
let result = remove_attribute(&result, "data-core-metadata");
|
||||||
|
remove_attribute(&result, "data-dist-info-metadata")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Remove an HTML attribute from all tags
|
||||||
|
fn remove_attribute(html: &str, attr_name: &str) -> String {
|
||||||
|
let mut result = String::with_capacity(html.len());
|
||||||
|
let mut remaining = html;
|
||||||
|
let pattern = format!(" {}=\"", attr_name);
|
||||||
|
|
||||||
|
while let Some(attr_start) = remaining.find(&pattern) {
|
||||||
|
result.push_str(&remaining[..attr_start]);
|
||||||
|
remaining = &remaining[attr_start + pattern.len()..];
|
||||||
|
|
||||||
|
// Skip the attribute value
|
||||||
|
if let Some(attr_end) = remaining.find('"') {
|
||||||
|
remaining = &remaining[attr_end + 1..];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.push_str(remaining);
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extract filename from PyPI download URL
|
||||||
|
fn extract_filename(url: &str) -> Option<&str> {
|
||||||
|
// PyPI URLs look like:
|
||||||
|
// https://files.pythonhosted.org/packages/.../package-1.0.0.tar.gz#sha256=...
|
||||||
|
// or just the filename directly
|
||||||
|
|
||||||
|
// Remove hash fragment
|
||||||
|
let url = url.split('#').next()?;
|
||||||
|
|
||||||
|
// Get the last path component
|
||||||
|
let filename = url.rsplit('/').next()?;
|
||||||
|
|
||||||
|
// Must be a valid package file
|
||||||
|
if filename.ends_with(".tar.gz")
|
||||||
|
|| filename.ends_with(".tgz")
|
||||||
|
|| filename.ends_with(".whl")
|
||||||
|
|| filename.ends_with(".zip")
|
||||||
|
|| filename.ends_with(".egg")
|
||||||
|
{
|
||||||
|
Some(filename)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Find the download URL for a specific file in the HTML
|
||||||
|
fn find_file_url(html: &str, target_filename: &str) -> Option<String> {
|
||||||
|
let mut remaining = html;
|
||||||
|
|
||||||
|
while let Some(href_start) = remaining.find("href=\"") {
|
||||||
|
remaining = &remaining[href_start + 6..];
|
||||||
|
|
||||||
|
if let Some(href_end) = remaining.find('"') {
|
||||||
|
let url = &remaining[..href_end];
|
||||||
|
|
||||||
|
if let Some(filename) = extract_filename(url) {
|
||||||
|
if filename == target_filename {
|
||||||
|
// Remove hash fragment for actual download
|
||||||
|
return Some(url.split('#').next().unwrap_or(url).to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
remaining = &remaining[href_end..];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|||||||
133
nora-registry/src/registry/raw.rs
Normal file
133
nora-registry/src/registry/raw.rs
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
use crate::activity_log::{ActionType, ActivityEntry};
|
||||||
|
use crate::AppState;
|
||||||
|
use axum::{
|
||||||
|
body::Bytes,
|
||||||
|
extract::{Path, State},
|
||||||
|
http::{header, StatusCode},
|
||||||
|
response::{IntoResponse, Response},
|
||||||
|
routing::get,
|
||||||
|
Router,
|
||||||
|
};
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub fn routes() -> Router<Arc<AppState>> {
|
||||||
|
Router::new().route(
|
||||||
|
"/raw/{*path}",
|
||||||
|
get(download)
|
||||||
|
.put(upload)
|
||||||
|
.delete(delete_file)
|
||||||
|
.head(check_exists),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn download(State(state): State<Arc<AppState>>, Path(path): Path<String>) -> Response {
|
||||||
|
if !state.config.raw.enabled {
|
||||||
|
return StatusCode::NOT_FOUND.into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = format!("raw/{}", path);
|
||||||
|
match state.storage.get(&key).await {
|
||||||
|
Ok(data) => {
|
||||||
|
state.metrics.record_download("raw");
|
||||||
|
state
|
||||||
|
.activity
|
||||||
|
.push(ActivityEntry::new(ActionType::Pull, path, "raw", "LOCAL"));
|
||||||
|
|
||||||
|
// Guess content type from extension
|
||||||
|
let content_type = guess_content_type(&key);
|
||||||
|
(StatusCode::OK, [(header::CONTENT_TYPE, content_type)], data).into_response()
|
||||||
|
}
|
||||||
|
Err(_) => StatusCode::NOT_FOUND.into_response(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn upload(
|
||||||
|
State(state): State<Arc<AppState>>,
|
||||||
|
Path(path): Path<String>,
|
||||||
|
body: Bytes,
|
||||||
|
) -> Response {
|
||||||
|
if !state.config.raw.enabled {
|
||||||
|
return StatusCode::NOT_FOUND.into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check file size limit
|
||||||
|
if body.len() as u64 > state.config.raw.max_file_size {
|
||||||
|
return (
|
||||||
|
StatusCode::PAYLOAD_TOO_LARGE,
|
||||||
|
format!(
|
||||||
|
"File too large. Max size: {} bytes",
|
||||||
|
state.config.raw.max_file_size
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = format!("raw/{}", path);
|
||||||
|
match state.storage.put(&key, &body).await {
|
||||||
|
Ok(()) => {
|
||||||
|
state.metrics.record_upload("raw");
|
||||||
|
state
|
||||||
|
.activity
|
||||||
|
.push(ActivityEntry::new(ActionType::Push, path, "raw", "LOCAL"));
|
||||||
|
StatusCode::CREATED.into_response()
|
||||||
|
}
|
||||||
|
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn delete_file(State(state): State<Arc<AppState>>, Path(path): Path<String>) -> Response {
|
||||||
|
if !state.config.raw.enabled {
|
||||||
|
return StatusCode::NOT_FOUND.into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = format!("raw/{}", path);
|
||||||
|
match state.storage.delete(&key).await {
|
||||||
|
Ok(()) => StatusCode::NO_CONTENT.into_response(),
|
||||||
|
Err(crate::storage::StorageError::NotFound) => StatusCode::NOT_FOUND.into_response(),
|
||||||
|
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn check_exists(State(state): State<Arc<AppState>>, Path(path): Path<String>) -> Response {
|
||||||
|
if !state.config.raw.enabled {
|
||||||
|
return StatusCode::NOT_FOUND.into_response();
|
||||||
|
}
|
||||||
|
|
||||||
|
let key = format!("raw/{}", path);
|
||||||
|
match state.storage.stat(&key).await {
|
||||||
|
Some(meta) => (
|
||||||
|
StatusCode::OK,
|
||||||
|
[
|
||||||
|
(header::CONTENT_LENGTH, meta.size.to_string()),
|
||||||
|
(header::CONTENT_TYPE, guess_content_type(&key).to_string()),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.into_response(),
|
||||||
|
None => StatusCode::NOT_FOUND.into_response(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn guess_content_type(path: &str) -> &'static str {
|
||||||
|
let ext = path.rsplit('.').next().unwrap_or("");
|
||||||
|
match ext.to_lowercase().as_str() {
|
||||||
|
"json" => "application/json",
|
||||||
|
"xml" => "application/xml",
|
||||||
|
"html" | "htm" => "text/html",
|
||||||
|
"css" => "text/css",
|
||||||
|
"js" => "application/javascript",
|
||||||
|
"txt" => "text/plain",
|
||||||
|
"md" => "text/markdown",
|
||||||
|
"yaml" | "yml" => "application/x-yaml",
|
||||||
|
"toml" => "application/toml",
|
||||||
|
"tar" => "application/x-tar",
|
||||||
|
"gz" | "gzip" => "application/gzip",
|
||||||
|
"zip" => "application/zip",
|
||||||
|
"png" => "image/png",
|
||||||
|
"jpg" | "jpeg" => "image/jpeg",
|
||||||
|
"gif" => "image/gif",
|
||||||
|
"svg" => "image/svg+xml",
|
||||||
|
"pdf" => "application/pdf",
|
||||||
|
"wasm" => "application/wasm",
|
||||||
|
_ => "application/octet-stream",
|
||||||
|
}
|
||||||
|
}
|
||||||
127
nora-registry/src/secrets/env.rs
Normal file
127
nora-registry/src/secrets/env.rs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
//! Environment variables secrets provider
|
||||||
|
//!
|
||||||
|
//! Reads secrets from environment variables. This is the default provider
|
||||||
|
//! following 12-Factor App principles.
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use super::{SecretsError, SecretsProvider};
|
||||||
|
use crate::secrets::protected::ProtectedString;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
/// Environment variables secrets provider
|
||||||
|
///
|
||||||
|
/// Reads secrets from environment variables.
|
||||||
|
/// Optionally clears variables after reading for extra security.
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct EnvProvider {
|
||||||
|
/// Clear environment variables after reading
|
||||||
|
clear_after_read: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EnvProvider {
|
||||||
|
/// Create a new environment provider
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
clear_after_read: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a provider that clears env vars after reading
|
||||||
|
///
|
||||||
|
/// This prevents secrets from being visible in `/proc/<pid>/environ`
|
||||||
|
pub fn with_clear_after_read(mut self) -> Self {
|
||||||
|
self.clear_after_read = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for EnvProvider {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl SecretsProvider for EnvProvider {
|
||||||
|
async fn get_secret(&self, key: &str) -> Result<ProtectedString, SecretsError> {
|
||||||
|
let value = env::var(key).map_err(|_| SecretsError::NotFound(key.to_string()))?;
|
||||||
|
|
||||||
|
if self.clear_after_read {
|
||||||
|
env::remove_var(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(ProtectedString::new(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_secret_optional(&self, key: &str) -> Option<ProtectedString> {
|
||||||
|
env::var(key).ok().map(|v| {
|
||||||
|
if self.clear_after_read {
|
||||||
|
env::remove_var(key);
|
||||||
|
}
|
||||||
|
ProtectedString::new(v)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn provider_name(&self) -> &'static str {
|
||||||
|
"env"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_secret_exists() {
|
||||||
|
env::set_var("TEST_SECRET_123", "secret-value");
|
||||||
|
let provider = EnvProvider::new();
|
||||||
|
let secret = provider.get_secret("TEST_SECRET_123").await.unwrap();
|
||||||
|
assert_eq!(secret.expose(), "secret-value");
|
||||||
|
env::remove_var("TEST_SECRET_123");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_secret_not_found() {
|
||||||
|
let provider = EnvProvider::new();
|
||||||
|
let result = provider.get_secret("NONEXISTENT_VAR_XYZ").await;
|
||||||
|
assert!(matches!(result, Err(SecretsError::NotFound(_))));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_secret_optional_exists() {
|
||||||
|
env::set_var("TEST_OPTIONAL_123", "optional-value");
|
||||||
|
let provider = EnvProvider::new();
|
||||||
|
let secret = provider.get_secret_optional("TEST_OPTIONAL_123").await;
|
||||||
|
assert!(secret.is_some());
|
||||||
|
assert_eq!(secret.unwrap().expose(), "optional-value");
|
||||||
|
env::remove_var("TEST_OPTIONAL_123");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_get_secret_optional_not_found() {
|
||||||
|
let provider = EnvProvider::new();
|
||||||
|
let secret = provider
|
||||||
|
.get_secret_optional("NONEXISTENT_OPTIONAL_XYZ")
|
||||||
|
.await;
|
||||||
|
assert!(secret.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_clear_after_read() {
|
||||||
|
env::set_var("TEST_CLEAR_123", "to-be-cleared");
|
||||||
|
let provider = EnvProvider::new().with_clear_after_read();
|
||||||
|
|
||||||
|
let secret = provider.get_secret("TEST_CLEAR_123").await.unwrap();
|
||||||
|
assert_eq!(secret.expose(), "to-be-cleared");
|
||||||
|
|
||||||
|
// Variable should be cleared
|
||||||
|
assert!(env::var("TEST_CLEAR_123").is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_provider_name() {
|
||||||
|
let provider = EnvProvider::new();
|
||||||
|
assert_eq!(provider.provider_name(), "env");
|
||||||
|
}
|
||||||
|
}
|
||||||
166
nora-registry/src/secrets/mod.rs
Normal file
166
nora-registry/src/secrets/mod.rs
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
#![allow(dead_code)] // Foundational code for future S3/Vault integration
|
||||||
|
|
||||||
|
//! Secrets management for NORA
|
||||||
|
//!
|
||||||
|
//! Provides a trait-based architecture for secrets providers:
|
||||||
|
//! - `env` - Environment variables (default, 12-Factor App)
|
||||||
|
//! - `aws-secrets` - AWS Secrets Manager (v0.4.0+)
|
||||||
|
//! - `vault` - HashiCorp Vault (v0.5.0+)
|
||||||
|
//! - `k8s` - Kubernetes Secrets (v0.4.0+)
|
||||||
|
//!
|
||||||
|
//! # Example
|
||||||
|
//!
|
||||||
|
//! ```rust,ignore
|
||||||
|
//! use nora::secrets::{create_secrets_provider, SecretsConfig};
|
||||||
|
//!
|
||||||
|
//! let config = SecretsConfig::default(); // Uses ENV provider
|
||||||
|
//! let provider = create_secrets_provider(&config)?;
|
||||||
|
//!
|
||||||
|
//! let api_key = provider.get_secret("API_KEY").await?;
|
||||||
|
//! println!("Got secret (redacted): {:?}", api_key);
|
||||||
|
//! ```
|
||||||
|
|
||||||
|
mod env;
|
||||||
|
pub mod protected;
|
||||||
|
|
||||||
|
pub use env::EnvProvider;
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
pub use protected::{ProtectedString, S3Credentials};
|
||||||
|
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
/// Secrets provider error
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum SecretsError {
|
||||||
|
#[error("Secret not found: {0}")]
|
||||||
|
NotFound(String),
|
||||||
|
|
||||||
|
#[error("Provider error: {0}")]
|
||||||
|
Provider(String),
|
||||||
|
|
||||||
|
#[error("Configuration error: {0}")]
|
||||||
|
Config(String),
|
||||||
|
|
||||||
|
#[error("Unsupported provider: {0}")]
|
||||||
|
UnsupportedProvider(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Secrets provider trait
|
||||||
|
///
|
||||||
|
/// Implement this trait to add new secrets backends.
|
||||||
|
#[async_trait]
|
||||||
|
pub trait SecretsProvider: Send + Sync {
|
||||||
|
/// Get a secret by key (required)
|
||||||
|
async fn get_secret(&self, key: &str) -> Result<ProtectedString, SecretsError>;
|
||||||
|
|
||||||
|
/// Get a secret by key (optional, returns None if not found)
|
||||||
|
async fn get_secret_optional(&self, key: &str) -> Option<ProtectedString> {
|
||||||
|
self.get_secret(key).await.ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get provider name for logging
|
||||||
|
fn provider_name(&self) -> &'static str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Secrets configuration
|
||||||
|
///
|
||||||
|
/// # Example config.toml
|
||||||
|
///
|
||||||
|
/// ```toml
|
||||||
|
/// [secrets]
|
||||||
|
/// provider = "env"
|
||||||
|
/// clear_env = false
|
||||||
|
/// ```
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct SecretsConfig {
|
||||||
|
/// Provider type: "env", "aws-secrets", "vault", "k8s"
|
||||||
|
#[serde(default = "default_provider")]
|
||||||
|
pub provider: String,
|
||||||
|
|
||||||
|
/// Clear environment variables after reading (for env provider)
|
||||||
|
#[serde(default)]
|
||||||
|
pub clear_env: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_provider() -> String {
|
||||||
|
"env".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for SecretsConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
provider: default_provider(),
|
||||||
|
clear_env: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a secrets provider based on configuration
|
||||||
|
///
|
||||||
|
/// Currently supports:
|
||||||
|
/// - `env` - Environment variables (default)
|
||||||
|
///
|
||||||
|
/// Future versions will add:
|
||||||
|
/// - `aws-secrets` - AWS Secrets Manager
|
||||||
|
/// - `vault` - HashiCorp Vault
|
||||||
|
/// - `k8s` - Kubernetes Secrets
|
||||||
|
pub fn create_secrets_provider(
|
||||||
|
config: &SecretsConfig,
|
||||||
|
) -> Result<Box<dyn SecretsProvider>, SecretsError> {
|
||||||
|
match config.provider.as_str() {
|
||||||
|
"env" => {
|
||||||
|
let mut provider = EnvProvider::new();
|
||||||
|
if config.clear_env {
|
||||||
|
provider = provider.with_clear_after_read();
|
||||||
|
}
|
||||||
|
Ok(Box::new(provider))
|
||||||
|
}
|
||||||
|
// Future providers:
|
||||||
|
// "aws-secrets" => { ... }
|
||||||
|
// "vault" => { ... }
|
||||||
|
// "k8s" => { ... }
|
||||||
|
other => Err(SecretsError::UnsupportedProvider(other.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_default_config() {
|
||||||
|
let config = SecretsConfig::default();
|
||||||
|
assert_eq!(config.provider, "env");
|
||||||
|
assert!(!config.clear_env);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_create_env_provider() {
|
||||||
|
let config = SecretsConfig::default();
|
||||||
|
let provider = create_secrets_provider(&config).unwrap();
|
||||||
|
assert_eq!(provider.provider_name(), "env");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_create_unsupported_provider() {
|
||||||
|
let config = SecretsConfig {
|
||||||
|
provider: "unknown".to_string(),
|
||||||
|
clear_env: false,
|
||||||
|
};
|
||||||
|
let result = create_secrets_provider(&config);
|
||||||
|
assert!(matches!(result, Err(SecretsError::UnsupportedProvider(_))));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_config_from_toml() {
|
||||||
|
let toml = r#"
|
||||||
|
provider = "env"
|
||||||
|
clear_env = true
|
||||||
|
"#;
|
||||||
|
let config: SecretsConfig = toml::from_str(toml).unwrap();
|
||||||
|
assert_eq!(config.provider, "env");
|
||||||
|
assert!(config.clear_env);
|
||||||
|
}
|
||||||
|
}
|
||||||
152
nora-registry/src/secrets/protected.rs
Normal file
152
nora-registry/src/secrets/protected.rs
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
//! Protected secret types with memory safety
|
||||||
|
//!
|
||||||
|
//! Secrets are automatically zeroed on drop and redacted in Debug output.
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
use zeroize::{Zeroize, Zeroizing};
|
||||||
|
|
||||||
|
/// A protected secret string that is zeroed on drop
|
||||||
|
///
|
||||||
|
/// - Implements Zeroize: memory is overwritten with zeros when dropped
|
||||||
|
/// - Debug shows `***REDACTED***` instead of actual value
|
||||||
|
/// - Clone creates a new protected copy
|
||||||
|
#[derive(Clone, Zeroize)]
|
||||||
|
#[zeroize(drop)]
|
||||||
|
pub struct ProtectedString {
|
||||||
|
inner: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProtectedString {
|
||||||
|
/// Create a new protected string
|
||||||
|
pub fn new(value: String) -> Self {
|
||||||
|
Self { inner: value }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the secret value (use sparingly!)
|
||||||
|
pub fn expose(&self) -> &str {
|
||||||
|
&self.inner
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Consume and return the inner value
|
||||||
|
pub fn into_inner(self) -> Zeroizing<String> {
|
||||||
|
Zeroizing::new(self.inner.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if the secret is empty
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.inner.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for ProtectedString {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.debug_struct("ProtectedString")
|
||||||
|
.field("value", &"***REDACTED***")
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ProtectedString {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "***REDACTED***")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<String> for ProtectedString {
|
||||||
|
fn from(value: String) -> Self {
|
||||||
|
Self::new(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&str> for ProtectedString {
|
||||||
|
fn from(value: &str) -> Self {
|
||||||
|
Self::new(value.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// S3 credentials with protected secrets
|
||||||
|
#[derive(Clone, Zeroize)]
|
||||||
|
#[zeroize(drop)]
|
||||||
|
pub struct S3Credentials {
|
||||||
|
pub access_key_id: String,
|
||||||
|
#[zeroize(skip)] // access_key_id is not sensitive
|
||||||
|
pub secret_access_key: ProtectedString,
|
||||||
|
pub region: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl S3Credentials {
|
||||||
|
pub fn new(access_key_id: String, secret_access_key: String) -> Self {
|
||||||
|
Self {
|
||||||
|
access_key_id,
|
||||||
|
secret_access_key: ProtectedString::new(secret_access_key),
|
||||||
|
region: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_region(mut self, region: String) -> Self {
|
||||||
|
self.region = Some(region);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for S3Credentials {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.debug_struct("S3Credentials")
|
||||||
|
.field("access_key_id", &self.access_key_id)
|
||||||
|
.field("secret_access_key", &"***REDACTED***")
|
||||||
|
.field("region", &self.region)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_protected_string_redacted_debug() {
|
||||||
|
let secret = ProtectedString::new("super-secret-value".to_string());
|
||||||
|
let debug_output = format!("{:?}", secret);
|
||||||
|
assert!(debug_output.contains("REDACTED"));
|
||||||
|
assert!(!debug_output.contains("super-secret-value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_protected_string_redacted_display() {
|
||||||
|
let secret = ProtectedString::new("super-secret-value".to_string());
|
||||||
|
let display_output = format!("{}", secret);
|
||||||
|
assert_eq!(display_output, "***REDACTED***");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_protected_string_expose() {
|
||||||
|
let secret = ProtectedString::new("my-secret".to_string());
|
||||||
|
assert_eq!(secret.expose(), "my-secret");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_s3_credentials_redacted_debug() {
|
||||||
|
let creds = S3Credentials::new(
|
||||||
|
"AKIAIOSFODNN7EXAMPLE".to_string(),
|
||||||
|
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY".to_string(),
|
||||||
|
);
|
||||||
|
let debug_output = format!("{:?}", creds);
|
||||||
|
assert!(debug_output.contains("AKIAIOSFODNN7EXAMPLE"));
|
||||||
|
assert!(!debug_output.contains("wJalrXUtnFEMI"));
|
||||||
|
assert!(debug_output.contains("REDACTED"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_protected_string_from_str() {
|
||||||
|
let secret: ProtectedString = "test".into();
|
||||||
|
assert_eq!(secret.expose(), "test");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_protected_string_is_empty() {
|
||||||
|
let empty = ProtectedString::new(String::new());
|
||||||
|
let non_empty = ProtectedString::new("secret".to_string());
|
||||||
|
assert!(empty.is_empty());
|
||||||
|
assert!(!non_empty.is_empty());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -85,6 +85,20 @@ impl StorageBackend for LocalStorage {
|
|||||||
Ok(Bytes::from(buffer))
|
Ok(Bytes::from(buffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn delete(&self, key: &str) -> Result<()> {
|
||||||
|
let path = self.key_to_path(key);
|
||||||
|
|
||||||
|
if !path.exists() {
|
||||||
|
return Err(StorageError::NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::remove_file(&path)
|
||||||
|
.await
|
||||||
|
.map_err(|e| StorageError::Io(e.to_string()))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn list(&self, prefix: &str) -> Vec<String> {
|
async fn list(&self, prefix: &str) -> Vec<String> {
|
||||||
let base = self.base_path.clone();
|
let base = self.base_path.clone();
|
||||||
let prefix = prefix.to_string();
|
let prefix = prefix.to_string();
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ pub type Result<T> = std::result::Result<T, StorageError>;
|
|||||||
pub trait StorageBackend: Send + Sync {
|
pub trait StorageBackend: Send + Sync {
|
||||||
async fn put(&self, key: &str, data: &[u8]) -> Result<()>;
|
async fn put(&self, key: &str, data: &[u8]) -> Result<()>;
|
||||||
async fn get(&self, key: &str) -> Result<Bytes>;
|
async fn get(&self, key: &str) -> Result<Bytes>;
|
||||||
|
async fn delete(&self, key: &str) -> Result<()>;
|
||||||
async fn list(&self, prefix: &str) -> Vec<String>;
|
async fn list(&self, prefix: &str) -> Vec<String>;
|
||||||
async fn stat(&self, key: &str) -> Option<FileMeta>;
|
async fn stat(&self, key: &str) -> Option<FileMeta>;
|
||||||
async fn health_check(&self) -> bool;
|
async fn health_check(&self) -> bool;
|
||||||
@@ -74,13 +75,16 @@ impl Storage {
|
|||||||
self.inner.get(key).await
|
self.inner.get(key).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete(&self, key: &str) -> Result<()> {
|
||||||
|
validate_storage_key(key)?;
|
||||||
|
self.inner.delete(key).await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn list(&self, prefix: &str) -> Vec<String> {
|
pub async fn list(&self, prefix: &str) -> Vec<String> {
|
||||||
// Empty prefix is valid for listing all
|
// Empty prefix is valid for listing all
|
||||||
if !prefix.is_empty() {
|
if !prefix.is_empty() && validate_storage_key(prefix).is_err() {
|
||||||
if let Err(_) = validate_storage_key(prefix) {
|
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
self.inner.list(prefix).await
|
self.inner.list(prefix).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,27 @@ impl StorageBackend for S3Storage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn delete(&self, key: &str) -> Result<()> {
|
||||||
|
let url = format!("{}/{}/{}", self.s3_url, self.bucket, key);
|
||||||
|
let response = self
|
||||||
|
.client
|
||||||
|
.delete(&url)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.map_err(|e| StorageError::Network(e.to_string()))?;
|
||||||
|
|
||||||
|
if response.status().is_success() || response.status().as_u16() == 204 {
|
||||||
|
Ok(())
|
||||||
|
} else if response.status().as_u16() == 404 {
|
||||||
|
Err(StorageError::NotFound)
|
||||||
|
} else {
|
||||||
|
Err(StorageError::Network(format!(
|
||||||
|
"DELETE failed: {}",
|
||||||
|
response.status()
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn list(&self, prefix: &str) -> Vec<String> {
|
async fn list(&self, prefix: &str) -> Vec<String> {
|
||||||
let url = format!("{}/{}", self.s3_url, self.bucket);
|
let url = format!("{}/{}", self.s3_url, self.bucket);
|
||||||
match self.client.get(&url).send().await {
|
match self.client.get(&url).send().await {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use super::components::{format_size, format_timestamp, html_escape};
|
use super::components::{format_size, format_timestamp, html_escape};
|
||||||
use super::templates::encode_uri_component;
|
use super::templates::encode_uri_component;
|
||||||
|
use crate::activity_log::ActivityEntry;
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use crate::Storage;
|
use crate::Storage;
|
||||||
use axum::{
|
use axum::{
|
||||||
@@ -8,6 +9,7 @@ use axum::{
|
|||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@@ -32,6 +34,12 @@ pub struct TagInfo {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
pub created: String,
|
pub created: String,
|
||||||
|
pub downloads: u64,
|
||||||
|
pub last_pulled: Option<String>,
|
||||||
|
pub os: String,
|
||||||
|
pub arch: String,
|
||||||
|
pub layers_count: usize,
|
||||||
|
pub pull_command: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
@@ -67,6 +75,40 @@ pub struct SearchQuery {
|
|||||||
pub q: Option<String>,
|
pub q: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct DashboardResponse {
|
||||||
|
pub global_stats: GlobalStats,
|
||||||
|
pub registry_stats: Vec<RegistryCardStats>,
|
||||||
|
pub mount_points: Vec<MountPoint>,
|
||||||
|
pub activity: Vec<ActivityEntry>,
|
||||||
|
pub uptime_seconds: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct GlobalStats {
|
||||||
|
pub downloads: u64,
|
||||||
|
pub uploads: u64,
|
||||||
|
pub artifacts: u64,
|
||||||
|
pub cache_hit_percent: f64,
|
||||||
|
pub storage_bytes: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct RegistryCardStats {
|
||||||
|
pub name: String,
|
||||||
|
pub artifact_count: usize,
|
||||||
|
pub downloads: u64,
|
||||||
|
pub uploads: u64,
|
||||||
|
pub size_bytes: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct MountPoint {
|
||||||
|
pub registry: String,
|
||||||
|
pub mount_path: String,
|
||||||
|
pub proxy_upstream: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
// ============ API Handlers ============
|
// ============ API Handlers ============
|
||||||
|
|
||||||
pub async fn api_stats(State(state): State<Arc<AppState>>) -> Json<RegistryStats> {
|
pub async fn api_stats(State(state): State<Arc<AppState>>) -> Json<RegistryStats> {
|
||||||
@@ -74,6 +116,127 @@ pub async fn api_stats(State(state): State<Arc<AppState>>) -> Json<RegistryStats
|
|||||||
Json(stats)
|
Json(stats)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn api_dashboard(State(state): State<Arc<AppState>>) -> Json<DashboardResponse> {
|
||||||
|
let registry_stats = get_registry_stats(&state.storage).await;
|
||||||
|
|
||||||
|
// Calculate total storage size
|
||||||
|
let all_keys = state.storage.list("").await;
|
||||||
|
let mut total_storage: u64 = 0;
|
||||||
|
let mut docker_size: u64 = 0;
|
||||||
|
let mut maven_size: u64 = 0;
|
||||||
|
let mut npm_size: u64 = 0;
|
||||||
|
let mut cargo_size: u64 = 0;
|
||||||
|
let mut pypi_size: u64 = 0;
|
||||||
|
|
||||||
|
for key in &all_keys {
|
||||||
|
if let Some(meta) = state.storage.stat(key).await {
|
||||||
|
total_storage += meta.size;
|
||||||
|
if key.starts_with("docker/") {
|
||||||
|
docker_size += meta.size;
|
||||||
|
} else if key.starts_with("maven/") {
|
||||||
|
maven_size += meta.size;
|
||||||
|
} else if key.starts_with("npm/") {
|
||||||
|
npm_size += meta.size;
|
||||||
|
} else if key.starts_with("cargo/") {
|
||||||
|
cargo_size += meta.size;
|
||||||
|
} else if key.starts_with("pypi/") {
|
||||||
|
pypi_size += meta.size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let total_artifacts = registry_stats.docker
|
||||||
|
+ registry_stats.maven
|
||||||
|
+ registry_stats.npm
|
||||||
|
+ registry_stats.cargo
|
||||||
|
+ registry_stats.pypi;
|
||||||
|
|
||||||
|
let global_stats = GlobalStats {
|
||||||
|
downloads: state.metrics.downloads.load(Ordering::Relaxed),
|
||||||
|
uploads: state.metrics.uploads.load(Ordering::Relaxed),
|
||||||
|
artifacts: total_artifacts as u64,
|
||||||
|
cache_hit_percent: state.metrics.cache_hit_rate(),
|
||||||
|
storage_bytes: total_storage,
|
||||||
|
};
|
||||||
|
|
||||||
|
let registry_card_stats = vec![
|
||||||
|
RegistryCardStats {
|
||||||
|
name: "docker".to_string(),
|
||||||
|
artifact_count: registry_stats.docker,
|
||||||
|
downloads: state.metrics.get_registry_downloads("docker"),
|
||||||
|
uploads: state.metrics.get_registry_uploads("docker"),
|
||||||
|
size_bytes: docker_size,
|
||||||
|
},
|
||||||
|
RegistryCardStats {
|
||||||
|
name: "maven".to_string(),
|
||||||
|
artifact_count: registry_stats.maven,
|
||||||
|
downloads: state.metrics.get_registry_downloads("maven"),
|
||||||
|
uploads: state.metrics.get_registry_uploads("maven"),
|
||||||
|
size_bytes: maven_size,
|
||||||
|
},
|
||||||
|
RegistryCardStats {
|
||||||
|
name: "npm".to_string(),
|
||||||
|
artifact_count: registry_stats.npm,
|
||||||
|
downloads: state.metrics.get_registry_downloads("npm"),
|
||||||
|
uploads: 0,
|
||||||
|
size_bytes: npm_size,
|
||||||
|
},
|
||||||
|
RegistryCardStats {
|
||||||
|
name: "cargo".to_string(),
|
||||||
|
artifact_count: registry_stats.cargo,
|
||||||
|
downloads: state.metrics.get_registry_downloads("cargo"),
|
||||||
|
uploads: 0,
|
||||||
|
size_bytes: cargo_size,
|
||||||
|
},
|
||||||
|
RegistryCardStats {
|
||||||
|
name: "pypi".to_string(),
|
||||||
|
artifact_count: registry_stats.pypi,
|
||||||
|
downloads: state.metrics.get_registry_downloads("pypi"),
|
||||||
|
uploads: 0,
|
||||||
|
size_bytes: pypi_size,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
let mount_points = vec![
|
||||||
|
MountPoint {
|
||||||
|
registry: "Docker".to_string(),
|
||||||
|
mount_path: "/v2/".to_string(),
|
||||||
|
proxy_upstream: None,
|
||||||
|
},
|
||||||
|
MountPoint {
|
||||||
|
registry: "Maven".to_string(),
|
||||||
|
mount_path: "/maven2/".to_string(),
|
||||||
|
proxy_upstream: state.config.maven.proxies.first().cloned(),
|
||||||
|
},
|
||||||
|
MountPoint {
|
||||||
|
registry: "npm".to_string(),
|
||||||
|
mount_path: "/npm/".to_string(),
|
||||||
|
proxy_upstream: state.config.npm.proxy.clone(),
|
||||||
|
},
|
||||||
|
MountPoint {
|
||||||
|
registry: "Cargo".to_string(),
|
||||||
|
mount_path: "/cargo/".to_string(),
|
||||||
|
proxy_upstream: None,
|
||||||
|
},
|
||||||
|
MountPoint {
|
||||||
|
registry: "PyPI".to_string(),
|
||||||
|
mount_path: "/simple/".to_string(),
|
||||||
|
proxy_upstream: state.config.pypi.proxy.clone(),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
let activity = state.activity.recent(20);
|
||||||
|
let uptime_seconds = state.start_time.elapsed().as_secs();
|
||||||
|
|
||||||
|
Json(DashboardResponse {
|
||||||
|
global_stats,
|
||||||
|
registry_stats: registry_card_stats,
|
||||||
|
mount_points,
|
||||||
|
activity,
|
||||||
|
uptime_seconds,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn api_list(
|
pub async fn api_list(
|
||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
Path(registry_type): Path<String>,
|
Path(registry_type): Path<String>,
|
||||||
@@ -95,7 +258,7 @@ pub async fn api_detail(
|
|||||||
) -> Json<serde_json::Value> {
|
) -> Json<serde_json::Value> {
|
||||||
match registry_type.as_str() {
|
match registry_type.as_str() {
|
||||||
"docker" => {
|
"docker" => {
|
||||||
let detail = get_docker_detail(&state.storage, &name).await;
|
let detail = get_docker_detail(&state, &name).await;
|
||||||
Json(serde_json::to_value(detail).unwrap_or_default())
|
Json(serde_json::to_value(detail).unwrap_or_default())
|
||||||
}
|
}
|
||||||
"npm" => {
|
"npm" => {
|
||||||
@@ -268,25 +431,80 @@ pub async fn get_docker_repos(storage: &Storage) -> Vec<RepoInfo> {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_docker_detail(storage: &Storage, name: &str) -> DockerDetail {
|
pub async fn get_docker_detail(state: &AppState, name: &str) -> DockerDetail {
|
||||||
let prefix = format!("docker/{}/manifests/", name);
|
let prefix = format!("docker/{}/manifests/", name);
|
||||||
let keys = storage.list(&prefix).await;
|
let keys = state.storage.list(&prefix).await;
|
||||||
|
|
||||||
|
// Build public URL for pull commands
|
||||||
|
let registry_host =
|
||||||
|
state.config.server.public_url.clone().unwrap_or_else(|| {
|
||||||
|
format!("{}:{}", state.config.server.host, state.config.server.port)
|
||||||
|
});
|
||||||
|
|
||||||
let mut tags = Vec::new();
|
let mut tags = Vec::new();
|
||||||
for key in &keys {
|
for key in &keys {
|
||||||
|
// Skip .meta.json files
|
||||||
|
if key.ends_with(".meta.json") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(tag_name) = key
|
if let Some(tag_name) = key
|
||||||
.strip_prefix(&prefix)
|
.strip_prefix(&prefix)
|
||||||
.and_then(|s| s.strip_suffix(".json"))
|
.and_then(|s| s.strip_suffix(".json"))
|
||||||
{
|
{
|
||||||
let (size, created) = if let Some(meta) = storage.stat(key).await {
|
// Load metadata from .meta.json file
|
||||||
(meta.size, format_timestamp(meta.modified))
|
let meta_key = format!("{}.meta.json", key.trim_end_matches(".json"));
|
||||||
|
let metadata = if let Ok(meta_data) = state.storage.get(&meta_key).await {
|
||||||
|
serde_json::from_slice::<crate::registry::docker::ImageMetadata>(&meta_data)
|
||||||
|
.unwrap_or_default()
|
||||||
} else {
|
} else {
|
||||||
(0, "N/A".to_string())
|
crate::registry::docker::ImageMetadata::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get file stats for created timestamp if metadata doesn't have push_timestamp
|
||||||
|
let created = if metadata.push_timestamp > 0 {
|
||||||
|
format_timestamp(metadata.push_timestamp)
|
||||||
|
} else if let Some(file_meta) = state.storage.stat(key).await {
|
||||||
|
format_timestamp(file_meta.modified)
|
||||||
|
} else {
|
||||||
|
"N/A".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use size from metadata if available, otherwise from file
|
||||||
|
let size = if metadata.size_bytes > 0 {
|
||||||
|
metadata.size_bytes
|
||||||
|
} else {
|
||||||
|
state.storage.stat(key).await.map(|m| m.size).unwrap_or(0)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Format last_pulled
|
||||||
|
let last_pulled = if metadata.last_pulled > 0 {
|
||||||
|
Some(format_timestamp(metadata.last_pulled))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
// Build pull command
|
||||||
|
let pull_command = format!("docker pull {}/{}:{}", registry_host, name, tag_name);
|
||||||
|
|
||||||
tags.push(TagInfo {
|
tags.push(TagInfo {
|
||||||
name: tag_name.to_string(),
|
name: tag_name.to_string(),
|
||||||
size,
|
size,
|
||||||
created,
|
created,
|
||||||
|
downloads: metadata.downloads,
|
||||||
|
last_pulled,
|
||||||
|
os: if metadata.os.is_empty() {
|
||||||
|
"unknown".to_string()
|
||||||
|
} else {
|
||||||
|
metadata.os
|
||||||
|
},
|
||||||
|
arch: if metadata.arch.is_empty() {
|
||||||
|
"unknown".to_string()
|
||||||
|
} else {
|
||||||
|
metadata.arch
|
||||||
|
},
|
||||||
|
layers_count: metadata.layers.len(),
|
||||||
|
pull_command,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,20 @@
|
|||||||
/// Main layout wrapper with header and sidebar
|
use super::i18n::{get_translations, Lang, Translations};
|
||||||
pub fn layout(title: &str, content: &str, active_page: Option<&str>) -> String {
|
|
||||||
|
/// Application version from Cargo.toml
|
||||||
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
|
/// Dark theme layout wrapper for dashboard
|
||||||
|
pub fn layout_dark(
|
||||||
|
title: &str,
|
||||||
|
content: &str,
|
||||||
|
active_page: Option<&str>,
|
||||||
|
extra_scripts: &str,
|
||||||
|
lang: Lang,
|
||||||
|
) -> String {
|
||||||
|
let t = get_translations(lang);
|
||||||
format!(
|
format!(
|
||||||
r##"<!DOCTYPE html>
|
r##"<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="{}">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
@@ -14,7 +26,7 @@ pub fn layout(title: &str, content: &str, active_page: Option<&str>) -> String {
|
|||||||
.sidebar-open {{ overflow: hidden; }}
|
.sidebar-open {{ overflow: hidden; }}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-slate-100 min-h-screen">
|
<body class="bg-[#0f172a] min-h-screen">
|
||||||
<div class="flex h-screen overflow-hidden">
|
<div class="flex h-screen overflow-hidden">
|
||||||
<!-- Mobile sidebar overlay -->
|
<!-- Mobile sidebar overlay -->
|
||||||
<div id="sidebar-overlay" class="fixed inset-0 bg-black/50 z-40 hidden md:hidden" onclick="toggleSidebar()"></div>
|
<div id="sidebar-overlay" class="fixed inset-0 bg-black/50 z-40 hidden md:hidden" onclick="toggleSidebar()"></div>
|
||||||
@@ -50,17 +62,424 @@ pub fn layout(title: &str, content: &str, active_page: Option<&str>) -> String {
|
|||||||
document.body.classList.add('sidebar-open');
|
document.body.classList.add('sidebar-open');
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
function setLang(lang) {{
|
||||||
|
document.cookie = 'nora_lang=' + lang + ';path=/;max-age=31536000';
|
||||||
|
window.location.reload();
|
||||||
|
}}
|
||||||
</script>
|
</script>
|
||||||
|
{}
|
||||||
</body>
|
</body>
|
||||||
</html>"##,
|
</html>"##,
|
||||||
|
lang.code(),
|
||||||
html_escape(title),
|
html_escape(title),
|
||||||
sidebar(active_page),
|
sidebar_dark(active_page, t),
|
||||||
header(),
|
header_dark(lang),
|
||||||
content
|
content,
|
||||||
|
extra_scripts
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sidebar navigation component
|
/// Dark theme sidebar
|
||||||
|
fn sidebar_dark(active_page: Option<&str>, t: &Translations) -> String {
|
||||||
|
let active = active_page.unwrap_or("");
|
||||||
|
|
||||||
|
let docker_icon = r#"<path fill="currentColor" d="M13.983 11.078h2.119a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.119a.185.185 0 00-.185.185v1.888c0 .102.083.185.185.185m-2.954-5.43h2.118a.186.186 0 00.186-.186V3.574a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.186m0 2.716h2.118a.187.187 0 00.186-.186V6.29a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.887c0 .102.082.185.185.186m-2.93 0h2.12a.186.186 0 00.184-.186V6.29a.185.185 0 00-.185-.185H8.1a.185.185 0 00-.185.185v1.887c0 .102.083.185.185.186m-2.964 0h2.119a.186.186 0 00.185-.186V6.29a.185.185 0 00-.185-.185H5.136a.186.186 0 00-.186.185v1.887c0 .102.084.185.186.186m5.893 2.715h2.118a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.185m-2.93 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.083.185.185.185m-2.964 0h2.119a.185.185 0 00.185-.185V9.006a.185.185 0 00-.185-.186h-2.12a.186.186 0 00-.185.186v1.887c0 .102.084.185.186.185m-2.92 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.082.185.185.185M23.763 9.89c-.065-.051-.672-.51-1.954-.51-.338.001-.676.03-1.01.087-.248-1.7-1.653-2.53-1.716-2.566l-.344-.199-.226.327c-.284.438-.49.922-.612 1.43-.23.97-.09 1.882.403 2.661-.595.332-1.55.413-1.744.42H.751a.751.751 0 00-.75.748 11.376 11.376 0 00.692 4.062c.545 1.428 1.355 2.48 2.41 3.124 1.18.723 3.1 1.137 5.275 1.137.983.003 1.963-.086 2.93-.266a12.248 12.248 0 003.823-1.389c.98-.567 1.86-1.288 2.61-2.136 1.252-1.418 1.998-2.997 2.553-4.4h.221c1.372 0 2.215-.549 2.68-1.009.309-.293.55-.65.707-1.046l.098-.288Z"/>"#;
|
||||||
|
let maven_icon = r#"<path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/>"#;
|
||||||
|
let npm_icon = r#"<path fill="currentColor" d="M0 7.334v8h6.666v1.332H12v-1.332h12v-8H0zm6.666 6.664H5.334v-4H3.999v4H1.335V8.667h5.331v5.331zm4 0v1.336H8.001V8.667h5.334v5.332h-2.669v-.001zm12.001 0h-1.33v-4h-1.336v4h-1.335v-4h-1.33v4h-2.671V8.667h8.002v5.331zM10.665 10H12v2.667h-1.335V10z"/>"#;
|
||||||
|
let cargo_icon = r#"<path fill="currentColor" d="M20 8h-3V4H3c-1.1 0-2 .9-2 2v11h2c0 1.66 1.34 3 3 3s3-1.34 3-3h6c0 1.66 1.34 3 3 3s3-1.34 3-3h2v-5l-3-4zM6 18.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm13.5-9l1.96 2.5H17V9.5h2.5zm-1.5 9c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z"/>"#;
|
||||||
|
let pypi_icon = r#"<path fill="currentColor" d="M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.83l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.23l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05L0 11.97l.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.24l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05 1.07.13zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09-.33.22zM21.1 6.11l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01.21.03zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08-.33.23z"/>"#;
|
||||||
|
|
||||||
|
// Dashboard label is translated, registry names stay as-is
|
||||||
|
let dashboard_label = t.nav_dashboard;
|
||||||
|
|
||||||
|
let nav_items = [
|
||||||
|
(
|
||||||
|
"dashboard",
|
||||||
|
"/ui/",
|
||||||
|
dashboard_label,
|
||||||
|
r#"<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/>"#,
|
||||||
|
true,
|
||||||
|
),
|
||||||
|
("docker", "/ui/docker", "Docker", docker_icon, false),
|
||||||
|
("maven", "/ui/maven", "Maven", maven_icon, false),
|
||||||
|
("npm", "/ui/npm", "npm", npm_icon, false),
|
||||||
|
("cargo", "/ui/cargo", "Cargo", cargo_icon, false),
|
||||||
|
("pypi", "/ui/pypi", "PyPI", pypi_icon, false),
|
||||||
|
];
|
||||||
|
|
||||||
|
let nav_html: String = nav_items.iter().map(|(id, href, label, icon_path, is_stroke)| {
|
||||||
|
let is_active = active == *id;
|
||||||
|
let active_class = if is_active {
|
||||||
|
"bg-slate-700 text-white"
|
||||||
|
} else {
|
||||||
|
"text-slate-300 hover:bg-slate-700 hover:text-white"
|
||||||
|
};
|
||||||
|
|
||||||
|
let (fill_attr, stroke_attr) = if *is_stroke {
|
||||||
|
("none", r#" stroke="currentColor""#)
|
||||||
|
} else {
|
||||||
|
("currentColor", "")
|
||||||
|
};
|
||||||
|
|
||||||
|
format!(r##"
|
||||||
|
<a href="{}" class="flex items-center px-4 py-3 text-sm font-medium rounded-lg transition-colors {}">
|
||||||
|
<svg class="w-5 h-5 mr-3" fill="{}"{} viewBox="0 0 24 24">
|
||||||
|
{}
|
||||||
|
</svg>
|
||||||
|
{}
|
||||||
|
</a>
|
||||||
|
"##, href, active_class, fill_attr, stroke_attr, icon_path, label)
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
format!(
|
||||||
|
r#"
|
||||||
|
<div id="sidebar" class="fixed md:static inset-y-0 left-0 z-50 w-64 bg-slate-800 text-white flex flex-col transform -translate-x-full md:translate-x-0 transition-transform duration-200 ease-in-out">
|
||||||
|
<div class="h-16 flex items-center justify-between px-6 border-b border-slate-700">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<span class="text-2xl font-bold tracking-tight">N<span class="inline-block w-5 h-5 rounded-full border-2 border-current align-middle relative -top-0.5 mx-0.5"></span>RA</span>
|
||||||
|
</div>
|
||||||
|
<button onclick="toggleSidebar()" class="md:hidden p-1 rounded-lg hover:bg-slate-700">
|
||||||
|
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<nav class="flex-1 px-4 py-6 space-y-1 overflow-y-auto">
|
||||||
|
{}
|
||||||
|
<div class="text-xs font-semibold text-slate-400 uppercase tracking-wider px-4 mt-6 mb-3">
|
||||||
|
{}
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
<div class="px-4 py-4 border-t border-slate-700">
|
||||||
|
<div class="text-xs text-slate-400">
|
||||||
|
Nora v{}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
"#,
|
||||||
|
nav_html, t.nav_registries, VERSION
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Dark theme header with language switcher
|
||||||
|
fn header_dark(lang: Lang) -> String {
|
||||||
|
let (en_class, ru_class) = match lang {
|
||||||
|
Lang::En => (
|
||||||
|
"text-white font-semibold",
|
||||||
|
"text-slate-400 hover:text-slate-200",
|
||||||
|
),
|
||||||
|
Lang::Ru => (
|
||||||
|
"text-slate-400 hover:text-slate-200",
|
||||||
|
"text-white font-semibold",
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
format!(
|
||||||
|
r##"
|
||||||
|
<header class="h-16 bg-[#1e293b] border-b border-slate-700 flex items-center justify-between px-4 md:px-6">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<button onclick="toggleSidebar()" class="md:hidden p-2 -ml-2 mr-2 rounded-lg hover:bg-slate-700">
|
||||||
|
<svg class="w-6 h-6 text-slate-300" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<div class="md:hidden flex items-center">
|
||||||
|
<span class="font-bold text-slate-200 tracking-tight">N<span class="inline-block w-4 h-4 rounded-full border-2 border-current align-middle mx-px"></span>RA</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center space-x-2 md:space-x-4">
|
||||||
|
<!-- Language switcher -->
|
||||||
|
<div class="flex items-center border border-slate-600 rounded-lg overflow-hidden text-sm">
|
||||||
|
<button onclick="setLang('en')" class="px-3 py-1.5 {} transition-colors">EN</button>
|
||||||
|
<span class="text-slate-600">|</span>
|
||||||
|
<button onclick="setLang('ru')" class="px-3 py-1.5 {} transition-colors">RU</button>
|
||||||
|
</div>
|
||||||
|
<a href="https://github.com/getnora-io/nora" target="_blank" class="p-2 text-slate-400 hover:text-slate-200 hover:bg-slate-700 rounded-lg">
|
||||||
|
<svg class="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.202 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.943.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"/>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
<a href="/api-docs" class="p-2 text-slate-400 hover:text-slate-200 hover:bg-slate-700 rounded-lg" title="API Docs">
|
||||||
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
|
||||||
|
</svg>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
"##,
|
||||||
|
en_class, ru_class
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render global stats row (5-column grid)
|
||||||
|
pub fn render_global_stats(
|
||||||
|
downloads: u64,
|
||||||
|
uploads: u64,
|
||||||
|
artifacts: u64,
|
||||||
|
cache_hit_percent: f64,
|
||||||
|
storage_bytes: u64,
|
||||||
|
lang: Lang,
|
||||||
|
) -> String {
|
||||||
|
let t = get_translations(lang);
|
||||||
|
format!(
|
||||||
|
r##"
|
||||||
|
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4 mb-6">
|
||||||
|
<div class="bg-[#1e293b] rounded-lg p-4 border border-slate-700">
|
||||||
|
<div class="text-slate-400 text-sm mb-1">{}</div>
|
||||||
|
<div id="stat-downloads" class="text-2xl font-bold text-slate-200">{}</div>
|
||||||
|
</div>
|
||||||
|
<div class="bg-[#1e293b] rounded-lg p-4 border border-slate-700">
|
||||||
|
<div class="text-slate-400 text-sm mb-1">{}</div>
|
||||||
|
<div id="stat-uploads" class="text-2xl font-bold text-slate-200">{}</div>
|
||||||
|
</div>
|
||||||
|
<div class="bg-[#1e293b] rounded-lg p-4 border border-slate-700">
|
||||||
|
<div class="text-slate-400 text-sm mb-1">{}</div>
|
||||||
|
<div id="stat-artifacts" class="text-2xl font-bold text-slate-200">{}</div>
|
||||||
|
</div>
|
||||||
|
<div class="bg-[#1e293b] rounded-lg p-4 border border-slate-700">
|
||||||
|
<div class="text-slate-400 text-sm mb-1">{}</div>
|
||||||
|
<div id="stat-cache-hit" class="text-2xl font-bold text-slate-200">{:.1}%</div>
|
||||||
|
</div>
|
||||||
|
<div class="bg-[#1e293b] rounded-lg p-4 border border-slate-700">
|
||||||
|
<div class="text-slate-400 text-sm mb-1">{}</div>
|
||||||
|
<div id="stat-storage" class="text-2xl font-bold text-slate-200">{}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
"##,
|
||||||
|
t.stat_downloads,
|
||||||
|
downloads,
|
||||||
|
t.stat_uploads,
|
||||||
|
uploads,
|
||||||
|
t.stat_artifacts,
|
||||||
|
artifacts,
|
||||||
|
t.stat_cache_hit,
|
||||||
|
cache_hit_percent,
|
||||||
|
t.stat_storage,
|
||||||
|
format_size(storage_bytes)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render registry card with extended metrics
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
pub fn render_registry_card(
|
||||||
|
name: &str,
|
||||||
|
icon_path: &str,
|
||||||
|
artifact_count: usize,
|
||||||
|
downloads: u64,
|
||||||
|
uploads: u64,
|
||||||
|
size_bytes: u64,
|
||||||
|
href: &str,
|
||||||
|
t: &Translations,
|
||||||
|
) -> String {
|
||||||
|
format!(
|
||||||
|
r##"
|
||||||
|
<a href="{}" id="registry-{}" class="block bg-[#1e293b] rounded-lg border border-slate-700 p-4 md:p-6 hover:border-blue-400 transition-all">
|
||||||
|
<div class="flex items-center justify-between mb-3">
|
||||||
|
<svg class="w-8 h-8 text-slate-400" fill="currentColor" viewBox="0 0 24 24">
|
||||||
|
{}
|
||||||
|
</svg>
|
||||||
|
<span class="text-xs font-medium text-green-400 bg-green-400/10 px-2 py-1 rounded-full">{}</span>
|
||||||
|
</div>
|
||||||
|
<div class="text-lg font-semibold text-slate-200 mb-2">{}</div>
|
||||||
|
<div class="grid grid-cols-2 gap-2 text-sm">
|
||||||
|
<div>
|
||||||
|
<span class="text-slate-500">{}</span>
|
||||||
|
<div class="text-slate-300 font-medium">{}</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="text-slate-500">{}</span>
|
||||||
|
<div class="text-slate-300 font-medium">{}</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="text-slate-500">{}</span>
|
||||||
|
<div class="text-slate-300 font-medium">{}</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="text-slate-500">{}</span>
|
||||||
|
<div class="text-slate-300 font-medium">{}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
"##,
|
||||||
|
href,
|
||||||
|
name.to_lowercase(),
|
||||||
|
icon_path,
|
||||||
|
t.active,
|
||||||
|
name,
|
||||||
|
t.artifacts,
|
||||||
|
artifact_count,
|
||||||
|
t.size,
|
||||||
|
format_size(size_bytes),
|
||||||
|
t.downloads,
|
||||||
|
downloads,
|
||||||
|
t.uploads,
|
||||||
|
uploads
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render mount points table
|
||||||
|
pub fn render_mount_points_table(
|
||||||
|
mount_points: &[(String, String, Option<String>)],
|
||||||
|
t: &Translations,
|
||||||
|
) -> String {
|
||||||
|
let rows: String = mount_points
|
||||||
|
.iter()
|
||||||
|
.map(|(registry, mount_path, proxy)| {
|
||||||
|
let proxy_display = proxy.as_deref().unwrap_or("-");
|
||||||
|
format!(
|
||||||
|
r##"
|
||||||
|
<tr class="border-b border-slate-700">
|
||||||
|
<td class="py-3 text-slate-300">{}</td>
|
||||||
|
<td class="py-3 font-mono text-blue-400">{}</td>
|
||||||
|
<td class="py-3 text-slate-400">{}</td>
|
||||||
|
</tr>
|
||||||
|
"##,
|
||||||
|
registry, mount_path, proxy_display
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
format!(
|
||||||
|
r##"
|
||||||
|
<div class="bg-[#1e293b] rounded-lg border border-slate-700 overflow-hidden">
|
||||||
|
<div class="px-4 py-3 border-b border-slate-700">
|
||||||
|
<h3 class="text-slate-200 font-semibold">{}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="overflow-auto max-h-80">
|
||||||
|
<table class="w-full">
|
||||||
|
<thead class="sticky top-0 bg-slate-800">
|
||||||
|
<tr class="text-left text-xs text-slate-500 uppercase border-b border-slate-700">
|
||||||
|
<th class="px-4 py-2">{}</th>
|
||||||
|
<th class="px-4 py-2">{}</th>
|
||||||
|
<th class="px-4 py-2">{}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="px-4">
|
||||||
|
{}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
"##,
|
||||||
|
t.mount_points, t.registry, t.mount_path, t.proxy_upstream, rows
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render a single activity log row
|
||||||
|
pub fn render_activity_row(
|
||||||
|
timestamp: &str,
|
||||||
|
action: &str,
|
||||||
|
artifact: &str,
|
||||||
|
registry: &str,
|
||||||
|
source: &str,
|
||||||
|
) -> String {
|
||||||
|
let action_color = match action {
|
||||||
|
"PULL" => "text-blue-400",
|
||||||
|
"PUSH" => "text-green-400",
|
||||||
|
"CACHE" => "text-yellow-400",
|
||||||
|
"PROXY" => "text-purple-400",
|
||||||
|
_ => "text-slate-400",
|
||||||
|
};
|
||||||
|
|
||||||
|
format!(
|
||||||
|
r##"
|
||||||
|
<tr class="border-b border-slate-700/50 text-sm">
|
||||||
|
<td class="py-2 text-slate-500">{}</td>
|
||||||
|
<td class="py-2 font-medium {}"><span class="px-2 py-0.5 bg-slate-700 rounded">{}</span></td>
|
||||||
|
<td class="py-2 text-slate-300 font-mono text-xs">{}</td>
|
||||||
|
<td class="py-2 text-slate-400">{}</td>
|
||||||
|
<td class="py-2 text-slate-500">{}</td>
|
||||||
|
</tr>
|
||||||
|
"##,
|
||||||
|
timestamp,
|
||||||
|
action_color,
|
||||||
|
action,
|
||||||
|
html_escape(artifact),
|
||||||
|
registry,
|
||||||
|
source
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render the activity log container
|
||||||
|
pub fn render_activity_log(rows: &str, t: &Translations) -> String {
|
||||||
|
format!(
|
||||||
|
r##"
|
||||||
|
<div class="bg-[#1e293b] rounded-lg border border-slate-700 overflow-hidden">
|
||||||
|
<div class="px-4 py-3 border-b border-slate-700 flex items-center justify-between">
|
||||||
|
<h3 class="text-slate-200 font-semibold">{}</h3>
|
||||||
|
<span class="text-xs text-slate-500">{}</span>
|
||||||
|
</div>
|
||||||
|
<div class="overflow-auto max-h-80">
|
||||||
|
<table class="w-full" id="activity-log">
|
||||||
|
<thead class="sticky top-0 bg-slate-800">
|
||||||
|
<tr class="text-left text-xs text-slate-500 uppercase border-b border-slate-700">
|
||||||
|
<th class="px-4 py-2">{}</th>
|
||||||
|
<th class="px-4 py-2">{}</th>
|
||||||
|
<th class="px-4 py-2">{}</th>
|
||||||
|
<th class="px-4 py-2">{}</th>
|
||||||
|
<th class="px-4 py-2">{}</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="px-4">
|
||||||
|
{}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
"##,
|
||||||
|
t.recent_activity,
|
||||||
|
t.last_n_events,
|
||||||
|
t.time,
|
||||||
|
t.action,
|
||||||
|
t.artifact,
|
||||||
|
t.registry,
|
||||||
|
t.source,
|
||||||
|
rows
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render the polling script for auto-refresh
|
||||||
|
pub fn render_polling_script() -> String {
|
||||||
|
r##"
|
||||||
|
<script>
|
||||||
|
setInterval(async () => {
|
||||||
|
try {
|
||||||
|
const data = await fetch('/api/ui/dashboard').then(r => r.json());
|
||||||
|
|
||||||
|
// Update global stats
|
||||||
|
document.getElementById('stat-downloads').textContent = data.global_stats.downloads;
|
||||||
|
document.getElementById('stat-uploads').textContent = data.global_stats.uploads;
|
||||||
|
document.getElementById('stat-artifacts').textContent = data.global_stats.artifacts;
|
||||||
|
document.getElementById('stat-cache-hit').textContent = data.global_stats.cache_hit_percent.toFixed(1) + '%';
|
||||||
|
|
||||||
|
// Format storage size
|
||||||
|
const bytes = data.global_stats.storage_bytes;
|
||||||
|
let sizeStr;
|
||||||
|
if (bytes >= 1073741824) sizeStr = (bytes / 1073741824).toFixed(1) + ' GB';
|
||||||
|
else if (bytes >= 1048576) sizeStr = (bytes / 1048576).toFixed(1) + ' MB';
|
||||||
|
else if (bytes >= 1024) sizeStr = (bytes / 1024).toFixed(1) + ' KB';
|
||||||
|
else sizeStr = bytes + ' B';
|
||||||
|
document.getElementById('stat-storage').textContent = sizeStr;
|
||||||
|
|
||||||
|
// Update uptime
|
||||||
|
const uptime = document.getElementById('uptime');
|
||||||
|
if (uptime) {
|
||||||
|
const secs = data.uptime_seconds;
|
||||||
|
const hours = Math.floor(secs / 3600);
|
||||||
|
const mins = Math.floor((secs % 3600) / 60);
|
||||||
|
uptime.textContent = hours + 'h ' + mins + 'm';
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Dashboard poll failed:', e);
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
</script>
|
||||||
|
"##.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sidebar navigation component (light theme, unused)
|
||||||
|
#[allow(dead_code)]
|
||||||
fn sidebar(active_page: Option<&str>) -> String {
|
fn sidebar(active_page: Option<&str>) -> String {
|
||||||
let active = active_page.unwrap_or("");
|
let active = active_page.unwrap_or("");
|
||||||
|
|
||||||
@@ -68,7 +487,7 @@ fn sidebar(active_page: Option<&str>) -> String {
|
|||||||
let docker_icon = r#"<path fill="currentColor" d="M13.983 11.078h2.119a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.119a.185.185 0 00-.185.185v1.888c0 .102.083.185.185.185m-2.954-5.43h2.118a.186.186 0 00.186-.186V3.574a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.186m0 2.716h2.118a.187.187 0 00.186-.186V6.29a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.887c0 .102.082.185.185.186m-2.93 0h2.12a.186.186 0 00.184-.186V6.29a.185.185 0 00-.185-.185H8.1a.185.185 0 00-.185.185v1.887c0 .102.083.185.185.186m-2.964 0h2.119a.186.186 0 00.185-.186V6.29a.185.185 0 00-.185-.185H5.136a.186.186 0 00-.186.185v1.887c0 .102.084.185.186.186m5.893 2.715h2.118a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.185m-2.93 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.083.185.185.185m-2.964 0h2.119a.185.185 0 00.185-.185V9.006a.185.185 0 00-.185-.186h-2.12a.186.186 0 00-.185.186v1.887c0 .102.084.185.186.185m-2.92 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.082.185.185.185M23.763 9.89c-.065-.051-.672-.51-1.954-.51-.338.001-.676.03-1.01.087-.248-1.7-1.653-2.53-1.716-2.566l-.344-.199-.226.327c-.284.438-.49.922-.612 1.43-.23.97-.09 1.882.403 2.661-.595.332-1.55.413-1.744.42H.751a.751.751 0 00-.75.748 11.376 11.376 0 00.692 4.062c.545 1.428 1.355 2.48 2.41 3.124 1.18.723 3.1 1.137 5.275 1.137.983.003 1.963-.086 2.93-.266a12.248 12.248 0 003.823-1.389c.98-.567 1.86-1.288 2.61-2.136 1.252-1.418 1.998-2.997 2.553-4.4h.221c1.372 0 2.215-.549 2.68-1.009.309-.293.55-.65.707-1.046l.098-.288Z"/>"#;
|
let docker_icon = r#"<path fill="currentColor" d="M13.983 11.078h2.119a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.119a.185.185 0 00-.185.185v1.888c0 .102.083.185.185.185m-2.954-5.43h2.118a.186.186 0 00.186-.186V3.574a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.186m0 2.716h2.118a.187.187 0 00.186-.186V6.29a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.887c0 .102.082.185.185.186m-2.93 0h2.12a.186.186 0 00.184-.186V6.29a.185.185 0 00-.185-.185H8.1a.185.185 0 00-.185.185v1.887c0 .102.083.185.185.186m-2.964 0h2.119a.186.186 0 00.185-.186V6.29a.185.185 0 00-.185-.185H5.136a.186.186 0 00-.186.185v1.887c0 .102.084.185.186.186m5.893 2.715h2.118a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.185m-2.93 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.083.185.185.185m-2.964 0h2.119a.185.185 0 00.185-.185V9.006a.185.185 0 00-.185-.186h-2.12a.186.186 0 00-.185.186v1.887c0 .102.084.185.186.185m-2.92 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.082.185.185.185M23.763 9.89c-.065-.051-.672-.51-1.954-.51-.338.001-.676.03-1.01.087-.248-1.7-1.653-2.53-1.716-2.566l-.344-.199-.226.327c-.284.438-.49.922-.612 1.43-.23.97-.09 1.882.403 2.661-.595.332-1.55.413-1.744.42H.751a.751.751 0 00-.75.748 11.376 11.376 0 00.692 4.062c.545 1.428 1.355 2.48 2.41 3.124 1.18.723 3.1 1.137 5.275 1.137.983.003 1.963-.086 2.93-.266a12.248 12.248 0 003.823-1.389c.98-.567 1.86-1.288 2.61-2.136 1.252-1.418 1.998-2.997 2.553-4.4h.221c1.372 0 2.215-.549 2.68-1.009.309-.293.55-.65.707-1.046l.098-.288Z"/>"#;
|
||||||
let maven_icon = r#"<path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/>"#;
|
let maven_icon = r#"<path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/>"#;
|
||||||
let npm_icon = r#"<path fill="currentColor" d="M0 7.334v8h6.666v1.332H12v-1.332h12v-8H0zm6.666 6.664H5.334v-4H3.999v4H1.335V8.667h5.331v5.331zm4 0v1.336H8.001V8.667h5.334v5.332h-2.669v-.001zm12.001 0h-1.33v-4h-1.336v4h-1.335v-4h-1.33v4h-2.671V8.667h8.002v5.331zM10.665 10H12v2.667h-1.335V10z"/>"#;
|
let npm_icon = r#"<path fill="currentColor" d="M0 7.334v8h6.666v1.332H12v-1.332h12v-8H0zm6.666 6.664H5.334v-4H3.999v4H1.335V8.667h5.331v5.331zm4 0v1.336H8.001V8.667h5.334v5.332h-2.669v-.001zm12.001 0h-1.33v-4h-1.336v4h-1.335v-4h-1.33v4h-2.671V8.667h8.002v5.331zM10.665 10H12v2.667h-1.335V10z"/>"#;
|
||||||
let cargo_icon = r#"<path fill="currentColor" d="M23.834 8.101a13.912 13.912 0 0 1-13.643 11.72 10.105 10.105 0 0 1-1.994-.12 6.111 6.111 0 0 1-5.082-5.761 5.934 5.934 0 0 1 11.867-.084c.025.983-.401 1.846-1.277 1.871-.936 0-1.374-.668-1.374-1.567v-2.5a1.531 1.531 0 0 0-1.52-1.533H8.715a3.648 3.648 0 1 0 2.695 6.08l.073-.11.074.121a2.58 2.58 0 0 0 2.2 1.048 2.909 2.909 0 0 0 2.695-3.04 7.912 7.912 0 0 0-.217-1.933 7.404 7.404 0 0 0-14.64 1.603 7.497 7.497 0 0 0 7.308 7.405 12.822 12.822 0 0 0 2.14-.12 11.927 11.927 0 0 0 9.98-10.023.117.117 0 0 0-.043-.117.115.115 0 0 0-.084-.023l-.09.024a.116.116 0 0 1-.147-.085.116.116 0 0 1 .054-.133zm-14.49 7.072a2.162 2.162 0 1 1 0-4.324 2.162 2.162 0 0 1 0 4.324z"/>"#;
|
let cargo_icon = r#"<path fill="currentColor" d="M20 8h-3V4H3c-1.1 0-2 .9-2 2v11h2c0 1.66 1.34 3 3 3s3-1.34 3-3h6c0 1.66 1.34 3 3 3s3-1.34 3-3h2v-5l-3-4zM6 18.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm13.5-9l1.96 2.5H17V9.5h2.5zm-1.5 9c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z"/>"#;
|
||||||
let pypi_icon = r#"<path fill="currentColor" d="M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.83l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.23l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05L0 11.97l.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.24l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05 1.07.13zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09-.33.22zM21.1 6.11l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01.21.03zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08-.33.23z"/>"#;
|
let pypi_icon = r#"<path fill="currentColor" d="M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.83l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.23l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05L0 11.97l.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.24l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05 1.07.13zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09-.33.22zM21.1 6.11l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01.21.03zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08-.33.23z"/>"#;
|
||||||
|
|
||||||
let nav_items = [
|
let nav_items = [
|
||||||
@@ -142,17 +561,19 @@ fn sidebar(active_page: Option<&str>) -> String {
|
|||||||
<!-- Footer -->
|
<!-- Footer -->
|
||||||
<div class="px-4 py-4 border-t border-slate-700">
|
<div class="px-4 py-4 border-t border-slate-700">
|
||||||
<div class="text-xs text-slate-400">
|
<div class="text-xs text-slate-400">
|
||||||
Nora v0.2.0
|
Nora v{}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
"#,
|
"#,
|
||||||
super::logo::LOGO_BASE64,
|
super::logo::LOGO_BASE64,
|
||||||
nav_html
|
nav_html,
|
||||||
|
VERSION
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Header component
|
/// Header component (light theme, unused)
|
||||||
|
#[allow(dead_code)]
|
||||||
fn header() -> String {
|
fn header() -> String {
|
||||||
r##"
|
r##"
|
||||||
<header class="h-16 bg-white border-b border-slate-200 flex items-center justify-between px-4 md:px-6">
|
<header class="h-16 bg-white border-b border-slate-200 flex items-center justify-between px-4 md:px-6">
|
||||||
@@ -189,11 +610,12 @@ pub mod icons {
|
|||||||
pub const DOCKER: &str = r#"<path fill="currentColor" d="M13.983 11.078h2.119a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.119a.185.185 0 00-.185.185v1.888c0 .102.083.185.185.185m-2.954-5.43h2.118a.186.186 0 00.186-.186V3.574a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.186m0 2.716h2.118a.187.187 0 00.186-.186V6.29a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.887c0 .102.082.185.185.186m-2.93 0h2.12a.186.186 0 00.184-.186V6.29a.185.185 0 00-.185-.185H8.1a.185.185 0 00-.185.185v1.887c0 .102.083.185.185.186m-2.964 0h2.119a.186.186 0 00.185-.186V6.29a.185.185 0 00-.185-.185H5.136a.186.186 0 00-.186.185v1.887c0 .102.084.185.186.186m5.893 2.715h2.118a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.185m-2.93 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.083.185.185.185m-2.964 0h2.119a.185.185 0 00.185-.185V9.006a.185.185 0 00-.185-.186h-2.12a.186.186 0 00-.185.186v1.887c0 .102.084.185.186.185m-2.92 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.082.185.185.185M23.763 9.89c-.065-.051-.672-.51-1.954-.51-.338.001-.676.03-1.01.087-.248-1.7-1.653-2.53-1.716-2.566l-.344-.199-.226.327c-.284.438-.49.922-.612 1.43-.23.97-.09 1.882.403 2.661-.595.332-1.55.413-1.744.42H.751a.751.751 0 00-.75.748 11.376 11.376 0 00.692 4.062c.545 1.428 1.355 2.48 2.41 3.124 1.18.723 3.1 1.137 5.275 1.137.983.003 1.963-.086 2.93-.266a12.248 12.248 0 003.823-1.389c.98-.567 1.86-1.288 2.61-2.136 1.252-1.418 1.998-2.997 2.553-4.4h.221c1.372 0 2.215-.549 2.68-1.009.309-.293.55-.65.707-1.046l.098-.288Z"/>"#;
|
pub const DOCKER: &str = r#"<path fill="currentColor" d="M13.983 11.078h2.119a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.119a.185.185 0 00-.185.185v1.888c0 .102.083.185.185.185m-2.954-5.43h2.118a.186.186 0 00.186-.186V3.574a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.186m0 2.716h2.118a.187.187 0 00.186-.186V6.29a.186.186 0 00-.186-.185h-2.118a.185.185 0 00-.185.185v1.887c0 .102.082.185.185.186m-2.93 0h2.12a.186.186 0 00.184-.186V6.29a.185.185 0 00-.185-.185H8.1a.185.185 0 00-.185.185v1.887c0 .102.083.185.185.186m-2.964 0h2.119a.186.186 0 00.185-.186V6.29a.185.185 0 00-.185-.185H5.136a.186.186 0 00-.186.185v1.887c0 .102.084.185.186.186m5.893 2.715h2.118a.186.186 0 00.186-.185V9.006a.186.186 0 00-.186-.186h-2.118a.185.185 0 00-.185.185v1.888c0 .102.082.185.185.185m-2.93 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.083.185.185.185m-2.964 0h2.119a.185.185 0 00.185-.185V9.006a.185.185 0 00-.185-.186h-2.12a.186.186 0 00-.185.186v1.887c0 .102.084.185.186.185m-2.92 0h2.12a.185.185 0 00.184-.185V9.006a.185.185 0 00-.184-.186h-2.12a.185.185 0 00-.184.185v1.888c0 .102.082.185.185.185M23.763 9.89c-.065-.051-.672-.51-1.954-.51-.338.001-.676.03-1.01.087-.248-1.7-1.653-2.53-1.716-2.566l-.344-.199-.226.327c-.284.438-.49.922-.612 1.43-.23.97-.09 1.882.403 2.661-.595.332-1.55.413-1.744.42H.751a.751.751 0 00-.75.748 11.376 11.376 0 00.692 4.062c.545 1.428 1.355 2.48 2.41 3.124 1.18.723 3.1 1.137 5.275 1.137.983.003 1.963-.086 2.93-.266a12.248 12.248 0 003.823-1.389c.98-.567 1.86-1.288 2.61-2.136 1.252-1.418 1.998-2.997 2.553-4.4h.221c1.372 0 2.215-.549 2.68-1.009.309-.293.55-.65.707-1.046l.098-.288Z"/>"#;
|
||||||
pub const MAVEN: &str = r#"<path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/>"#;
|
pub const MAVEN: &str = r#"<path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/>"#;
|
||||||
pub const NPM: &str = r#"<path fill="currentColor" d="M0 7.334v8h6.666v1.332H12v-1.332h12v-8H0zm6.666 6.664H5.334v-4H3.999v4H1.335V8.667h5.331v5.331zm4 0v1.336H8.001V8.667h5.334v5.332h-2.669v-.001zm12.001 0h-1.33v-4h-1.336v4h-1.335v-4h-1.33v4h-2.671V8.667h8.002v5.331zM10.665 10H12v2.667h-1.335V10z"/>"#;
|
pub const NPM: &str = r#"<path fill="currentColor" d="M0 7.334v8h6.666v1.332H12v-1.332h12v-8H0zm6.666 6.664H5.334v-4H3.999v4H1.335V8.667h5.331v5.331zm4 0v1.336H8.001V8.667h5.334v5.332h-2.669v-.001zm12.001 0h-1.33v-4h-1.336v4h-1.335v-4h-1.33v4h-2.671V8.667h8.002v5.331zM10.665 10H12v2.667h-1.335V10z"/>"#;
|
||||||
pub const CARGO: &str = r#"<path fill="currentColor" d="M23.834 8.101a13.912 13.912 0 0 1-13.643 11.72 10.105 10.105 0 0 1-1.994-.12 6.111 6.111 0 0 1-5.082-5.761 5.934 5.934 0 0 1 11.867-.084c.025.983-.401 1.846-1.277 1.871-.936 0-1.374-.668-1.374-1.567v-2.5a1.531 1.531 0 0 0-1.52-1.533H8.715a3.648 3.648 0 1 0 2.695 6.08l.073-.11.074.121a2.58 2.58 0 0 0 2.2 1.048 2.909 2.909 0 0 0 2.695-3.04 7.912 7.912 0 0 0-.217-1.933 7.404 7.404 0 0 0-14.64 1.603 7.497 7.497 0 0 0 7.308 7.405 12.822 12.822 0 0 0 2.14-.12 11.927 11.927 0 0 0 9.98-10.023.117.117 0 0 0-.043-.117.115.115 0 0 0-.084-.023l-.09.024a.116.116 0 0 1-.147-.085.116.116 0 0 1 .054-.133zm-14.49 7.072a2.162 2.162 0 1 1 0-4.324 2.162 2.162 0 0 1 0 4.324z"/>"#;
|
pub const CARGO: &str = r#"<path fill="currentColor" d="M20 8h-3V4H3c-1.1 0-2 .9-2 2v11h2c0 1.66 1.34 3 3 3s3-1.34 3-3h6c0 1.66 1.34 3 3 3s3-1.34 3-3h2v-5l-3-4zM6 18.5c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5zm13.5-9l1.96 2.5H17V9.5h2.5zm-1.5 9c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5 1.5.67 1.5 1.5-.67 1.5-1.5 1.5z"/>"#;
|
||||||
pub const PYPI: &str = r#"<path fill="currentColor" d="M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.83l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.23l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05L0 11.97l.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.24l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05 1.07.13zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09-.33.22zM21.1 6.11l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01.21.03zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08-.33.23z"/>"#;
|
pub const PYPI: &str = r#"<path fill="currentColor" d="M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.83l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.23l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05L0 11.97l.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.24l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05 1.07.13zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09-.33.22zM21.1 6.11l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01.21.03zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08-.33.23z"/>"#;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stat card for dashboard with SVG icon
|
/// Stat card for dashboard with SVG icon (used in light theme pages)
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn stat_card(name: &str, icon_path: &str, count: usize, href: &str, unit: &str) -> String {
|
pub fn stat_card(name: &str, icon_path: &str, count: usize, href: &str, unit: &str) -> String {
|
||||||
format!(
|
format!(
|
||||||
r##"
|
r##"
|
||||||
@@ -239,6 +661,57 @@ pub fn html_escape(s: &str) -> String {
|
|||||||
.replace('\'', "'")
|
.replace('\'', "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Render the "bragging" footer with NORA stats
|
||||||
|
pub fn render_bragging_footer(lang: Lang) -> String {
|
||||||
|
let t = get_translations(lang);
|
||||||
|
format!(
|
||||||
|
r##"
|
||||||
|
<div class="mt-8 bg-gradient-to-r from-slate-800 to-slate-900 rounded-lg border border-slate-700 p-6">
|
||||||
|
<div class="text-center mb-4">
|
||||||
|
<span class="text-slate-400 text-sm uppercase tracking-wider">{}</span>
|
||||||
|
</div>
|
||||||
|
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4 text-center">
|
||||||
|
<div class="p-3">
|
||||||
|
<div class="text-2xl font-bold text-blue-400">34 MB</div>
|
||||||
|
<div class="text-xs text-slate-500 mt-1">{}</div>
|
||||||
|
</div>
|
||||||
|
<div class="p-3">
|
||||||
|
<div class="text-2xl font-bold text-green-400"><1s</div>
|
||||||
|
<div class="text-xs text-slate-500 mt-1">{}</div>
|
||||||
|
</div>
|
||||||
|
<div class="p-3">
|
||||||
|
<div class="text-2xl font-bold text-purple-400">~30 MB</div>
|
||||||
|
<div class="text-xs text-slate-500 mt-1">{}</div>
|
||||||
|
</div>
|
||||||
|
<div class="p-3">
|
||||||
|
<div class="text-2xl font-bold text-yellow-400">5</div>
|
||||||
|
<div class="text-xs text-slate-500 mt-1">{}</div>
|
||||||
|
</div>
|
||||||
|
<div class="p-3">
|
||||||
|
<div class="text-2xl font-bold text-pink-400">{}</div>
|
||||||
|
<div class="text-xs text-slate-500 mt-1">amd64 / arm64</div>
|
||||||
|
</div>
|
||||||
|
<div class="p-3">
|
||||||
|
<div class="text-2xl font-bold text-cyan-400">{}</div>
|
||||||
|
<div class="text-xs text-slate-500 mt-1">Config</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-center mt-4">
|
||||||
|
<span class="text-slate-500 text-xs">{}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
"##,
|
||||||
|
t.built_for_speed,
|
||||||
|
t.docker_image,
|
||||||
|
t.cold_start,
|
||||||
|
t.memory,
|
||||||
|
t.registries_count,
|
||||||
|
t.multi_arch,
|
||||||
|
t.zero_config,
|
||||||
|
t.tagline
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Format Unix timestamp as relative time
|
/// Format Unix timestamp as relative time
|
||||||
pub fn format_timestamp(ts: u64) -> String {
|
pub fn format_timestamp(ts: u64) -> String {
|
||||||
if ts == 0 {
|
if ts == 0 {
|
||||||
|
|||||||
272
nora-registry/src/ui/i18n.rs
Normal file
272
nora-registry/src/ui/i18n.rs
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
/// Internationalization support for the UI
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
pub enum Lang {
|
||||||
|
#[default]
|
||||||
|
En,
|
||||||
|
Ru,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Lang {
|
||||||
|
pub fn from_str(s: &str) -> Self {
|
||||||
|
match s.to_lowercase().as_str() {
|
||||||
|
"ru" | "rus" | "russian" => Lang::Ru,
|
||||||
|
_ => Lang::En,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn code(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Lang::En => "en",
|
||||||
|
Lang::Ru => "ru",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// All translatable strings
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub struct Translations {
|
||||||
|
// Navigation
|
||||||
|
pub nav_dashboard: &'static str,
|
||||||
|
pub nav_registries: &'static str,
|
||||||
|
|
||||||
|
// Dashboard
|
||||||
|
pub dashboard_title: &'static str,
|
||||||
|
pub dashboard_subtitle: &'static str,
|
||||||
|
pub uptime: &'static str,
|
||||||
|
|
||||||
|
// Stats
|
||||||
|
pub stat_downloads: &'static str,
|
||||||
|
pub stat_uploads: &'static str,
|
||||||
|
pub stat_artifacts: &'static str,
|
||||||
|
pub stat_cache_hit: &'static str,
|
||||||
|
pub stat_storage: &'static str,
|
||||||
|
|
||||||
|
// Registry cards
|
||||||
|
pub active: &'static str,
|
||||||
|
pub artifacts: &'static str,
|
||||||
|
pub size: &'static str,
|
||||||
|
pub downloads: &'static str,
|
||||||
|
pub uploads: &'static str,
|
||||||
|
|
||||||
|
// Mount points
|
||||||
|
pub mount_points: &'static str,
|
||||||
|
pub registry: &'static str,
|
||||||
|
pub mount_path: &'static str,
|
||||||
|
pub proxy_upstream: &'static str,
|
||||||
|
|
||||||
|
// Activity
|
||||||
|
pub recent_activity: &'static str,
|
||||||
|
pub last_n_events: &'static str,
|
||||||
|
pub time: &'static str,
|
||||||
|
pub action: &'static str,
|
||||||
|
pub artifact: &'static str,
|
||||||
|
pub source: &'static str,
|
||||||
|
pub no_activity: &'static str,
|
||||||
|
|
||||||
|
// Relative time
|
||||||
|
pub just_now: &'static str,
|
||||||
|
pub min_ago: &'static str,
|
||||||
|
pub mins_ago: &'static str,
|
||||||
|
pub hour_ago: &'static str,
|
||||||
|
pub hours_ago: &'static str,
|
||||||
|
pub day_ago: &'static str,
|
||||||
|
pub days_ago: &'static str,
|
||||||
|
|
||||||
|
// Registry pages
|
||||||
|
pub repositories: &'static str,
|
||||||
|
pub search_placeholder: &'static str,
|
||||||
|
pub no_repos_found: &'static str,
|
||||||
|
pub push_first_artifact: &'static str,
|
||||||
|
pub name: &'static str,
|
||||||
|
pub tags: &'static str,
|
||||||
|
pub versions: &'static str,
|
||||||
|
pub updated: &'static str,
|
||||||
|
|
||||||
|
// Detail pages
|
||||||
|
pub pull_command: &'static str,
|
||||||
|
pub install_command: &'static str,
|
||||||
|
pub maven_dependency: &'static str,
|
||||||
|
pub total: &'static str,
|
||||||
|
pub created: &'static str,
|
||||||
|
pub published: &'static str,
|
||||||
|
pub filename: &'static str,
|
||||||
|
pub files: &'static str,
|
||||||
|
|
||||||
|
// Bragging footer
|
||||||
|
pub built_for_speed: &'static str,
|
||||||
|
pub docker_image: &'static str,
|
||||||
|
pub cold_start: &'static str,
|
||||||
|
pub memory: &'static str,
|
||||||
|
pub registries_count: &'static str,
|
||||||
|
pub multi_arch: &'static str,
|
||||||
|
pub zero_config: &'static str,
|
||||||
|
pub tagline: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_translations(lang: Lang) -> &'static Translations {
|
||||||
|
match lang {
|
||||||
|
Lang::En => &TRANSLATIONS_EN,
|
||||||
|
Lang::Ru => &TRANSLATIONS_RU,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static TRANSLATIONS_EN: Translations = Translations {
|
||||||
|
// Navigation
|
||||||
|
nav_dashboard: "Dashboard",
|
||||||
|
nav_registries: "Registries",
|
||||||
|
|
||||||
|
// Dashboard
|
||||||
|
dashboard_title: "Dashboard",
|
||||||
|
dashboard_subtitle: "Overview of all registries",
|
||||||
|
uptime: "Uptime",
|
||||||
|
|
||||||
|
// Stats
|
||||||
|
stat_downloads: "Downloads",
|
||||||
|
stat_uploads: "Uploads",
|
||||||
|
stat_artifacts: "Artifacts",
|
||||||
|
stat_cache_hit: "Cache Hit",
|
||||||
|
stat_storage: "Storage",
|
||||||
|
|
||||||
|
// Registry cards
|
||||||
|
active: "ACTIVE",
|
||||||
|
artifacts: "Artifacts",
|
||||||
|
size: "Size",
|
||||||
|
downloads: "Downloads",
|
||||||
|
uploads: "Uploads",
|
||||||
|
|
||||||
|
// Mount points
|
||||||
|
mount_points: "Mount Points",
|
||||||
|
registry: "Registry",
|
||||||
|
mount_path: "Mount Path",
|
||||||
|
proxy_upstream: "Proxy Upstream",
|
||||||
|
|
||||||
|
// Activity
|
||||||
|
recent_activity: "Recent Activity",
|
||||||
|
last_n_events: "Last 20 events",
|
||||||
|
time: "Time",
|
||||||
|
action: "Action",
|
||||||
|
artifact: "Artifact",
|
||||||
|
source: "Source",
|
||||||
|
no_activity: "No recent activity",
|
||||||
|
|
||||||
|
// Relative time
|
||||||
|
just_now: "just now",
|
||||||
|
min_ago: "min ago",
|
||||||
|
mins_ago: "mins ago",
|
||||||
|
hour_ago: "hour ago",
|
||||||
|
hours_ago: "hours ago",
|
||||||
|
day_ago: "day ago",
|
||||||
|
days_ago: "days ago",
|
||||||
|
|
||||||
|
// Registry pages
|
||||||
|
repositories: "repositories",
|
||||||
|
search_placeholder: "Search repositories...",
|
||||||
|
no_repos_found: "No repositories found",
|
||||||
|
push_first_artifact: "Push your first artifact to see it here",
|
||||||
|
name: "Name",
|
||||||
|
tags: "Tags",
|
||||||
|
versions: "Versions",
|
||||||
|
updated: "Updated",
|
||||||
|
|
||||||
|
// Detail pages
|
||||||
|
pull_command: "Pull Command",
|
||||||
|
install_command: "Install Command",
|
||||||
|
maven_dependency: "Maven Dependency",
|
||||||
|
total: "total",
|
||||||
|
created: "Created",
|
||||||
|
published: "Published",
|
||||||
|
filename: "Filename",
|
||||||
|
files: "files",
|
||||||
|
|
||||||
|
// Bragging footer
|
||||||
|
built_for_speed: "Built for speed",
|
||||||
|
docker_image: "Docker Image",
|
||||||
|
cold_start: "Cold Start",
|
||||||
|
memory: "Memory",
|
||||||
|
registries_count: "Registries",
|
||||||
|
multi_arch: "Multi-arch",
|
||||||
|
zero_config: "Zero",
|
||||||
|
tagline: "Pure Rust. Single binary. OCI compatible.",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub static TRANSLATIONS_RU: Translations = Translations {
|
||||||
|
// Navigation
|
||||||
|
nav_dashboard: "Панель",
|
||||||
|
nav_registries: "Реестры",
|
||||||
|
|
||||||
|
// Dashboard
|
||||||
|
dashboard_title: "Панель управления",
|
||||||
|
dashboard_subtitle: "Обзор всех реестров",
|
||||||
|
uptime: "Аптайм",
|
||||||
|
|
||||||
|
// Stats
|
||||||
|
stat_downloads: "Загрузки",
|
||||||
|
stat_uploads: "Публикации",
|
||||||
|
stat_artifacts: "Артефакты",
|
||||||
|
stat_cache_hit: "Кэш",
|
||||||
|
stat_storage: "Хранилище",
|
||||||
|
|
||||||
|
// Registry cards
|
||||||
|
active: "АКТИВЕН",
|
||||||
|
artifacts: "Артефакты",
|
||||||
|
size: "Размер",
|
||||||
|
downloads: "Загрузки",
|
||||||
|
uploads: "Публикации",
|
||||||
|
|
||||||
|
// Mount points
|
||||||
|
mount_points: "Точки монтирования",
|
||||||
|
registry: "Реестр",
|
||||||
|
mount_path: "Путь",
|
||||||
|
proxy_upstream: "Прокси",
|
||||||
|
|
||||||
|
// Activity
|
||||||
|
recent_activity: "Последняя активность",
|
||||||
|
last_n_events: "Последние 20 событий",
|
||||||
|
time: "Время",
|
||||||
|
action: "Действие",
|
||||||
|
artifact: "Артефакт",
|
||||||
|
source: "Источник",
|
||||||
|
no_activity: "Нет активности",
|
||||||
|
|
||||||
|
// Relative time
|
||||||
|
just_now: "только что",
|
||||||
|
min_ago: "мин назад",
|
||||||
|
mins_ago: "мин назад",
|
||||||
|
hour_ago: "час назад",
|
||||||
|
hours_ago: "ч назад",
|
||||||
|
day_ago: "день назад",
|
||||||
|
days_ago: "дн назад",
|
||||||
|
|
||||||
|
// Registry pages
|
||||||
|
repositories: "репозиториев",
|
||||||
|
search_placeholder: "Поиск репозиториев...",
|
||||||
|
no_repos_found: "Репозитории не найдены",
|
||||||
|
push_first_artifact: "Загрузите первый артефакт, чтобы увидеть его здесь",
|
||||||
|
name: "Название",
|
||||||
|
tags: "Теги",
|
||||||
|
versions: "Версии",
|
||||||
|
updated: "Обновлено",
|
||||||
|
|
||||||
|
// Detail pages
|
||||||
|
pull_command: "Команда загрузки",
|
||||||
|
install_command: "Команда установки",
|
||||||
|
maven_dependency: "Maven зависимость",
|
||||||
|
total: "всего",
|
||||||
|
created: "Создан",
|
||||||
|
published: "Опубликован",
|
||||||
|
filename: "Файл",
|
||||||
|
files: "файлов",
|
||||||
|
|
||||||
|
// Bragging footer
|
||||||
|
built_for_speed: "Создан для скорости",
|
||||||
|
docker_image: "Docker образ",
|
||||||
|
cold_start: "Холодный старт",
|
||||||
|
memory: "Память",
|
||||||
|
registries_count: "Реестров",
|
||||||
|
multi_arch: "Мульти-арх",
|
||||||
|
zero_config: "Без",
|
||||||
|
tagline: "Чистый Rust. Один бинарник. OCI совместимый.",
|
||||||
|
};
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
mod api;
|
mod api;
|
||||||
mod components;
|
mod components;
|
||||||
|
pub mod i18n;
|
||||||
mod logo;
|
mod logo;
|
||||||
mod templates;
|
mod templates;
|
||||||
|
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, State},
|
extract::{Path, Query, State},
|
||||||
response::{Html, IntoResponse, Redirect},
|
response::{Html, IntoResponse, Redirect},
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
@@ -13,8 +14,33 @@ use axum::{
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use api::*;
|
use api::*;
|
||||||
|
use i18n::Lang;
|
||||||
use templates::*;
|
use templates::*;
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
struct LangQuery {
|
||||||
|
lang: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_lang(query: &Query<LangQuery>, cookie_header: Option<&str>) -> Lang {
|
||||||
|
// Priority: query param > cookie > default
|
||||||
|
if let Some(ref lang) = query.lang {
|
||||||
|
return Lang::from_str(lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try cookie
|
||||||
|
if let Some(cookies) = cookie_header {
|
||||||
|
for part in cookies.split(';') {
|
||||||
|
let part = part.trim();
|
||||||
|
if let Some(value) = part.strip_prefix("nora_lang=") {
|
||||||
|
return Lang::from_str(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Lang::default()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn routes() -> Router<Arc<AppState>> {
|
pub fn routes() -> Router<Arc<AppState>> {
|
||||||
Router::new()
|
Router::new()
|
||||||
// UI Pages
|
// UI Pages
|
||||||
@@ -33,83 +59,182 @@ pub fn routes() -> Router<Arc<AppState>> {
|
|||||||
.route("/ui/pypi/{name}", get(pypi_detail))
|
.route("/ui/pypi/{name}", get(pypi_detail))
|
||||||
// API endpoints for HTMX
|
// API endpoints for HTMX
|
||||||
.route("/api/ui/stats", get(api_stats))
|
.route("/api/ui/stats", get(api_stats))
|
||||||
|
.route("/api/ui/dashboard", get(api_dashboard))
|
||||||
.route("/api/ui/{registry_type}/list", get(api_list))
|
.route("/api/ui/{registry_type}/list", get(api_list))
|
||||||
.route("/api/ui/{registry_type}/{name}", get(api_detail))
|
.route("/api/ui/{registry_type}/{name}", get(api_detail))
|
||||||
.route("/api/ui/{registry_type}/search", get(api_search))
|
.route("/api/ui/{registry_type}/search", get(api_search))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dashboard page
|
// Dashboard page
|
||||||
async fn dashboard(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
async fn dashboard(
|
||||||
let stats = get_registry_stats(&state.storage).await;
|
State(state): State<Arc<AppState>>,
|
||||||
Html(render_dashboard(&stats))
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
|
let response = api_dashboard(State(state)).await.0;
|
||||||
|
Html(render_dashboard(&response, lang))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Docker pages
|
// Docker pages
|
||||||
async fn docker_list(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
async fn docker_list(
|
||||||
|
State(state): State<Arc<AppState>>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
let repos = get_docker_repos(&state.storage).await;
|
let repos = get_docker_repos(&state.storage).await;
|
||||||
Html(render_registry_list("docker", "Docker Registry", &repos))
|
Html(render_registry_list(
|
||||||
|
"docker",
|
||||||
|
"Docker Registry",
|
||||||
|
&repos,
|
||||||
|
lang,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn docker_detail(
|
async fn docker_detail(
|
||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
Path(name): Path<String>,
|
Path(name): Path<String>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let detail = get_docker_detail(&state.storage, &name).await;
|
let lang = extract_lang(
|
||||||
Html(render_docker_detail(&name, &detail))
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
|
let detail = get_docker_detail(&state, &name).await;
|
||||||
|
Html(render_docker_detail(&name, &detail, lang))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maven pages
|
// Maven pages
|
||||||
async fn maven_list(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
async fn maven_list(
|
||||||
|
State(state): State<Arc<AppState>>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
let repos = get_maven_repos(&state.storage).await;
|
let repos = get_maven_repos(&state.storage).await;
|
||||||
Html(render_registry_list("maven", "Maven Repository", &repos))
|
Html(render_registry_list(
|
||||||
|
"maven",
|
||||||
|
"Maven Repository",
|
||||||
|
&repos,
|
||||||
|
lang,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn maven_detail(
|
async fn maven_detail(
|
||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
Path(path): Path<String>,
|
Path(path): Path<String>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
let detail = get_maven_detail(&state.storage, &path).await;
|
let detail = get_maven_detail(&state.storage, &path).await;
|
||||||
Html(render_maven_detail(&path, &detail))
|
Html(render_maven_detail(&path, &detail, lang))
|
||||||
}
|
}
|
||||||
|
|
||||||
// npm pages
|
// npm pages
|
||||||
async fn npm_list(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
async fn npm_list(
|
||||||
|
State(state): State<Arc<AppState>>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
let packages = get_npm_packages(&state.storage).await;
|
let packages = get_npm_packages(&state.storage).await;
|
||||||
Html(render_registry_list("npm", "npm Registry", &packages))
|
Html(render_registry_list("npm", "npm Registry", &packages, lang))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn npm_detail(
|
async fn npm_detail(
|
||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
Path(name): Path<String>,
|
Path(name): Path<String>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
let detail = get_npm_detail(&state.storage, &name).await;
|
let detail = get_npm_detail(&state.storage, &name).await;
|
||||||
Html(render_package_detail("npm", &name, &detail))
|
Html(render_package_detail("npm", &name, &detail, lang))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cargo pages
|
// Cargo pages
|
||||||
async fn cargo_list(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
async fn cargo_list(
|
||||||
|
State(state): State<Arc<AppState>>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
let crates = get_cargo_crates(&state.storage).await;
|
let crates = get_cargo_crates(&state.storage).await;
|
||||||
Html(render_registry_list("cargo", "Cargo Registry", &crates))
|
Html(render_registry_list(
|
||||||
|
"cargo",
|
||||||
|
"Cargo Registry",
|
||||||
|
&crates,
|
||||||
|
lang,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cargo_detail(
|
async fn cargo_detail(
|
||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
Path(name): Path<String>,
|
Path(name): Path<String>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
let detail = get_cargo_detail(&state.storage, &name).await;
|
let detail = get_cargo_detail(&state.storage, &name).await;
|
||||||
Html(render_package_detail("cargo", &name, &detail))
|
Html(render_package_detail("cargo", &name, &detail, lang))
|
||||||
}
|
}
|
||||||
|
|
||||||
// PyPI pages
|
// PyPI pages
|
||||||
async fn pypi_list(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
async fn pypi_list(
|
||||||
|
State(state): State<Arc<AppState>>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
let packages = get_pypi_packages(&state.storage).await;
|
let packages = get_pypi_packages(&state.storage).await;
|
||||||
Html(render_registry_list("pypi", "PyPI Repository", &packages))
|
Html(render_registry_list(
|
||||||
|
"pypi",
|
||||||
|
"PyPI Repository",
|
||||||
|
&packages,
|
||||||
|
lang,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn pypi_detail(
|
async fn pypi_detail(
|
||||||
State(state): State<Arc<AppState>>,
|
State(state): State<Arc<AppState>>,
|
||||||
Path(name): Path<String>,
|
Path(name): Path<String>,
|
||||||
|
Query(query): Query<LangQuery>,
|
||||||
|
headers: axum::http::HeaderMap,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
|
let lang = extract_lang(
|
||||||
|
&Query(query),
|
||||||
|
headers.get("cookie").and_then(|v| v.to_str().ok()),
|
||||||
|
);
|
||||||
let detail = get_pypi_detail(&state.storage, &name).await;
|
let detail = get_pypi_detail(&state.storage, &name).await;
|
||||||
Html(render_package_detail("pypi", &name, &detail))
|
Html(render_package_detail("pypi", &name, &detail, lang))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,91 +1,186 @@
|
|||||||
use super::api::{DockerDetail, MavenDetail, PackageDetail, RegistryStats, RepoInfo};
|
use super::api::{DashboardResponse, DockerDetail, MavenDetail, PackageDetail, RepoInfo};
|
||||||
use super::components::*;
|
use super::components::*;
|
||||||
|
use super::i18n::{get_translations, Lang};
|
||||||
|
|
||||||
/// Renders the main dashboard page
|
/// Renders the main dashboard page with dark theme
|
||||||
pub fn render_dashboard(stats: &RegistryStats) -> String {
|
pub fn render_dashboard(data: &DashboardResponse, lang: Lang) -> String {
|
||||||
let content = format!(
|
let t = get_translations(lang);
|
||||||
r##"
|
// Render global stats
|
||||||
<div class="mb-8">
|
let global_stats = render_global_stats(
|
||||||
<h1 class="text-2xl font-bold text-slate-800 mb-2">Dashboard</h1>
|
data.global_stats.downloads,
|
||||||
<p class="text-slate-500">Overview of all registries</p>
|
data.global_stats.uploads,
|
||||||
</div>
|
data.global_stats.artifacts,
|
||||||
|
data.global_stats.cache_hit_percent,
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 gap-6 mb-8">
|
data.global_stats.storage_bytes,
|
||||||
{}
|
lang,
|
||||||
{}
|
|
||||||
{}
|
|
||||||
{}
|
|
||||||
{}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-sm border border-slate-200 p-6">
|
|
||||||
<h2 class="text-lg font-semibold text-slate-800 mb-4">Quick Links</h2>
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
||||||
<a href="/ui/docker" class="flex items-center p-3 rounded-lg border border-slate-200 hover:border-blue-300 hover:bg-blue-50 transition-colors">
|
|
||||||
<svg class="w-8 h-8 mr-3 text-slate-600" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
|
||||||
<div>
|
|
||||||
<div class="font-medium text-slate-700">Docker Registry</div>
|
|
||||||
<div class="text-sm text-slate-500">API: /v2/</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<a href="/ui/maven" class="flex items-center p-3 rounded-lg border border-slate-200 hover:border-blue-300 hover:bg-blue-50 transition-colors">
|
|
||||||
<svg class="w-8 h-8 mr-3 text-slate-600" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
|
||||||
<div>
|
|
||||||
<div class="font-medium text-slate-700">Maven Repository</div>
|
|
||||||
<div class="text-sm text-slate-500">API: /maven2/</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<a href="/ui/npm" class="flex items-center p-3 rounded-lg border border-slate-200 hover:border-blue-300 hover:bg-blue-50 transition-colors">
|
|
||||||
<svg class="w-8 h-8 mr-3 text-slate-600" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
|
||||||
<div>
|
|
||||||
<div class="font-medium text-slate-700">npm Registry</div>
|
|
||||||
<div class="text-sm text-slate-500">API: /npm/</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<a href="/ui/cargo" class="flex items-center p-3 rounded-lg border border-slate-200 hover:border-blue-300 hover:bg-blue-50 transition-colors">
|
|
||||||
<svg class="w-8 h-8 mr-3 text-slate-600" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
|
||||||
<div>
|
|
||||||
<div class="font-medium text-slate-700">Cargo Registry</div>
|
|
||||||
<div class="text-sm text-slate-500">API: /cargo/</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
<a href="/ui/pypi" class="flex items-center p-3 rounded-lg border border-slate-200 hover:border-blue-300 hover:bg-blue-50 transition-colors">
|
|
||||||
<svg class="w-8 h-8 mr-3 text-slate-600" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
|
||||||
<div>
|
|
||||||
<div class="font-medium text-slate-700">PyPI Repository</div>
|
|
||||||
<div class="text-sm text-slate-500">API: /simple/</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
"##,
|
|
||||||
stat_card("Docker", icons::DOCKER, stats.docker, "/ui/docker", "images"),
|
|
||||||
stat_card("Maven", icons::MAVEN, stats.maven, "/ui/maven", "artifacts"),
|
|
||||||
stat_card("npm", icons::NPM, stats.npm, "/ui/npm", "packages"),
|
|
||||||
stat_card("Cargo", icons::CARGO, stats.cargo, "/ui/cargo", "crates"),
|
|
||||||
stat_card("PyPI", icons::PYPI, stats.pypi, "/ui/pypi", "packages"),
|
|
||||||
// Quick Links icons
|
|
||||||
icons::DOCKER,
|
|
||||||
icons::MAVEN,
|
|
||||||
icons::NPM,
|
|
||||||
icons::CARGO,
|
|
||||||
icons::PYPI,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
layout("Dashboard", &content, Some("dashboard"))
|
// Render registry cards
|
||||||
|
let registry_cards: String = data
|
||||||
|
.registry_stats
|
||||||
|
.iter()
|
||||||
|
.map(|r| {
|
||||||
|
let icon = match r.name.as_str() {
|
||||||
|
"docker" => icons::DOCKER,
|
||||||
|
"maven" => icons::MAVEN,
|
||||||
|
"npm" => icons::NPM,
|
||||||
|
"cargo" => icons::CARGO,
|
||||||
|
"pypi" => icons::PYPI,
|
||||||
|
_ => icons::DOCKER,
|
||||||
|
};
|
||||||
|
let display_name = match r.name.as_str() {
|
||||||
|
"docker" => "Docker",
|
||||||
|
"maven" => "Maven",
|
||||||
|
"npm" => "npm",
|
||||||
|
"cargo" => "Cargo",
|
||||||
|
"pypi" => "PyPI",
|
||||||
|
_ => &r.name,
|
||||||
|
};
|
||||||
|
render_registry_card(
|
||||||
|
display_name,
|
||||||
|
icon,
|
||||||
|
r.artifact_count,
|
||||||
|
r.downloads,
|
||||||
|
r.uploads,
|
||||||
|
r.size_bytes,
|
||||||
|
&format!("/ui/{}", r.name),
|
||||||
|
t,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Render mount points
|
||||||
|
let mount_data: Vec<(String, String, Option<String>)> = data
|
||||||
|
.mount_points
|
||||||
|
.iter()
|
||||||
|
.map(|m| {
|
||||||
|
(
|
||||||
|
m.registry.clone(),
|
||||||
|
m.mount_path.clone(),
|
||||||
|
m.proxy_upstream.clone(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let mount_points = render_mount_points_table(&mount_data, t);
|
||||||
|
|
||||||
|
// Render activity log
|
||||||
|
let activity_rows: String = if data.activity.is_empty() {
|
||||||
|
format!(
|
||||||
|
r##"<tr><td colspan="5" class="py-8 text-center text-slate-500">{}</td></tr>"##,
|
||||||
|
t.no_activity
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
data.activity
|
||||||
|
.iter()
|
||||||
|
.map(|entry| {
|
||||||
|
let time_ago = format_relative_time(&entry.timestamp);
|
||||||
|
render_activity_row(
|
||||||
|
&time_ago,
|
||||||
|
&entry.action.to_string(),
|
||||||
|
&entry.artifact,
|
||||||
|
&entry.registry,
|
||||||
|
&entry.source,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
let activity_log = render_activity_log(&activity_rows, t);
|
||||||
|
|
||||||
|
// Format uptime
|
||||||
|
let hours = data.uptime_seconds / 3600;
|
||||||
|
let mins = (data.uptime_seconds % 3600) / 60;
|
||||||
|
let uptime_str = format!("{}h {}m", hours, mins);
|
||||||
|
|
||||||
|
// Render bragging footer
|
||||||
|
let bragging_footer = render_bragging_footer(lang);
|
||||||
|
|
||||||
|
let content = format!(
|
||||||
|
r##"
|
||||||
|
<div class="mb-6">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<div>
|
||||||
|
<h1 class="text-2xl font-bold text-slate-200 mb-1">{}</h1>
|
||||||
|
<p class="text-slate-400">{}</p>
|
||||||
|
</div>
|
||||||
|
<div class="text-right">
|
||||||
|
<div class="text-sm text-slate-500">{}</div>
|
||||||
|
<div id="uptime" class="text-lg font-semibold text-slate-300">{}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{}
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5 gap-4 mb-6">
|
||||||
|
{}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
|
||||||
|
{}
|
||||||
|
{}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{}
|
||||||
|
"##,
|
||||||
|
t.dashboard_title,
|
||||||
|
t.dashboard_subtitle,
|
||||||
|
t.uptime,
|
||||||
|
uptime_str,
|
||||||
|
global_stats,
|
||||||
|
registry_cards,
|
||||||
|
mount_points,
|
||||||
|
activity_log,
|
||||||
|
bragging_footer,
|
||||||
|
);
|
||||||
|
|
||||||
|
let polling_script = render_polling_script();
|
||||||
|
layout_dark(
|
||||||
|
t.dashboard_title,
|
||||||
|
&content,
|
||||||
|
Some("dashboard"),
|
||||||
|
&polling_script,
|
||||||
|
lang,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Format timestamp as relative time (e.g., "2 min ago")
|
||||||
|
fn format_relative_time(timestamp: &chrono::DateTime<chrono::Utc>) -> String {
|
||||||
|
let now = chrono::Utc::now();
|
||||||
|
let diff = now.signed_duration_since(*timestamp);
|
||||||
|
|
||||||
|
if diff.num_seconds() < 60 {
|
||||||
|
"just now".to_string()
|
||||||
|
} else if diff.num_minutes() < 60 {
|
||||||
|
let mins = diff.num_minutes();
|
||||||
|
format!("{} min{} ago", mins, if mins == 1 { "" } else { "s" })
|
||||||
|
} else if diff.num_hours() < 24 {
|
||||||
|
let hours = diff.num_hours();
|
||||||
|
format!("{} hour{} ago", hours, if hours == 1 { "" } else { "s" })
|
||||||
|
} else {
|
||||||
|
let days = diff.num_days();
|
||||||
|
format!("{} day{} ago", days, if days == 1 { "" } else { "s" })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Renders a registry list page (docker, maven, npm, cargo, pypi)
|
/// Renders a registry list page (docker, maven, npm, cargo, pypi)
|
||||||
pub fn render_registry_list(registry_type: &str, title: &str, repos: &[RepoInfo]) -> String {
|
pub fn render_registry_list(
|
||||||
|
registry_type: &str,
|
||||||
|
title: &str,
|
||||||
|
repos: &[RepoInfo],
|
||||||
|
lang: Lang,
|
||||||
|
) -> String {
|
||||||
|
let t = get_translations(lang);
|
||||||
let icon = get_registry_icon(registry_type);
|
let icon = get_registry_icon(registry_type);
|
||||||
|
|
||||||
let table_rows = if repos.is_empty() {
|
let table_rows = if repos.is_empty() {
|
||||||
|
format!(
|
||||||
r##"<tr><td colspan="4" class="px-6 py-12 text-center text-slate-500">
|
r##"<tr><td colspan="4" class="px-6 py-12 text-center text-slate-500">
|
||||||
<div class="text-4xl mb-2">📭</div>
|
<div class="text-4xl mb-2">📭</div>
|
||||||
<div>No repositories found</div>
|
<div>{}</div>
|
||||||
<div class="text-sm mt-1">Push your first artifact to see it here</div>
|
<div class="text-sm mt-1">{}</div>
|
||||||
</td></tr>"##
|
</td></tr>"##,
|
||||||
.to_string()
|
t.no_repos_found, t.push_first_artifact
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
repos
|
repos
|
||||||
.iter()
|
.iter()
|
||||||
@@ -94,12 +189,12 @@ pub fn render_registry_list(registry_type: &str, title: &str, repos: &[RepoInfo]
|
|||||||
format!("/ui/{}/{}", registry_type, encode_uri_component(&repo.name));
|
format!("/ui/{}/{}", registry_type, encode_uri_component(&repo.name));
|
||||||
format!(
|
format!(
|
||||||
r##"
|
r##"
|
||||||
<tr class="hover:bg-slate-50 cursor-pointer" onclick="window.location='{}'">
|
<tr class="hover:bg-slate-700 cursor-pointer" onclick="window.location='{}'">
|
||||||
<td class="px-6 py-4">
|
<td class="px-6 py-4">
|
||||||
<a href="{}" class="text-blue-600 hover:text-blue-800 font-medium">{}</a>
|
<a href="{}" class="text-blue-400 hover:text-blue-300 font-medium">{}</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 text-slate-600">{}</td>
|
<td class="px-6 py-4 text-slate-400">{}</td>
|
||||||
<td class="px-6 py-4 text-slate-600">{}</td>
|
<td class="px-6 py-4 text-slate-400">{}</td>
|
||||||
<td class="px-6 py-4 text-slate-500 text-sm">{}</td>
|
<td class="px-6 py-4 text-slate-500 text-sm">{}</td>
|
||||||
</tr>
|
</tr>
|
||||||
"##,
|
"##,
|
||||||
@@ -116,48 +211,47 @@ pub fn render_registry_list(registry_type: &str, title: &str, repos: &[RepoInfo]
|
|||||||
};
|
};
|
||||||
|
|
||||||
let version_label = match registry_type {
|
let version_label = match registry_type {
|
||||||
"docker" => "Tags",
|
"docker" => t.tags,
|
||||||
"maven" => "Versions",
|
_ => t.versions,
|
||||||
_ => "Versions",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let content = format!(
|
let content = format!(
|
||||||
r##"
|
r##"
|
||||||
<div class="mb-6 flex items-center justify-between">
|
<div class="mb-6 flex items-center justify-between">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<svg class="w-10 h-10 mr-3 text-slate-600" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
<svg class="w-10 h-10 mr-3 text-slate-400" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
||||||
<div>
|
<div>
|
||||||
<h1 class="text-2xl font-bold text-slate-800">{}</h1>
|
<h1 class="text-2xl font-bold text-slate-200">{}</h1>
|
||||||
<p class="text-slate-500">{} repositories</p>
|
<p class="text-slate-500">{} {}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-4">
|
<div class="flex items-center gap-4">
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<input type="text"
|
<input type="text"
|
||||||
placeholder="Search repositories..."
|
placeholder="{}"
|
||||||
class="pl-10 pr-4 py-2 border border-slate-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
class="pl-10 pr-4 py-2 bg-slate-800 border border-slate-600 text-slate-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent placeholder-slate-500"
|
||||||
hx-get="/api/ui/{}/search"
|
hx-get="/api/ui/{}/search"
|
||||||
hx-trigger="keyup changed delay:300ms"
|
hx-trigger="keyup changed delay:300ms"
|
||||||
hx-target="#repo-table-body"
|
hx-target="#repo-table-body"
|
||||||
name="q">
|
name="q">
|
||||||
<svg class="absolute left-3 top-2.5 h-5 w-5 text-slate-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg class="absolute left-3 top-2.5 h-5 w-5 text-slate-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-sm border border-slate-200 overflow-hidden">
|
<div class="bg-[#1e293b] rounded-lg shadow-sm border border-slate-700 overflow-hidden">
|
||||||
<table class="w-full">
|
<table class="w-full">
|
||||||
<thead class="bg-slate-50 border-b border-slate-200">
|
<thead class="bg-slate-800 border-b border-slate-700">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Name</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">{}</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">{}</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">{}</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Size</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">{}</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Updated</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">{}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="repo-table-body" class="divide-y divide-slate-200">
|
<tbody id="repo-table-body" class="divide-y divide-slate-700">
|
||||||
{}
|
{}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -166,16 +260,22 @@ pub fn render_registry_list(registry_type: &str, title: &str, repos: &[RepoInfo]
|
|||||||
icon,
|
icon,
|
||||||
title,
|
title,
|
||||||
repos.len(),
|
repos.len(),
|
||||||
|
t.repositories,
|
||||||
|
t.search_placeholder,
|
||||||
registry_type,
|
registry_type,
|
||||||
|
t.name,
|
||||||
version_label,
|
version_label,
|
||||||
|
t.size,
|
||||||
|
t.updated,
|
||||||
table_rows
|
table_rows
|
||||||
);
|
);
|
||||||
|
|
||||||
layout(title, &content, Some(registry_type))
|
layout_dark(title, &content, Some(registry_type), "", lang)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Renders Docker image detail page
|
/// Renders Docker image detail page
|
||||||
pub fn render_docker_detail(name: &str, detail: &DockerDetail) -> String {
|
pub fn render_docker_detail(name: &str, detail: &DockerDetail, lang: Lang) -> String {
|
||||||
|
let _t = get_translations(lang);
|
||||||
let tags_rows = if detail.tags.is_empty() {
|
let tags_rows = if detail.tags.is_empty() {
|
||||||
r##"<tr><td colspan="3" class="px-6 py-8 text-center text-slate-500">No tags found</td></tr>"##.to_string()
|
r##"<tr><td colspan="3" class="px-6 py-8 text-center text-slate-500">No tags found</td></tr>"##.to_string()
|
||||||
} else {
|
} else {
|
||||||
@@ -185,11 +285,11 @@ pub fn render_docker_detail(name: &str, detail: &DockerDetail) -> String {
|
|||||||
.map(|tag| {
|
.map(|tag| {
|
||||||
format!(
|
format!(
|
||||||
r##"
|
r##"
|
||||||
<tr class="hover:bg-slate-50">
|
<tr class="hover:bg-slate-700">
|
||||||
<td class="px-6 py-4">
|
<td class="px-6 py-4">
|
||||||
<span class="font-mono text-sm bg-slate-100 px-2 py-1 rounded">{}</span>
|
<span class="font-mono text-sm bg-slate-700 text-slate-200 px-2 py-1 rounded">{}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 text-slate-600">{}</td>
|
<td class="px-6 py-4 text-slate-400">{}</td>
|
||||||
<td class="px-6 py-4 text-slate-500 text-sm">{}</td>
|
<td class="px-6 py-4 text-slate-500 text-sm">{}</td>
|
||||||
</tr>
|
</tr>
|
||||||
"##,
|
"##,
|
||||||
@@ -208,18 +308,18 @@ pub fn render_docker_detail(name: &str, detail: &DockerDetail) -> String {
|
|||||||
r##"
|
r##"
|
||||||
<div class="mb-6">
|
<div class="mb-6">
|
||||||
<div class="flex items-center mb-2">
|
<div class="flex items-center mb-2">
|
||||||
<a href="/ui/docker" class="text-blue-600 hover:text-blue-800">Docker Registry</a>
|
<a href="/ui/docker" class="text-blue-400 hover:text-blue-300">Docker Registry</a>
|
||||||
<span class="mx-2 text-slate-400">/</span>
|
<span class="mx-2 text-slate-500">/</span>
|
||||||
<span class="text-slate-800 font-medium">{}</span>
|
<span class="text-slate-200 font-medium">{}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<svg class="w-10 h-10 mr-3 text-slate-600" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
<svg class="w-10 h-10 mr-3 text-slate-400" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
||||||
<h1 class="text-2xl font-bold text-slate-800">{}</h1>
|
<h1 class="text-2xl font-bold text-slate-200">{}</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-sm border border-slate-200 p-6 mb-6">
|
<div class="bg-[#1e293b] rounded-lg shadow-sm border border-slate-700 p-6 mb-6">
|
||||||
<h2 class="text-lg font-semibold text-slate-800 mb-3">Pull Command</h2>
|
<h2 class="text-lg font-semibold text-slate-200 mb-3">Pull Command</h2>
|
||||||
<div class="flex items-center bg-slate-900 text-green-400 rounded-lg p-4 font-mono text-sm">
|
<div class="flex items-center bg-slate-900 text-green-400 rounded-lg p-4 font-mono text-sm">
|
||||||
<code class="flex-1">{}</code>
|
<code class="flex-1">{}</code>
|
||||||
<button onclick="navigator.clipboard.writeText('{}')" class="ml-4 text-slate-400 hover:text-white transition-colors" title="Copy to clipboard">
|
<button onclick="navigator.clipboard.writeText('{}')" class="ml-4 text-slate-400 hover:text-white transition-colors" title="Copy to clipboard">
|
||||||
@@ -230,19 +330,19 @@ pub fn render_docker_detail(name: &str, detail: &DockerDetail) -> String {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-sm border border-slate-200 overflow-hidden">
|
<div class="bg-[#1e293b] rounded-lg shadow-sm border border-slate-700 overflow-hidden">
|
||||||
<div class="px-6 py-4 border-b border-slate-200">
|
<div class="px-6 py-4 border-b border-slate-700">
|
||||||
<h2 class="text-lg font-semibold text-slate-800">Tags ({} total)</h2>
|
<h2 class="text-lg font-semibold text-slate-200">Tags ({} total)</h2>
|
||||||
</div>
|
</div>
|
||||||
<table class="w-full">
|
<table class="w-full">
|
||||||
<thead class="bg-slate-50 border-b border-slate-200">
|
<thead class="bg-slate-800 border-b border-slate-700">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Tag</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">Tag</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Size</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">Size</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Created</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">Created</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="divide-y divide-slate-200">
|
<tbody class="divide-y divide-slate-700">
|
||||||
{}
|
{}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -257,11 +357,23 @@ pub fn render_docker_detail(name: &str, detail: &DockerDetail) -> String {
|
|||||||
tags_rows
|
tags_rows
|
||||||
);
|
);
|
||||||
|
|
||||||
layout(&format!("{} - Docker", name), &content, Some("docker"))
|
layout_dark(
|
||||||
|
&format!("{} - Docker", name),
|
||||||
|
&content,
|
||||||
|
Some("docker"),
|
||||||
|
"",
|
||||||
|
lang,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Renders package detail page (npm, cargo, pypi)
|
/// Renders package detail page (npm, cargo, pypi)
|
||||||
pub fn render_package_detail(registry_type: &str, name: &str, detail: &PackageDetail) -> String {
|
pub fn render_package_detail(
|
||||||
|
registry_type: &str,
|
||||||
|
name: &str,
|
||||||
|
detail: &PackageDetail,
|
||||||
|
lang: Lang,
|
||||||
|
) -> String {
|
||||||
|
let _t = get_translations(lang);
|
||||||
let icon = get_registry_icon(registry_type);
|
let icon = get_registry_icon(registry_type);
|
||||||
let registry_title = get_registry_title(registry_type);
|
let registry_title = get_registry_title(registry_type);
|
||||||
|
|
||||||
@@ -274,11 +386,11 @@ pub fn render_package_detail(registry_type: &str, name: &str, detail: &PackageDe
|
|||||||
.map(|v| {
|
.map(|v| {
|
||||||
format!(
|
format!(
|
||||||
r##"
|
r##"
|
||||||
<tr class="hover:bg-slate-50">
|
<tr class="hover:bg-slate-700">
|
||||||
<td class="px-6 py-4">
|
<td class="px-6 py-4">
|
||||||
<span class="font-mono text-sm bg-slate-100 px-2 py-1 rounded">{}</span>
|
<span class="font-mono text-sm bg-slate-700 text-slate-200 px-2 py-1 rounded">{}</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 text-slate-600">{}</td>
|
<td class="px-6 py-4 text-slate-400">{}</td>
|
||||||
<td class="px-6 py-4 text-slate-500 text-sm">{}</td>
|
<td class="px-6 py-4 text-slate-500 text-sm">{}</td>
|
||||||
</tr>
|
</tr>
|
||||||
"##,
|
"##,
|
||||||
@@ -305,18 +417,18 @@ pub fn render_package_detail(registry_type: &str, name: &str, detail: &PackageDe
|
|||||||
r##"
|
r##"
|
||||||
<div class="mb-6">
|
<div class="mb-6">
|
||||||
<div class="flex items-center mb-2">
|
<div class="flex items-center mb-2">
|
||||||
<a href="/ui/{}" class="text-blue-600 hover:text-blue-800">{}</a>
|
<a href="/ui/{}" class="text-blue-400 hover:text-blue-300">{}</a>
|
||||||
<span class="mx-2 text-slate-400">/</span>
|
<span class="mx-2 text-slate-500">/</span>
|
||||||
<span class="text-slate-800 font-medium">{}</span>
|
<span class="text-slate-200 font-medium">{}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<svg class="w-10 h-10 mr-3 text-slate-600" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
<svg class="w-10 h-10 mr-3 text-slate-400" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
||||||
<h1 class="text-2xl font-bold text-slate-800">{}</h1>
|
<h1 class="text-2xl font-bold text-slate-200">{}</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-sm border border-slate-200 p-6 mb-6">
|
<div class="bg-[#1e293b] rounded-lg shadow-sm border border-slate-700 p-6 mb-6">
|
||||||
<h2 class="text-lg font-semibold text-slate-800 mb-3">Install Command</h2>
|
<h2 class="text-lg font-semibold text-slate-200 mb-3">Install Command</h2>
|
||||||
<div class="flex items-center bg-slate-900 text-green-400 rounded-lg p-4 font-mono text-sm">
|
<div class="flex items-center bg-slate-900 text-green-400 rounded-lg p-4 font-mono text-sm">
|
||||||
<code class="flex-1">{}</code>
|
<code class="flex-1">{}</code>
|
||||||
<button onclick="navigator.clipboard.writeText('{}')" class="ml-4 text-slate-400 hover:text-white transition-colors" title="Copy to clipboard">
|
<button onclick="navigator.clipboard.writeText('{}')" class="ml-4 text-slate-400 hover:text-white transition-colors" title="Copy to clipboard">
|
||||||
@@ -327,19 +439,19 @@ pub fn render_package_detail(registry_type: &str, name: &str, detail: &PackageDe
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-sm border border-slate-200 overflow-hidden">
|
<div class="bg-[#1e293b] rounded-lg shadow-sm border border-slate-700 overflow-hidden">
|
||||||
<div class="px-6 py-4 border-b border-slate-200">
|
<div class="px-6 py-4 border-b border-slate-700">
|
||||||
<h2 class="text-lg font-semibold text-slate-800">Versions ({} total)</h2>
|
<h2 class="text-lg font-semibold text-slate-200">Versions ({} total)</h2>
|
||||||
</div>
|
</div>
|
||||||
<table class="w-full">
|
<table class="w-full">
|
||||||
<thead class="bg-slate-50 border-b border-slate-200">
|
<thead class="bg-slate-800 border-b border-slate-700">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Version</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">Version</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Size</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">Size</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Published</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">Published</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="divide-y divide-slate-200">
|
<tbody class="divide-y divide-slate-700">
|
||||||
{}
|
{}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -356,26 +468,29 @@ pub fn render_package_detail(registry_type: &str, name: &str, detail: &PackageDe
|
|||||||
versions_rows
|
versions_rows
|
||||||
);
|
);
|
||||||
|
|
||||||
layout(
|
layout_dark(
|
||||||
&format!("{} - {}", name, registry_title),
|
&format!("{} - {}", name, registry_title),
|
||||||
&content,
|
&content,
|
||||||
Some(registry_type),
|
Some(registry_type),
|
||||||
|
"",
|
||||||
|
lang,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Renders Maven artifact detail page
|
/// Renders Maven artifact detail page
|
||||||
pub fn render_maven_detail(path: &str, detail: &MavenDetail) -> String {
|
pub fn render_maven_detail(path: &str, detail: &MavenDetail, lang: Lang) -> String {
|
||||||
|
let _t = get_translations(lang);
|
||||||
let artifact_rows = if detail.artifacts.is_empty() {
|
let artifact_rows = if detail.artifacts.is_empty() {
|
||||||
r##"<tr><td colspan="2" class="px-6 py-8 text-center text-slate-500">No artifacts found</td></tr>"##.to_string()
|
r##"<tr><td colspan="2" class="px-6 py-8 text-center text-slate-500">No artifacts found</td></tr>"##.to_string()
|
||||||
} else {
|
} else {
|
||||||
detail.artifacts.iter().map(|a| {
|
detail.artifacts.iter().map(|a| {
|
||||||
let download_url = format!("/maven2/{}/{}", path, a.filename);
|
let download_url = format!("/maven2/{}/{}", path, a.filename);
|
||||||
format!(r##"
|
format!(r##"
|
||||||
<tr class="hover:bg-slate-50">
|
<tr class="hover:bg-slate-700">
|
||||||
<td class="px-6 py-4">
|
<td class="px-6 py-4">
|
||||||
<a href="{}" class="text-blue-600 hover:text-blue-800 font-mono text-sm">{}</a>
|
<a href="{}" class="text-blue-400 hover:text-blue-300 font-mono text-sm">{}</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 text-slate-600">{}</td>
|
<td class="px-6 py-4 text-slate-400">{}</td>
|
||||||
</tr>
|
</tr>
|
||||||
"##, download_url, html_escape(&a.filename), format_size(a.size))
|
"##, download_url, html_escape(&a.filename), format_size(a.size))
|
||||||
}).collect::<Vec<_>>().join("")
|
}).collect::<Vec<_>>().join("")
|
||||||
@@ -404,33 +519,33 @@ pub fn render_maven_detail(path: &str, detail: &MavenDetail) -> String {
|
|||||||
r##"
|
r##"
|
||||||
<div class="mb-6">
|
<div class="mb-6">
|
||||||
<div class="flex items-center mb-2">
|
<div class="flex items-center mb-2">
|
||||||
<a href="/ui/maven" class="text-blue-600 hover:text-blue-800">Maven Repository</a>
|
<a href="/ui/maven" class="text-blue-400 hover:text-blue-300">Maven Repository</a>
|
||||||
<span class="mx-2 text-slate-400">/</span>
|
<span class="mx-2 text-slate-500">/</span>
|
||||||
<span class="text-slate-800 font-medium">{}</span>
|
<span class="text-slate-200 font-medium">{}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<svg class="w-10 h-10 mr-3 text-slate-600" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
<svg class="w-10 h-10 mr-3 text-slate-400" fill="currentColor" viewBox="0 0 24 24">{}</svg>
|
||||||
<h1 class="text-2xl font-bold text-slate-800">{}</h1>
|
<h1 class="text-2xl font-bold text-slate-200">{}</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-sm border border-slate-200 p-6 mb-6">
|
<div class="bg-[#1e293b] rounded-lg shadow-sm border border-slate-700 p-6 mb-6">
|
||||||
<h2 class="text-lg font-semibold text-slate-800 mb-3">Maven Dependency</h2>
|
<h2 class="text-lg font-semibold text-slate-200 mb-3">Maven Dependency</h2>
|
||||||
<pre class="bg-slate-900 text-green-400 rounded-lg p-4 font-mono text-sm overflow-x-auto">{}</pre>
|
<pre class="bg-slate-900 text-green-400 rounded-lg p-4 font-mono text-sm overflow-x-auto">{}</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow-sm border border-slate-200 overflow-hidden">
|
<div class="bg-[#1e293b] rounded-lg shadow-sm border border-slate-700 overflow-hidden">
|
||||||
<div class="px-6 py-4 border-b border-slate-200">
|
<div class="px-6 py-4 border-b border-slate-700">
|
||||||
<h2 class="text-lg font-semibold text-slate-800">Artifacts ({} files)</h2>
|
<h2 class="text-lg font-semibold text-slate-200">Artifacts ({} files)</h2>
|
||||||
</div>
|
</div>
|
||||||
<table class="w-full">
|
<table class="w-full">
|
||||||
<thead class="bg-slate-50 border-b border-slate-200">
|
<thead class="bg-slate-800 border-b border-slate-700">
|
||||||
<tr>
|
<tr>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Filename</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">Filename</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider">Size</th>
|
<th class="px-6 py-3 text-left text-xs font-semibold text-slate-400 uppercase tracking-wider">Size</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="divide-y divide-slate-200">
|
<tbody class="divide-y divide-slate-700">
|
||||||
{}
|
{}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
@@ -444,7 +559,13 @@ pub fn render_maven_detail(path: &str, detail: &MavenDetail) -> String {
|
|||||||
artifact_rows
|
artifact_rows
|
||||||
);
|
);
|
||||||
|
|
||||||
layout(&format!("{} - Maven", path), &content, Some("maven"))
|
layout_dark(
|
||||||
|
&format!("{} - Maven", path),
|
||||||
|
&content,
|
||||||
|
Some("maven"),
|
||||||
|
"",
|
||||||
|
lang,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns SVG icon path for the registry type
|
/// Returns SVG icon path for the registry type
|
||||||
@@ -455,7 +576,9 @@ fn get_registry_icon(registry_type: &str) -> &'static str {
|
|||||||
"npm" => icons::NPM,
|
"npm" => icons::NPM,
|
||||||
"cargo" => icons::CARGO,
|
"cargo" => icons::CARGO,
|
||||||
"pypi" => icons::PYPI,
|
"pypi" => icons::PYPI,
|
||||||
_ => r#"<path fill="currentColor" d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/>"#,
|
_ => {
|
||||||
|
r#"<path fill="currentColor" d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/>"#
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
//! Input validation for artifact registry paths and identifiers
|
//! Input validation for artifact registry paths and identifiers
|
||||||
//!
|
//!
|
||||||
//! Provides security validation to prevent path traversal attacks and
|
//! Provides security validation to prevent path traversal attacks and
|
||||||
@@ -92,7 +93,7 @@ pub fn validate_storage_key(key: &str) -> Result<(), ValidationError> {
|
|||||||
|
|
||||||
// Check each segment
|
// Check each segment
|
||||||
for segment in key.split('/') {
|
for segment in key.split('/') {
|
||||||
if segment.is_empty() && key != "" {
|
if segment.is_empty() && !key.is_empty() {
|
||||||
// Allow trailing slash but not double slashes
|
// Allow trailing slash but not double slashes
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,9 +133,7 @@ async fn main() {
|
|||||||
.expect("Failed to bind to address");
|
.expect("Failed to bind to address");
|
||||||
|
|
||||||
info!("nora-storage (S3 compatible) running on http://{}", addr);
|
info!("nora-storage (S3 compatible) running on http://{}", addr);
|
||||||
axum::serve(listener, app)
|
axum::serve(listener, app).await.expect("Server error");
|
||||||
.await
|
|
||||||
.expect("Server error");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn list_buckets(State(state): State<Arc<AppState>>) -> Response {
|
async fn list_buckets(State(state): State<Arc<AppState>>) -> Response {
|
||||||
|
|||||||
Reference in New Issue
Block a user