go-container: S3_PREFIX, VERSION на главной
This commit is contained in:
+12
-6
@@ -20,8 +20,11 @@ var (
|
|||||||
s3Client *s3.Client
|
s3Client *s3.Client
|
||||||
bucketName = "terraform-registry" // Default
|
bucketName = "terraform-registry" // Default
|
||||||
hostname = os.Getenv("REGISTRY_HOSTNAME")
|
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
|
// Terraform Registry Protocol Structs
|
||||||
type Discovery struct {
|
type Discovery struct {
|
||||||
ProvidersV1 string `json:"providers.v1"`
|
ProvidersV1 string `json:"providers.v1"`
|
||||||
@@ -70,6 +73,9 @@ func main() {
|
|||||||
if hostname == "" {
|
if hostname == "" {
|
||||||
hostname = "localhost:8080"
|
hostname = "localhost:8080"
|
||||||
}
|
}
|
||||||
|
if s3Prefix == "" {
|
||||||
|
s3Prefix = hostname
|
||||||
|
}
|
||||||
|
|
||||||
endpoint := os.Getenv("S3_ENDPOINT")
|
endpoint := os.Getenv("S3_ENDPOINT")
|
||||||
accessKeyID := os.Getenv("S3_ACCESS_KEY")
|
accessKeyID := os.Getenv("S3_ACCESS_KEY")
|
||||||
@@ -97,7 +103,7 @@ func main() {
|
|||||||
http.HandleFunc("/healthz", healthzHandler)
|
http.HandleFunc("/healthz", healthzHandler)
|
||||||
http.HandleFunc("/readyz", readyzHandler)
|
http.HandleFunc("/readyz", readyzHandler)
|
||||||
|
|
||||||
port := os.Getenv("PORT")
|
port := os.Getenv("PORT")
|
||||||
if port == "" {
|
if port == "" {
|
||||||
port = "5000"
|
port = "5000"
|
||||||
}
|
}
|
||||||
@@ -111,12 +117,12 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
fmt.Fprint(w, `
|
fmt.Fprintf(w, `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head><title>Terra Registry</title></head>
|
<head><title>Terra Registry v`+VERSION+`</title></head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Terra Registry & Documentation Server</h1>
|
<h1>Terra Registry & Documentation Server v`+VERSION+`</h1>
|
||||||
<p>Status: <span style="color: green">ONLINE</span></p>
|
<p>Status: <span style="color: green">ONLINE</span></p>
|
||||||
<hr>
|
<hr>
|
||||||
<p>Powered by Nubes Cloud S3 Storage</p>
|
<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) {
|
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()
|
ctx := context.Background()
|
||||||
versions := []Version{}
|
versions := []Version{}
|
||||||
seenVersions := map[string]*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) {
|
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)
|
filename := fmt.Sprintf("terraform-provider-%s_%s_%s_%s.zip", pType, version, osType, arch)
|
||||||
fullKey := fmt.Sprintf("%s/%s", basePath, filename)
|
fullKey := fmt.Sprintf("%s/%s", basePath, filename)
|
||||||
shasumsKey := fmt.Sprintf("%s/terraform-provider-%s_%s_SHA256SUMS", basePath, pType, version)
|
shasumsKey := fmt.Sprintf("%s/terraform-provider-%s_%s_SHA256SUMS", basePath, pType, version)
|
||||||
|
|||||||
Reference in New Issue
Block a user