go-container: S3_PREFIX, VERSION на главной

This commit is contained in:
“Naeel”
2026-08-06 21:33:41 +04:00
parent a0e72b1c7f
commit e19bb6f290
+12 -6
View File
@@ -20,8 +20,11 @@ var (
s3Client *s3.Client
bucketName = "terraform-registry" // Default
hostname = os.Getenv("REGISTRY_HOSTNAME")
s3Prefix = os.Getenv("S3_PREFIX") // S3 key prefix (may differ from hostname)
)
const VERSION = "1.0.0"
// Terraform Registry Protocol Structs
type Discovery struct {
ProvidersV1 string `json:"providers.v1"`
@@ -70,6 +73,9 @@ func main() {
if hostname == "" {
hostname = "localhost:8080"
}
if s3Prefix == "" {
s3Prefix = hostname
}
endpoint := os.Getenv("S3_ENDPOINT")
accessKeyID := os.Getenv("S3_ACCESS_KEY")
@@ -97,7 +103,7 @@ func main() {
http.HandleFunc("/healthz", healthzHandler)
http.HandleFunc("/readyz", readyzHandler)
port := os.Getenv("PORT")
port := os.Getenv("PORT")
if port == "" {
port = "5000"
}
@@ -111,12 +117,12 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, `
fmt.Fprintf(w, `
<!DOCTYPE html>
<html>
<head><title>Terra Registry</title></head>
<head><title>Terra Registry v`+VERSION+`</title></head>
<body>
<h1>Terra Registry & Documentation Server</h1>
<h1>Terra Registry & Documentation Server v`+VERSION+`</h1>
<p>Status: <span style="color: green">ONLINE</span></p>
<hr>
<p>Powered by Nubes Cloud S3 Storage</p>
@@ -181,7 +187,7 @@ func router(w http.ResponseWriter, r *http.Request) {
}
func listVersions(w http.ResponseWriter, r *http.Request, namespace, pType string) {
prefix := fmt.Sprintf("%s/%s/%s/", hostname, namespace, pType)
prefix := fmt.Sprintf("%s/%s/%s/", s3Prefix, namespace, pType)
ctx := context.Background()
versions := []Version{}
seenVersions := map[string]*Version{}
@@ -235,7 +241,7 @@ func listVersions(w http.ResponseWriter, r *http.Request, namespace, pType strin
}
func downloadVersion(w http.ResponseWriter, r *http.Request, namespace, pType, version, osType, arch string) {
basePath := fmt.Sprintf("%s/%s/%s/%s", hostname, namespace, pType, version)
basePath := fmt.Sprintf("%s/%s/%s/%s", s3Prefix, namespace, pType, version)
filename := fmt.Sprintf("terraform-provider-%s_%s_%s_%s.zip", pType, version, osType, arch)
fullKey := fmt.Sprintf("%s/%s", basePath, filename)
shasumsKey := fmt.Sprintf("%s/terraform-provider-%s_%s_SHA256SUMS", basePath, pType, version)