-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from uselagoon/add-persistent-storage
Feature: Incorporates a test for persistent storage
- Loading branch information
Showing
10 changed files
with
81 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters