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