-
Notifications
You must be signed in to change notification settings - Fork 1
/
persistentstorage.go
47 lines (42 loc) · 1.07 KB
/
persistentstorage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
machineryEnvVars "github.com/uselagoon/machinery/utils/variables"
"log"
"net/http"
"os"
"strconv"
"strings"
)
func persistentStorageHandler(w http.ResponseWriter, r *http.Request) {
path := r.URL.Query().Get("path")
log.Print(fmt.Sprintf("Writing to %s", path))
fmt.Fprintf(w, persistentStorageConnector(path))
}
func persistentStorageConnector(route string) string {
if route != machineryEnvVars.GetEnv("STORAGE_LOCATION", "") {
return "Storage location is not defined - ensure format matches '/storage?path=[path]'"
}
path := route + "/storage.txt"
f, err := os.Create(path)
if err != nil {
log.Println(err)
}
for _, e := range os.Environ() {
if strings.Contains(e, "LAGOON_") {
_, err := f.WriteString(strconv.Quote(e) + "\n")
if err != nil {
log.Print(err)
}
e := f.Sync()
if e != nil {
log.Print(e)
}
}
}
fileBuffer, err := os.ReadFile(path)
var results = string(fileBuffer)
storagePath := fmt.Sprintf(`"STORAGE_PATH=%s"`, path)
storageResults := storagePath + "\n" + results
return storageResults
}