diff --git a/internal/auth/machine.go b/internal/auth/machine.go index 1836061..de5afcb 100644 --- a/internal/auth/machine.go +++ b/internal/auth/machine.go @@ -26,13 +26,13 @@ type MachineProfile struct { } type HardwareProfile struct { - CPU string `json:"cpu,omitempty"` - Cores int `json:"cores,omitempty"` - Arch string `json:"arch,omitempty"` - RAMMB int `json:"ram_mb,omitempty"` - StorageMB int `json:"storage_mb,omitempty"` - GPU string `json:"gpu,omitempty"` - TPM bool `json:"tpm,omitempty"` + CPU string `json:"cpu,omitempty"` + Cores int `json:"cores,omitempty"` + Arch string `json:"arch,omitempty"` + RAMMB int `json:"ram_mb,omitempty"` + StorageMB int `json:"storage_mb,omitempty"` + GPU string `json:"gpu,omitempty"` + TPM bool `json:"tpm,omitempty"` MachineID string `json:"machine_id,omitempty"` } diff --git a/internal/auth/owner.go b/internal/auth/owner.go index 7933c36..85b4048 100644 --- a/internal/auth/owner.go +++ b/internal/auth/owner.go @@ -42,7 +42,7 @@ type OwnerStore interface { type MemoryOwnerStore struct { mu sync.RWMutex owners map[int64]*Owner -ByKey map[string]*ownerKeyRef + ByKey map[string]*ownerKeyRef } func NewMemoryOwnerStore() *MemoryOwnerStore { diff --git a/internal/auth/sshmiddleware_test.go b/internal/auth/sshmiddleware_test.go index 139dbb7..37094e3 100644 --- a/internal/auth/sshmiddleware_test.go +++ b/internal/auth/sshmiddleware_test.go @@ -3,8 +3,8 @@ package auth import ( "bytes" "crypto/ed25519" - "crypto/sha256" "crypto/rand" + "crypto/sha256" "encoding/base64" "encoding/json" "io" diff --git a/internal/github/github_test.go b/internal/github/github_test.go index f007d09..a06bf7d 100644 --- a/internal/github/github_test.go +++ b/internal/github/github_test.go @@ -45,9 +45,9 @@ func TestPublishPackage(t *testing.T) { releaseCreated = true w.WriteHeader(201) json.NewEncoder(w).Encode(map[string]interface{}{ - "id": 123, - "tag_name": "v1.0.0", - "name": "hello-world v1.0.0", + "id": 123, + "tag_name": "v1.0.0", + "name": "hello-world v1.0.0", }) }) diff --git a/internal/middleware/ratelimit.go b/internal/middleware/ratelimit.go index 191c78f..63f1b1e 100644 --- a/internal/middleware/ratelimit.go +++ b/internal/middleware/ratelimit.go @@ -31,9 +31,9 @@ type routeLimiter struct { } type RateLimitConfig struct { - Global rate.Limit - GlobalBurst int - Routes []RouteLimit + Global rate.Limit + GlobalBurst int + Routes []RouteLimit } type RouteLimit struct { @@ -47,12 +47,12 @@ func DefaultRateLimitConfig() RateLimitConfig { Global: rate.Limit(30.0 / 60), // 30 per minute global per IP GlobalBurst: 30, Routes: []RouteLimit{ - {Pattern: "search", Rate: 100.0 / 60, Burst: 20}, // Read: 100/min - {Pattern: "patches", Rate: 100.0 / 60, Burst: 20}, // Read: 100/min - {Pattern: "notary", Rate: 30.0 / 60, Burst: 10}, // Notary: 30/min - {Pattern: "unlock", Rate: 5.0 / 60, Burst: 5}, // Unlock: 5/min - {Pattern: "auth", Rate: 10.0 / 60, Burst: 5}, // Auth: 10/min - {Pattern: "download", Rate: 50.0 / 60, Burst: 15}, // Download: 50/min + {Pattern: "search", Rate: 100.0 / 60, Burst: 20}, // Read: 100/min + {Pattern: "patches", Rate: 100.0 / 60, Burst: 20}, // Read: 100/min + {Pattern: "notary", Rate: 30.0 / 60, Burst: 10}, // Notary: 30/min + {Pattern: "unlock", Rate: 5.0 / 60, Burst: 5}, // Unlock: 5/min + {Pattern: "auth", Rate: 10.0 / 60, Burst: 5}, // Auth: 10/min + {Pattern: "download", Rate: 50.0 / 60, Burst: 15}, // Download: 50/min }, } } @@ -143,7 +143,7 @@ func (rl *RateLimiter) Middleware(next http.Handler) http.Handler { rt := rl.matchRoute(r.URL.Path) limiter := rl.getVisitor(key, rt) - remaining := int(limiter.Tokens()-1) + remaining := int(limiter.Tokens() - 1) if remaining < 0 { remaining = 0 } diff --git a/internal/server/e2e_test.go b/internal/server/e2e_test.go index dd88539..3a8887b 100644 --- a/internal/server/e2e_test.go +++ b/internal/server/e2e_test.go @@ -116,9 +116,9 @@ func TestE2EFullFlow(t *testing.T) { publishBody := map[string]interface{}{ "name": "contacts-bridge", "version": "1.2.0", "description": "Contacts bridge MCP", "author": "tester", "license": "MIT", - "sha256": "bbbb2222bbbb2222bbbb2222bbbb2222bbbb2222bbbb2222bbbb2222bbbb2222", - "download_urls": map[string]string{"linux/amd64": "https://example.com/contacts-bridge-1.2.0.cgp"}, - "manifest": map[string]interface{}{"name": "contacts-bridge", "version": "1.2.0", "description": "Contacts bridge MCP"}, + "sha256": "bbbb2222bbbb2222bbbb2222bbbb2222bbbb2222bbbb2222bbbb2222bbbb2222", + "download_urls": map[string]string{"linux/amd64": "https://example.com/contacts-bridge-1.2.0.cgp"}, + "manifest": map[string]interface{}{"name": "contacts-bridge", "version": "1.2.0", "description": "Contacts bridge MCP"}, "hardware_requirements": map[string]interface{}{"min_ram_mb": 256, "min_storage_mb": 100}, } code, resp := e2eReq(srv, "POST", "/v1/patches", publishBody, nil) @@ -132,15 +132,15 @@ func TestE2EFullFlow(t *testing.T) { "name": "hello-world", "version": "1.0.0", "description": "A test hello world", "author": "tester", "license": "MIT", "hardware_requirements": map[string]interface{}{"min_ram_mb": 512}, - "dependencies": map[string]interface{}{"contacts-bridge": "^1.0.0"}, + "dependencies": map[string]interface{}{"contacts-bridge": "^1.0.0"}, } publishBody := map[string]interface{}{ "name": "hello-world", "version": "1.0.0", "description": "A test hello world package", "author": "tester", "license": "MIT", - "sha256": "aaaa1111aaaa1111aaaa1111aaaa1111aaaa1111aaaa1111aaaa1111aaaa1111", - "download_urls": map[string]string{"linux/amd64": "https://example.com/hello-world-1.0.0-linux-amd64.cgp"}, - "manifest": manifest, + "sha256": "aaaa1111aaaa1111aaaa1111aaaa1111aaaa1111aaaa1111aaaa1111aaaa1111", + "download_urls": map[string]string{"linux/amd64": "https://example.com/hello-world-1.0.0-linux-amd64.cgp"}, + "manifest": manifest, "hardware_requirements": map[string]interface{}{"min_ram_mb": 512}, } @@ -168,7 +168,7 @@ func TestE2EFullFlow(t *testing.T) { "linux/amd64": "https://example.com/email-manager-2.0.0.cgp", "linux/arm64": "https://example.com/email-manager-2.0.0-arm64.cgp", }, - "manifest": emailManifest, + "manifest": emailManifest, "hardware_requirements": map[string]interface{}{"min_ram_mb": 1024, "min_storage_mb": 500}, } code, _ := e2eReq(srv, "POST", "/v1/patches", publishBody, nil) @@ -277,7 +277,7 @@ func TestE2EFullFlow(t *testing.T) { "name": "hello-world", "version": "1.0.0", "description": "duplicate", "sha256": "dddd", "download_urls": map[string]string{"": "https://example.com/dup.cgp"}, - "manifest": map[string]interface{}{"name": "hello-world", "version": "1.0.0", "description": "A test hello world package"}, + "manifest": map[string]interface{}{"name": "hello-world", "version": "1.0.0", "description": "A test hello world package"}, } code, body := e2eReq(srv, "POST", "/v1/patches", publishBody, nil) test("duplicate 409", code == 409) @@ -332,17 +332,17 @@ func TestE2EMinRAMFilter(t *testing.T) { packages := []map[string]interface{}{ { "name": "light-pkg", "version": "1.0.0", "sha256": "aaaa", - "download_urls": map[string]string{"": "https://example.com/light.cgp"}, + "download_urls": map[string]string{"": "https://example.com/light.cgp"}, "hardware_requirements": map[string]interface{}{"min_ram_mb": 256}, }, { "name": "medium-pkg", "version": "1.0.0", "sha256": "bbbb", - "download_urls": map[string]string{"": "https://example.com/medium.cgp"}, + "download_urls": map[string]string{"": "https://example.com/medium.cgp"}, "hardware_requirements": map[string]interface{}{"min_ram_mb": 1024}, }, { "name": "heavy-pkg", "version": "1.0.0", "sha256": "cccc", - "download_urls": map[string]string{"": "https://example.com/heavy.cgp"}, + "download_urls": map[string]string{"": "https://example.com/heavy.cgp"}, "hardware_requirements": map[string]interface{}{"min_ram_mb": 4096, "min_storage_mb": 2000}, }, } @@ -395,7 +395,7 @@ func TestE2EDependenciesTransitive(t *testing.T) { { "name": "leaf-dep", "version": "1.0.0", "sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "download_urls": map[string]string{"": "https://example.com/leaf.cgp"}, - "manifest": map[string]interface{}{"name": "leaf-dep", "version": "1.0.0", "description": "leaf dep"}, + "manifest": map[string]interface{}{"name": "leaf-dep", "version": "1.0.0", "description": "leaf dep"}, }, { "name": "mid-dep", "version": "1.0.0", "sha256": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", @@ -485,7 +485,7 @@ func TestE2EMultiVariantDownload(t *testing.T) { if w.Code != http.StatusFound { t.Errorf("expected 302 redirect, got %d", w.Code) } -Location := w.Header().Get("Location") + Location := w.Header().Get("Location") if Location != "https://example.com/multi-linux-arm64.cgp" { t.Errorf("wrong redirect URL: %s", Location) } diff --git a/internal/server/handlers.go b/internal/server/handlers.go index aa35586..eebc216 100644 --- a/internal/server/handlers.go +++ b/internal/server/handlers.go @@ -25,10 +25,10 @@ func (s *Server) handleHealth() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { patchesCount, _ := s.config.Store.List() writeJSON(w, http.StatusOK, map[string]interface{}{ - "status": "healthy", + "status": "healthy", "uptime_seconds": int(time.Since(s.startedAt).Seconds()), - "patches_count": len(patchesCount), - "version": "2.1.0", + "patches_count": len(patchesCount), + "version": "2.1.0", }) } } @@ -70,16 +70,16 @@ func (s *Server) handleSearch() http.HandlerFunc { } type searchResult struct { - Name string `json:"name"` - Version string `json:"version"` - Description string `json:"description"` - Author string `json:"author,omitempty"` - License string `json:"license"` - SHA256 string `json:"sha256"` - Downloads int64 `json:"downloads"` + Name string `json:"name"` + Version string `json:"version"` + Description string `json:"description"` + Author string `json:"author,omitempty"` + License string `json:"license"` + SHA256 string `json:"sha256"` + Downloads int64 `json:"downloads"` HardwareRequirements *store.HardwareReqs `json:"hardware_requirements,omitempty"` - Capabilities []string `json:"capabilities,omitempty"` - PublishedAt string `json:"published_at,omitempty"` + Capabilities []string `json:"capabilities,omitempty"` + PublishedAt string `json:"published_at,omitempty"` } items := make([]searchResult, len(results)) for i, r := range results { @@ -222,19 +222,19 @@ func (s *Server) handleDownload() http.HandlerFunc { } type publishRequest struct { - Name string `json:"name"` - Version string `json:"version"` - Description string `json:"description,omitempty"` - Author string `json:"author,omitempty"` - License string `json:"license,omitempty"` - SourceRepository string `json:"source_repository,omitempty"` - SourceIssues string `json:"source_issues,omitempty"` - DownloadURL string `json:"download_url,omitempty"` // v1 compat - DownloadURLs map[string]string `json:"download_urls,omitempty"` // v2: variant-keyed - SHA256 string `json:"sha256"` - Tags []string `json:"tags,omitempty"` - Capabilities []string `json:"capabilities,omitempty"` - Manifest json.RawMessage `json:"manifest"` + Name string `json:"name"` + Version string `json:"version"` + Description string `json:"description,omitempty"` + Author string `json:"author,omitempty"` + License string `json:"license,omitempty"` + SourceRepository string `json:"source_repository,omitempty"` + SourceIssues string `json:"source_issues,omitempty"` + DownloadURL string `json:"download_url,omitempty"` // v1 compat + DownloadURLs map[string]string `json:"download_urls,omitempty"` // v2: variant-keyed + SHA256 string `json:"sha256"` + Tags []string `json:"tags,omitempty"` + Capabilities []string `json:"capabilities,omitempty"` + Manifest json.RawMessage `json:"manifest"` Hardware *store.HardwareReqs `json:"hardware_requirements,omitempty"` } @@ -879,10 +879,10 @@ func (s *Server) handleAuthRegister() http.HandlerFunc { } writeJSON(w, http.StatusCreated, map[string]interface{}{ - "fingerprint": info.Fingerprint, + "fingerprint": info.Fingerprint, "public_key_type": info.KeyType, - "comment": info.Comment, - "registered_at": info.Registered.Format(time.RFC3339), + "comment": info.Comment, + "registered_at": info.Registered.Format(time.RFC3339), }) } } diff --git a/internal/server/server.go b/internal/server/server.go index a8b6e80..64c9341 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -12,24 +12,24 @@ import ( ) type Config struct { - Addr string - DataDir string - Store store.Store - TokenAuth auth.TokenStore - SSHKeys auth.SSHKeyStore - Machines auth.MachineKeyStore - Owners auth.OwnerStore - GitHub *githubclient.Client - Session *SessionMiddleware - UI *UIHandlers + Addr string + DataDir string + Store store.Store + TokenAuth auth.TokenStore + SSHKeys auth.SSHKeyStore + Machines auth.MachineKeyStore + Owners auth.OwnerStore + GitHub *githubclient.Client + Session *SessionMiddleware + UI *UIHandlers } type Server struct { - config Config - mux *http.ServeMux - rateLimit *middleware.RateLimiter - antiBot *middleware.AntiBot - startedAt time.Time + config Config + mux *http.ServeMux + rateLimit *middleware.RateLimiter + antiBot *middleware.AntiBot + startedAt time.Time } func New(config Config) *Server { diff --git a/internal/server/server_test.go b/internal/server/server_test.go index bc539ba..6f76240 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -1154,8 +1154,8 @@ func TestAuthSignup(t *testing.T) { "ram_mb": 8192, }, "software": map[string]interface{}{ - "os": "linux", - "distro": "CognitiveOS", + "os": "linux", + "distro": "CognitiveOS", "cpm_version": "1.0.0", }, } diff --git a/internal/server/session.go b/internal/server/session.go index 015c905..f46797c 100644 --- a/internal/server/session.go +++ b/internal/server/session.go @@ -13,9 +13,9 @@ import ( ) type SessionMiddleware struct { - Secret []byte - MaxAge time.Duration - Path string + Secret []byte + MaxAge time.Duration + Path string } type Session struct { @@ -90,7 +90,7 @@ func (s *SessionMiddleware) GetSession(r *http.Request) (*Session, error) { return nil, fmt.Errorf("invalid session signature") } -_fields := strings.Split(value, "|") + _fields := strings.Split(value, "|") if len(_fields) != 3 { return nil, fmt.Errorf("invalid session data") } diff --git a/internal/store/s3store.go b/internal/store/s3store.go index 97b7803..aaaa3de 100644 --- a/internal/store/s3store.go +++ b/internal/store/s3store.go @@ -19,13 +19,13 @@ import ( ) type S3Store struct { - client *s3.Client - bucket string - prefix string - mu sync.RWMutex - cache map[string]Package - loaded bool - loadedAt time.Time + client *s3.Client + bucket string + prefix string + mu sync.RWMutex + cache map[string]Package + loaded bool + loadedAt time.Time } type S3Config struct { diff --git a/internal/store/store.go b/internal/store/store.go index 9234163..9a7d3af 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -17,8 +17,8 @@ type Package struct { License string `json:"license,omitempty"` SourceRepository string `json:"source_repository,omitempty"` SourceIssues string `json:"source_issues,omitempty"` - DownloadURL string `json:"download_url,omitempty"` // v1 compat (deprecated) - DownloadURLs map[string]string `json:"download_urls,omitempty"` // v2: variant-keyed URLs + DownloadURL string `json:"download_url,omitempty"` // v1 compat (deprecated) + DownloadURLs map[string]string `json:"download_urls,omitempty"` // v2: variant-keyed URLs Size int64 `json:"size,omitempty"` ChecksumSHA256 string `json:"checksum_sha256,omitempty"` Status string `json:"status,omitempty"` diff --git a/internal/validate/validate.go b/internal/validate/validate.go index bd7bd57..fcda017 100644 --- a/internal/validate/validate.go +++ b/internal/validate/validate.go @@ -13,16 +13,16 @@ import ( ) type Manifest struct { - Name string `json:"name"` - Version string `json:"version"` - Description string `json:"description,omitempty"` - Author string `json:"author,omitempty"` - License string `json:"license,omitempty"` - Source *SourceInfo `json:"source,omitempty"` - Dependencies map[string]string `json:"dependencies,omitempty"` - HardwareRequirements *HardwareReq `json:"hardware_requirements,omitempty"` - Brain *BrainConfig `json:"brain,omitempty"` - Runtime *RuntimeConfig `json:"runtime,omitempty"` + Name string `json:"name"` + Version string `json:"version"` + Description string `json:"description,omitempty"` + Author string `json:"author,omitempty"` + License string `json:"license,omitempty"` + Source *SourceInfo `json:"source,omitempty"` + Dependencies map[string]string `json:"dependencies,omitempty"` + HardwareRequirements *HardwareReq `json:"hardware_requirements,omitempty"` + Brain *BrainConfig `json:"brain,omitempty"` + Runtime *RuntimeConfig `json:"runtime,omitempty"` } type SourceInfo struct { @@ -32,9 +32,9 @@ type SourceInfo struct { } type HardwareReq struct { - MinRAMMB int `json:"min_ram_mb,omitempty"` - MinStorageMB int `json:"min_storage_mb,omitempty"` - NPURequired bool `json:"npu_required,omitempty"` + MinRAMMB int `json:"min_ram_mb,omitempty"` + MinStorageMB int `json:"min_storage_mb,omitempty"` + NPURequired bool `json:"npu_required,omitempty"` } type BrainConfig struct {