mirror of
https://github.com/hanzoai/compute.git
synced 2026-10-30 14:50:41 +00:00
- /v1/regions|/v1/sizes|/v1/gpus: cached DO catalog (24h TTL), resale-priced (service/pricing.go: one knob, base x1.40 / GPU x1.25; wholesale + provider never surfaced per brand policy). - /v1/machines[/launch|/:id]: per-org machines over ONE house DO account, isolated by the hanzo-org:<org> tag (cross-tenant impossible by construction). Launch is IAM-native + commerce-metered (Authorize gate + Record debit); dryRun returns a price quote and spends nothing. - Auth: resolveComputeOrg derives org from the IAM Owner claim (spoof-proof); service/app calls may pass ?owner. Catalog GETs public-read. - authz: complete the /api->/v1 policy sweep the rebrand missed and add catalog read policies. - KMS-only secrets: houseDOToken() reads DIGITALOCEAN_ACCESS_TOKEN env or the KMS-synced digitalOceanToken conf key. Commerce token from COMMERCE_SERVICE_TOKEN. - deps: add commerce/metering (iam already v1.28.12). Tests: markup/GPU-detection/size-mapping + per-org isolation predicate (unit), plus a live DO catalog integration test (skipped without token; green against real DO: 16 regions, 9 GPU types incl H100/H200/MI300X).
68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
// Copyright 2025 Hanzo Industries Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package service
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// TestLiveDOCatalog exercises the real DigitalOcean catalog through the exact
|
|
// production code path (house client -> godo -> mapping -> resale pricing).
|
|
// It is skipped unless DIGITALOCEAN_ACCESS_TOKEN is set, so it never runs in CI
|
|
// without credentials.
|
|
func TestLiveDOCatalog(t *testing.T) {
|
|
if os.Getenv("DIGITALOCEAN_ACCESS_TOKEN") == "" {
|
|
t.Skip("DIGITALOCEAN_ACCESS_TOKEN unset — skipping live DO catalog test")
|
|
}
|
|
|
|
regions, err := ListRegions()
|
|
if err != nil {
|
|
t.Fatalf("ListRegions: %v", err)
|
|
}
|
|
if len(regions) == 0 {
|
|
t.Fatal("expected at least one region")
|
|
}
|
|
t.Logf("regions: %d (e.g. %s = %q)", len(regions), regions[0].Slug, regions[0].Name)
|
|
|
|
sizes, err := ListSizes()
|
|
if err != nil {
|
|
t.Fatalf("ListSizes: %v", err)
|
|
}
|
|
if len(sizes) == 0 {
|
|
t.Fatal("expected at least one size")
|
|
}
|
|
for _, s := range sizes {
|
|
if s.PriceHourly <= 0 && s.PriceMonthly <= 0 {
|
|
continue
|
|
}
|
|
t.Logf("sample size: %s vcpus=%d mem=%dMB $%.5f/hr $%.2f/mo", s.Slug, s.Vcpus, s.MemoryMB, s.PriceHourly, s.PriceMonthly)
|
|
break
|
|
}
|
|
|
|
gpus, err := ListGPUSizes()
|
|
if err != nil {
|
|
t.Fatalf("ListGPUSizes: %v", err)
|
|
}
|
|
t.Logf("gpu sizes: %d", len(gpus))
|
|
for _, g := range gpus {
|
|
model := ""
|
|
if g.GPU != nil {
|
|
model = g.GPU.Model
|
|
}
|
|
t.Logf("gpu: %s model=%s $%.4f/hr $%.2f/mo", g.Slug, model, g.PriceHourly, g.PriceMonthly)
|
|
}
|
|
}
|