Fixed Google storage necessity bug
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -83,16 +84,11 @@ func formatAppfile(filedata string) (string, string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Streams the data into a zip to be used for a cloud function
|
// Streams the data into a zip to be used for a cloud function
|
||||||
func streamZipdata(ctx context.Context, client *storage.Client, identifier, pythoncode, requirements string) (string, error) {
|
func streamZipdata(ctx context.Context, identifier, pythoncode, requirements string) (string, error) {
|
||||||
bucket := client.Bucket(bucketName)
|
|
||||||
|
|
||||||
filename := fmt.Sprintf("generated_cloudfunctions/%s.zip", identifier)
|
filename := fmt.Sprintf("generated_cloudfunctions/%s.zip", identifier)
|
||||||
|
|
||||||
obj := bucket.Object(filename)
|
buf := new(bytes.Buffer)
|
||||||
storageWriter := obj.NewWriter(ctx)
|
zipWriter := zip.NewWriter(buf)
|
||||||
defer storageWriter.Close()
|
|
||||||
|
|
||||||
zipWriter := zip.NewWriter(storageWriter)
|
|
||||||
|
|
||||||
zipFile, err := zipWriter.Create("main.py")
|
zipFile, err := zipWriter.Create("main.py")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -123,7 +119,7 @@ func streamZipdata(ctx context.Context, client *storage.Client, identifier, pyth
|
|||||||
return filename, nil
|
return filename, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAppbase(ctx context.Context, client *storage.Client) ([]byte, []byte, error) {
|
func getAppbase() ([]byte, []byte, error) {
|
||||||
// 1. Have baseline in bucket/generated_apps/baseline
|
// 1. Have baseline in bucket/generated_apps/baseline
|
||||||
// 2. Copy the baseline to a new folder with identifier name
|
// 2. Copy the baseline to a new folder with identifier name
|
||||||
static := "../../functions/static_baseline.py"
|
static := "../../functions/static_baseline.py"
|
||||||
|
|||||||
@@ -5403,13 +5403,13 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) {
|
|||||||
// Test = client side with fetch?
|
// Test = client side with fetch?
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
client, err := storage.NewClient(ctx)
|
//client, err := storage.NewClient(ctx)
|
||||||
if err != nil {
|
//if err != nil {
|
||||||
log.Printf("Failed to create client (storage): %v", err)
|
// log.Printf("Failed to create client (storage): %v", err)
|
||||||
resp.WriteHeader(401)
|
// resp.WriteHeader(401)
|
||||||
resp.Write([]byte(`{"success": false, "reason": "Failed creating client"}`))
|
// resp.Write([]byte(`{"success": false, "reason": "Failed creating client"}`))
|
||||||
return
|
// return
|
||||||
}
|
//}
|
||||||
|
|
||||||
swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromData(body)
|
swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromData(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -5486,7 +5486,7 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. Get all the required code
|
// 2. Get all the required code
|
||||||
appbase, staticBaseline, err := getAppbase(ctx, client)
|
appbase, staticBaseline, err := getAppbase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed getting appbase: %s", err)
|
log.Printf("Failed getting appbase: %s", err)
|
||||||
resp.WriteHeader(500)
|
resp.WriteHeader(500)
|
||||||
@@ -5505,7 +5505,7 @@ func verifySwagger(resp http.ResponseWriter, request *http.Request) {
|
|||||||
//log.Println(stitched)
|
//log.Println(stitched)
|
||||||
|
|
||||||
// 3. Zip and stream it directly in the directory
|
// 3. Zip and stream it directly in the directory
|
||||||
_, err = streamZipdata(ctx, client, identifier, stitched, "requests\nurllib3")
|
_, err = streamZipdata(ctx, identifier, stitched, "requests\nurllib3")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Zipfile error: %s", err)
|
log.Printf("Zipfile error: %s", err)
|
||||||
resp.WriteHeader(500)
|
resp.WriteHeader(500)
|
||||||
|
|||||||
Reference in New Issue
Block a user