Added basic fix for orborus execution
This commit is contained in:
@@ -53,8 +53,8 @@ SHUFFLE_ELASTIC=true
|
||||
DATASTORE_EMULATOR_HOST=shuffle-database:8000
|
||||
#SHUFFLE_OPENSEARCH_URL=https://shuffle-opensearch:9200
|
||||
SHUFFLE_OPENSEARCH_URL=http://shuffle-opensearch:9200
|
||||
SHUFFLE_OPENSEARCH_USERNAME= #admin
|
||||
SHUFFLE_OPENSEARCH_PASSWORD= #admin
|
||||
SHUFFLE_OPENSEARCH_USERNAME=
|
||||
SHUFFLE_OPENSEARCH_PASSWORD=
|
||||
SHUFFLE_OPENSEARCH_CERTIFICATE_FILE=
|
||||
SHUFFLE_OPENSEARCH_APIKEY=
|
||||
SHUFFLE_OPENSEARCH_CLOUDID=
|
||||
|
||||
@@ -1440,7 +1440,7 @@ class AppBase:
|
||||
print("[INFO] After second return")
|
||||
if len(parsersplit) == 1:
|
||||
returndata = str(baseresult)+str(appendresult)
|
||||
print("RETURNING: %s" % returndata)
|
||||
print("RETURNING!")#: %s" % returndata)
|
||||
return returndata, False
|
||||
|
||||
baseresult = baseresult.replace(" True,", " true,")
|
||||
@@ -1523,7 +1523,8 @@ class AppBase:
|
||||
# Trying without string dumping.
|
||||
|
||||
value, is_loop = get_json_value(fullexecution, to_be_replaced)
|
||||
print("\n\nType of value: %s. Value: %s" % (type(value), value))
|
||||
#print("\n\nType of value: %s. Value: %s" % (type(value), value))
|
||||
print("\n\nType of value: %s" % type(value))
|
||||
if isinstance(value, str):
|
||||
parameter["value"] = parameter["value"].replace(to_be_replaced, value)
|
||||
elif isinstance(value, dict) or isinstance(value, list):
|
||||
@@ -1543,8 +1544,7 @@ class AppBase:
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
parameter["value"] = parameter["value"].replace(to_be_replaced, value)
|
||||
|
||||
print("VALUE: %s" % parameter["value"])
|
||||
|
||||
#print("VALUE: %s" % parameter["value"])
|
||||
|
||||
if parameter["variant"] == "WORKFLOW_VARIABLE":
|
||||
print("Handling workflow variable")
|
||||
@@ -2326,7 +2326,8 @@ class AppBase:
|
||||
raise e
|
||||
#break
|
||||
|
||||
print("\n[INFO] Returned from execution with %s of types %s" % (newres, type(newres)))#, newres)
|
||||
print("\n[INFO] Returned from execution with types %s" % type(newres))
|
||||
#print("\n[INFO] Returned from execution with %s of types %s" % (newres, type(newres)))#, newres)
|
||||
if isinstance(newres, tuple):
|
||||
print("[INFO] Handling return as tuple")
|
||||
# Handles files.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
NAME=shuffle-app_sdk
|
||||
VERSION=0.8.99
|
||||
VERSION=0.8.100
|
||||
|
||||
docker rmi docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION --force
|
||||
docker build . -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.github.com/frikky/shuffle/$NAME:$VERSION -t ghcr.io/frikky/$NAME:$VERSION
|
||||
@@ -12,3 +12,4 @@ docker build . -t frikky/shuffle:app_sdk -t frikky/$NAME:$VERSION -t docker.pkg.
|
||||
|
||||
docker push frikky/shuffle:app_sdk
|
||||
docker push ghcr.io/frikky/$NAME:$VERSION
|
||||
docker push ghcr.io/frikky/$NAME:nightly
|
||||
|
||||
@@ -24,7 +24,7 @@ require (
|
||||
github.com/elastic/go-elasticsearch/v7 v7.12.0 // indirect
|
||||
github.com/elastic/go-elasticsearch/v8 v8.0.0-20210519083322-55daf7425ecb // indirect
|
||||
github.com/frikky/kin-openapi v0.39.0
|
||||
github.com/frikky/shuffle-shared v0.0.60
|
||||
github.com/frikky/shuffle-shared v0.0.61
|
||||
github.com/fsouza/go-dockerclient v1.7.2 // indirect
|
||||
github.com/ghodss/yaml v1.0.0
|
||||
github.com/go-git/go-billy/v5 v5.0.0
|
||||
|
||||
+71
-14
@@ -793,8 +793,14 @@ func handleRegister(resp http.ResponseWriter, request *http.Request) {
|
||||
} else {
|
||||
log.Printf("[DEBUG] Successfully created the default org!")
|
||||
|
||||
defaultEnv := os.Getenv("ORG_ID")
|
||||
if len(defaultEnv) == 0 {
|
||||
defaultEnv = "Shuffle"
|
||||
log.Printf("[DEBUG] Setting default environment for org to %s", defaultEnv)
|
||||
}
|
||||
|
||||
item := shuffle.Environment{
|
||||
Name: "Shuffle",
|
||||
Name: defaultEnv,
|
||||
Type: "onprem",
|
||||
OrgId: orgId,
|
||||
Default: true,
|
||||
@@ -3852,6 +3858,12 @@ func runInitCloudSetup() {
|
||||
func runInitEs(ctx context.Context) {
|
||||
log.Printf("[DEBUG] Starting INIT setup (ES)")
|
||||
|
||||
defaultEnv := os.Getenv("ORG_ID")
|
||||
if len(defaultEnv) == 0 {
|
||||
defaultEnv = "Shuffle"
|
||||
log.Printf("[DEBUG] Setting default environment for org to %s", defaultEnv)
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Getting organizations")
|
||||
activeOrgs, err := shuffle.GetAllOrgs(ctx)
|
||||
setUsers := false
|
||||
@@ -3894,7 +3906,7 @@ func runInitEs(ctx context.Context) {
|
||||
// setUsers = true
|
||||
|
||||
// item := shuffle.Environment{
|
||||
// Name: "Shuffle",
|
||||
// Name: defaultEnv,
|
||||
// Type: "onprem",
|
||||
// OrgId: orgId,
|
||||
// Default: true,
|
||||
@@ -3987,20 +3999,58 @@ func runInitEs(ctx context.Context) {
|
||||
log.Printf("[INFO] Trying to set up user based on environments SHUFFLE_DEFAULT_USERNAME & SHUFFLE_DEFAULT_PASSWORD")
|
||||
username := os.Getenv("SHUFFLE_DEFAULT_USERNAME")
|
||||
password := os.Getenv("SHUFFLE_DEFAULT_PASSWORD")
|
||||
if len(username) == 0 || len(password) == 0 {
|
||||
log.Printf("SHUFFLE_DEFAULT_USERNAME and SHUFFLE_DEFAULT_PASSWORD not defined as environments. Running without default user.")
|
||||
|
||||
if len(username) == 0 || len(password) == 0 || len(activeOrgs) > 0 {
|
||||
log.Printf("[DEBUG] SHUFFLE_DEFAULT_USERNAME and SHUFFLE_DEFAULT_PASSWORD not defined as environments. Running without default user.")
|
||||
} else {
|
||||
apikey := os.Getenv("SHUFFLE_DEFAULT_APIKEY")
|
||||
|
||||
tmpOrg := shuffle.OrgMini{
|
||||
Name: "default",
|
||||
log.Printf("[DEBUG] Creating org for default user %s", username)
|
||||
orgId := uuid.NewV4().String()
|
||||
orgSetupName := "default"
|
||||
newOrg := shuffle.Org{
|
||||
Name: orgSetupName,
|
||||
Id: orgId,
|
||||
Org: orgSetupName,
|
||||
Users: []shuffle.User{},
|
||||
Roles: []string{"admin", "user"},
|
||||
CloudSync: false,
|
||||
}
|
||||
|
||||
err = createNewUser(username, password, "admin", apikey, tmpOrg)
|
||||
err = shuffle.SetOrg(ctx, newOrg, orgId)
|
||||
setUsers := false
|
||||
if err != nil {
|
||||
log.Printf("Failed to create default user %s: %s", username, err)
|
||||
log.Printf("[WARNING] Failed setting organization when creating original user: %s", err)
|
||||
} else {
|
||||
log.Printf("Successfully created user %s", username)
|
||||
log.Printf("[DEBUG] Successfully created the default org with id %s!", orgId)
|
||||
setUsers = true
|
||||
|
||||
item := shuffle.Environment{
|
||||
Name: defaultEnv,
|
||||
Type: "onprem",
|
||||
OrgId: orgId,
|
||||
Default: true,
|
||||
Id: uuid.NewV4().String(),
|
||||
}
|
||||
|
||||
err = shuffle.SetEnvironment(ctx, &item)
|
||||
if err != nil {
|
||||
log.Printf("[WARNING] Failed setting up new environment")
|
||||
}
|
||||
}
|
||||
|
||||
if setUsers {
|
||||
tmpOrg := shuffle.OrgMini{
|
||||
Name: orgSetupName,
|
||||
Id: orgId,
|
||||
}
|
||||
|
||||
err = createNewUser(username, password, "admin", apikey, tmpOrg)
|
||||
if err != nil {
|
||||
log.Printf("[INFO] Failed to create default user %s: %s", username, err)
|
||||
} else {
|
||||
log.Printf("[INFO] Successfully created user %s", username)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4134,7 +4184,7 @@ func runInitEs(ctx context.Context) {
|
||||
log.Printf("[INFO] Finished downloading extra API samples")
|
||||
}
|
||||
|
||||
log.Printf("[INFO] Finished INIT")
|
||||
log.Printf("[INFO] Finished INIT (ES)")
|
||||
}
|
||||
|
||||
// Handles configuration items during Shuffle startup
|
||||
@@ -4206,7 +4256,7 @@ func runInit(ctx context.Context) {
|
||||
|
||||
log.Printf("Organizations exist!")
|
||||
if len(activeOrgs) == 0 {
|
||||
log.Printf(`No orgs. Setting org "default"`)
|
||||
log.Printf(`[DEBUG] No orgs. Setting org "default"`)
|
||||
orgSetupName := "default"
|
||||
orgId := uuid.NewV4().String()
|
||||
newOrg := shuffle.Org{
|
||||
@@ -4230,7 +4280,7 @@ func runInit(ctx context.Context) {
|
||||
|
||||
if len(activeOrgs) == 1 {
|
||||
if len(activeOrgs[0].Users) == 0 {
|
||||
log.Printf("ORG doesn't have any users??")
|
||||
log.Printf("[WARNING] ORG doesn't have any users??")
|
||||
|
||||
q := datastore.NewQuery("Users")
|
||||
var users []shuffle.User
|
||||
@@ -4424,8 +4474,15 @@ func runInit(ctx context.Context) {
|
||||
count, err := shuffle.GetEnvironmentCount()
|
||||
if count == 0 && err == nil && len(activeOrgs) == 1 {
|
||||
log.Printf("[INFO] Setting up environment with org %s", activeOrgs[0].Id)
|
||||
|
||||
defaultEnv := os.Getenv("ORG_ID")
|
||||
if len(defaultEnv) == 0 {
|
||||
defaultEnv = "Shuffle"
|
||||
log.Printf("[DEBUG] Setting default environment for org to %s", defaultEnv)
|
||||
}
|
||||
|
||||
item := shuffle.Environment{
|
||||
Name: "Shuffle",
|
||||
Name: defaultEnv,
|
||||
Type: "onprem",
|
||||
OrgId: activeOrgs[0].Id,
|
||||
Default: true,
|
||||
@@ -4761,7 +4818,7 @@ func runInit(ctx context.Context) {
|
||||
log.Printf("[INFO] Downloading OpenAPI data for search - EXTRA APPS")
|
||||
apis := "https://github.com/frikky/security-openapis"
|
||||
|
||||
// THis gets memory problems hahah
|
||||
// FIXME: This part gets memory problems. Fix in the future to load these apps too.
|
||||
//apis := "https://github.com/APIs-guru/openapi-directory"
|
||||
fs := memfs.New()
|
||||
storer := memory.NewStorage()
|
||||
|
||||
+2
-395
@@ -22,12 +22,9 @@ import (
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
|
||||
scheduler "cloud.google.com/go/scheduler/apiv1"
|
||||
gyaml "github.com/ghodss/yaml"
|
||||
"github.com/h2non/filetype"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"google.golang.org/api/cloudfunctions/v1"
|
||||
schedulerpb "google.golang.org/genproto/googleapis/cloud/scheduler/v1"
|
||||
|
||||
newscheduler "github.com/carlescere/scheduler"
|
||||
"github.com/frikky/kin-openapi/openapi3"
|
||||
@@ -48,7 +45,7 @@ var localBase = "http://localhost:5001"
|
||||
var baseEnvironment = "onprem"
|
||||
|
||||
var cloudname = "cloud"
|
||||
var defaultLocation = "europe-west2"
|
||||
|
||||
var scheduledJobs = map[string]*newscheduler.Job{}
|
||||
var scheduledOrgs = map[string]*newscheduler.Job{}
|
||||
|
||||
@@ -1530,8 +1527,8 @@ func handleExecution(id string, workflow shuffle.Workflow, request *http.Request
|
||||
//workflowExecution.Stream = "tmp"
|
||||
//workflowExecution.WorkflowQueue = "tmp"
|
||||
//workflowExecution.SubscriptionNameNodestream = "testcompany-nodestream"
|
||||
//workflowExecution.Locations = []string{"europe-west2"}
|
||||
workflowExecution.ProjectId = gceProject
|
||||
workflowExecution.Locations = []string{"europe-west2"}
|
||||
workflowExecution.WorkflowId = workflow.ID
|
||||
workflowExecution.StartedAt = int64(time.Now().Unix())
|
||||
workflowExecution.CompletedAt = 0
|
||||
@@ -2401,26 +2398,6 @@ func deleteSchedule(ctx context.Context, id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteScheduleGCP(ctx context.Context, id string) error {
|
||||
c, err := scheduler.NewCloudSchedulerClient(ctx)
|
||||
if err != nil {
|
||||
log.Printf("%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
req := &schedulerpb.DeleteJobRequest{
|
||||
Name: fmt.Sprintf("projects/%s/locations/europe-west2/jobs/schedule_%s", gceProject, id),
|
||||
}
|
||||
|
||||
err = c.DeleteJob(ctx, req)
|
||||
if err != nil {
|
||||
log.Printf("%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func scheduleWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
cors := handleCors(resp, request)
|
||||
if cors {
|
||||
@@ -2893,151 +2870,6 @@ func validateAppInput(resp http.ResponseWriter, request *http.Request) {
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": true}`)))
|
||||
}
|
||||
|
||||
// Deploy to google cloud function :)
|
||||
func deployCloudFunctionPython(ctx context.Context, name, localization, applocation string, environmentVariables map[string]string) error {
|
||||
service, err := cloudfunctions.NewService(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ProjectsLocationsListCall
|
||||
projectsLocationsFunctionsService := cloudfunctions.NewProjectsLocationsFunctionsService(service)
|
||||
location := fmt.Sprintf("projects/%s/locations/%s", gceProject, localization)
|
||||
functionName := fmt.Sprintf("%s/functions/%s", location, name)
|
||||
|
||||
cloudFunction := &cloudfunctions.CloudFunction{
|
||||
AvailableMemoryMb: 128,
|
||||
EntryPoint: "authorization",
|
||||
EnvironmentVariables: environmentVariables,
|
||||
HttpsTrigger: &cloudfunctions.HttpsTrigger{},
|
||||
MaxInstances: 0,
|
||||
Name: functionName,
|
||||
Runtime: "python37",
|
||||
SourceArchiveUrl: applocation,
|
||||
}
|
||||
|
||||
//getCall := projectsLocationsFunctionsService.Get(fmt.Sprintf("%s/functions/function-5", location))
|
||||
//resp, err := getCall.Do()
|
||||
|
||||
createCall := projectsLocationsFunctionsService.Create(location, cloudFunction)
|
||||
_, err = createCall.Do()
|
||||
if err != nil {
|
||||
log.Printf("Failed creating new function. SKIPPING patch, as it probably already exists: %s", err)
|
||||
|
||||
// FIXME - have patching code or nah?
|
||||
createCall := projectsLocationsFunctionsService.Patch(fmt.Sprintf("%s/functions/%s", location, name), cloudFunction)
|
||||
_, err = createCall.Do()
|
||||
if err != nil {
|
||||
log.Println("Failed patching function")
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Successfully patched %s to %s", name, localization)
|
||||
} else {
|
||||
log.Printf("Successfully deployed %s to %s", name, localization)
|
||||
}
|
||||
|
||||
// FIXME - use response to define the HTTPS entrypoint. It's default to an easy one tho
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deploy to google cloud function :)
|
||||
func deployCloudFunctionGo(ctx context.Context, name, localization, applocation string, environmentVariables map[string]string) error {
|
||||
service, err := cloudfunctions.NewService(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ProjectsLocationsListCall
|
||||
projectsLocationsFunctionsService := cloudfunctions.NewProjectsLocationsFunctionsService(service)
|
||||
location := fmt.Sprintf("projects/%s/locations/%s", gceProject, localization)
|
||||
functionName := fmt.Sprintf("%s/functions/%s", location, name)
|
||||
|
||||
cloudFunction := &cloudfunctions.CloudFunction{
|
||||
AvailableMemoryMb: 128,
|
||||
EntryPoint: "Authorization",
|
||||
EnvironmentVariables: environmentVariables,
|
||||
HttpsTrigger: &cloudfunctions.HttpsTrigger{},
|
||||
MaxInstances: 1,
|
||||
Name: functionName,
|
||||
Runtime: "go111",
|
||||
SourceArchiveUrl: applocation,
|
||||
}
|
||||
|
||||
//getCall := projectsLocationsFunctionsService.Get(fmt.Sprintf("%s/functions/function-5", location))
|
||||
//resp, err := getCall.Do()
|
||||
|
||||
createCall := projectsLocationsFunctionsService.Create(location, cloudFunction)
|
||||
_, err = createCall.Do()
|
||||
if err != nil {
|
||||
log.Println("Failed creating new function. Attempting patch, as it might exist already")
|
||||
|
||||
createCall := projectsLocationsFunctionsService.Patch(fmt.Sprintf("%s/functions/%s", location, name), cloudFunction)
|
||||
_, err = createCall.Do()
|
||||
if err != nil {
|
||||
log.Println("Failed patching function")
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Successfully patched %s to %s", name, localization)
|
||||
} else {
|
||||
log.Printf("Successfully deployed %s to %s", name, localization)
|
||||
}
|
||||
|
||||
// FIXME - use response to define the HTTPS entrypoint. It's default to an easy one tho
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Deploy to google cloud function :)
|
||||
func deployWebhookFunction(ctx context.Context, name, localization, applocation string, environmentVariables map[string]string) error {
|
||||
service, err := cloudfunctions.NewService(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ProjectsLocationsListCall
|
||||
projectsLocationsFunctionsService := cloudfunctions.NewProjectsLocationsFunctionsService(service)
|
||||
location := fmt.Sprintf("projects/%s/locations/%s", gceProject, localization)
|
||||
functionName := fmt.Sprintf("%s/functions/%s", location, name)
|
||||
|
||||
cloudFunction := &cloudfunctions.CloudFunction{
|
||||
AvailableMemoryMb: 128,
|
||||
EntryPoint: "Authorization",
|
||||
EnvironmentVariables: environmentVariables,
|
||||
HttpsTrigger: &cloudfunctions.HttpsTrigger{},
|
||||
MaxInstances: 1,
|
||||
Name: functionName,
|
||||
Runtime: "go111",
|
||||
SourceArchiveUrl: applocation,
|
||||
}
|
||||
|
||||
//getCall := projectsLocationsFunctionsService.Get(fmt.Sprintf("%s/functions/function-5", location))
|
||||
//resp, err := getCall.Do()
|
||||
|
||||
createCall := projectsLocationsFunctionsService.Create(location, cloudFunction)
|
||||
_, err = createCall.Do()
|
||||
if err != nil {
|
||||
log.Println("Failed creating new function. Attempting patch, as it might exist already")
|
||||
|
||||
createCall := projectsLocationsFunctionsService.Patch(fmt.Sprintf("%s/functions/%s", location, name), cloudFunction)
|
||||
_, err = createCall.Do()
|
||||
if err != nil {
|
||||
log.Println("Failed patching function")
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Successfully patched %s to %s", name, localization)
|
||||
} else {
|
||||
log.Printf("Successfully deployed %s to %s", name, localization)
|
||||
}
|
||||
|
||||
// FIXME - use response to define the HTTPS entrypoint. It's default to an easy one tho
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadGithubWorkflows(url, username, password, userId, branch, orgId string) error {
|
||||
fs := memfs.New()
|
||||
|
||||
@@ -4083,228 +3915,6 @@ func setNewWorkflowApp(resp http.ResponseWriter, request *http.Request) {
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": true}`)))
|
||||
}
|
||||
|
||||
// Starts a new webhook
|
||||
func handleStopHook(resp http.ResponseWriter, request *http.Request) {
|
||||
cors := handleCors(resp, request)
|
||||
if cors {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := shuffle.HandleApiAuthentication(resp, request)
|
||||
if err != nil {
|
||||
log.Printf("Api authentication failed in set new workflowhandler: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
location := strings.Split(request.URL.String(), "/")
|
||||
|
||||
var fileId string
|
||||
if location[1] == "api" {
|
||||
if len(location) <= 4 {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
fileId = location[4]
|
||||
}
|
||||
|
||||
if len(fileId) != 32 {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false, "reason": "Workflow ID when stopping hook is not valid"}`))
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
hook, err := shuffle.GetHook(ctx, fileId)
|
||||
if err != nil {
|
||||
log.Printf("Failed getting hook %s (stop): %s", fileId, err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
if user.Id != hook.Owner {
|
||||
log.Printf("Wrong user (%s) for workflow %s", user.Username, hook.Id)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Status: %s", hook.Status)
|
||||
log.Printf("Running: %t", hook.Running)
|
||||
if !hook.Running {
|
||||
message := fmt.Sprintf("Error: %s isn't running", hook.Id)
|
||||
log.Println(message)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, message)))
|
||||
return
|
||||
}
|
||||
|
||||
hook.Status = "stopped"
|
||||
hook.Running = false
|
||||
hook.Actions = []shuffle.HookAction{}
|
||||
err = shuffle.SetHook(ctx, *hook)
|
||||
if err != nil {
|
||||
log.Printf("Failed setting hook: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
image := "webhook"
|
||||
|
||||
// This is here to force stop and remove the old webhook
|
||||
// FIXME
|
||||
err = removeWebhookFunction(ctx, fileId)
|
||||
if err != nil {
|
||||
log.Printf("Container stop issue for %s-%s: %s", image, fileId, err)
|
||||
}
|
||||
|
||||
resp.WriteHeader(200)
|
||||
resp.Write([]byte(`{"success": true, "reason": "Stopped webhook"}`))
|
||||
}
|
||||
|
||||
func removeWebhookFunction(ctx context.Context, hookid string) error {
|
||||
service, err := cloudfunctions.NewService(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ProjectsLocationsListCall
|
||||
projectsLocationsFunctionsService := cloudfunctions.NewProjectsLocationsFunctionsService(service)
|
||||
location := fmt.Sprintf("projects/%s/locations/%s", gceProject, defaultLocation)
|
||||
functionName := fmt.Sprintf("%s/functions/webhook_%s", location, hookid)
|
||||
|
||||
deleteCall := projectsLocationsFunctionsService.Delete(functionName)
|
||||
resp, err := deleteCall.Do()
|
||||
if err != nil {
|
||||
log.Printf("Failed to delete %s from %s: %s", hookid, defaultLocation, err)
|
||||
return err
|
||||
} else {
|
||||
log.Printf("Successfully deleted %s from %s", hookid, defaultLocation)
|
||||
}
|
||||
|
||||
_ = resp
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleStartHook(resp http.ResponseWriter, request *http.Request) {
|
||||
cors := handleCors(resp, request)
|
||||
if cors {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := shuffle.HandleApiAuthentication(resp, request)
|
||||
if err != nil {
|
||||
log.Printf("Api authentication failed in set new workflowhandler: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
location := strings.Split(request.URL.String(), "/")
|
||||
|
||||
var fileId string
|
||||
if location[1] == "api" {
|
||||
if len(location) <= 4 {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
fileId = location[4]
|
||||
}
|
||||
|
||||
if len(fileId) != 36 {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false, "reason": "Workflow ID when starting hook is not valid"}`))
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
hook, err := shuffle.GetHook(ctx, fileId)
|
||||
if err != nil {
|
||||
log.Printf("Failed getting hook %s (start): %s", fileId, err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
if user.Id != hook.Owner {
|
||||
log.Printf("Wrong user (%s) for workflow %s", user.Username, hook.Id)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Status: %s", hook.Status)
|
||||
log.Printf("Running: %t", hook.Running)
|
||||
if hook.Running || hook.Status == "Running" {
|
||||
message := fmt.Sprintf("Error: %s is already running", hook.Id)
|
||||
log.Println(message)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, message)))
|
||||
return
|
||||
}
|
||||
|
||||
environmentVariables := map[string]string{
|
||||
"FUNCTION_APIKEY": user.ApiKey,
|
||||
"CALLBACKURL": syncUrl,
|
||||
"HOOKID": fileId,
|
||||
}
|
||||
|
||||
applocation := fmt.Sprintf("gs://%s/triggers/webhook.zip", bucketName)
|
||||
hookname := fmt.Sprintf("webhook_%s", fileId)
|
||||
err = deployWebhookFunction(ctx, hookname, "europe-west2", applocation, environmentVariables)
|
||||
if err != nil {
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "%s"}`, err)))
|
||||
return
|
||||
}
|
||||
|
||||
hook.Status = "running"
|
||||
hook.Running = true
|
||||
err = shuffle.SetHook(ctx, *hook)
|
||||
if err != nil {
|
||||
log.Printf("Failed setting hook: %s", err)
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(`{"success": false}`))
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("Starting function %s?", fileId)
|
||||
resp.WriteHeader(200)
|
||||
resp.Write([]byte(`{"success": true, "reason": "Started webhook"}`))
|
||||
return
|
||||
}
|
||||
|
||||
func removeOutlookTriggerFunction(ctx context.Context, triggerId string) error {
|
||||
service, err := cloudfunctions.NewService(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ProjectsLocationsListCall
|
||||
projectsLocationsFunctionsService := cloudfunctions.NewProjectsLocationsFunctionsService(service)
|
||||
location := fmt.Sprintf("projects/%s/locations/%s", gceProject, defaultLocation)
|
||||
functionName := fmt.Sprintf("%s/functions/outlooktrigger_%s", location, triggerId)
|
||||
|
||||
deleteCall := projectsLocationsFunctionsService.Delete(functionName)
|
||||
resp, err := deleteCall.Do()
|
||||
if err != nil {
|
||||
log.Printf("Failed to delete %s from %s: %s", triggerId, defaultLocation, err)
|
||||
return err
|
||||
} else {
|
||||
log.Printf("Successfully deleted %s from %s", triggerId, defaultLocation)
|
||||
}
|
||||
|
||||
_ = resp
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleUserInput(trigger shuffle.Trigger, organizationId string, workflowId string, referenceExecution string) error {
|
||||
// E.g. check email
|
||||
sms := ""
|
||||
@@ -4430,9 +4040,6 @@ func executeSingleAction(resp http.ResponseWriter, request *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
//workflowExecution.ProjectId = gceProject
|
||||
//workflowExecution.Locations = []string{defaultLocation}
|
||||
|
||||
environments, err := shuffle.GetEnvironments(ctx, user.ActiveOrg.Id)
|
||||
environment := "Shuffle"
|
||||
if len(environments) >= 1 {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ services:
|
||||
depends_on:
|
||||
- backend
|
||||
backend:
|
||||
#build: ./backend
|
||||
build: ./backend
|
||||
image: ghcr.io/frikky/shuffle-backend:nightly
|
||||
container_name: shuffle-backend
|
||||
hostname: ${BACKEND_HOSTNAME}
|
||||
|
||||
@@ -92,7 +92,7 @@ export const GetIconInfo = (action) => {
|
||||
{"key": "list", "values": ["list", "head", "options"]},
|
||||
{"key": "download", "values": ["get", "download", "return", "hello_world", "curl",]},
|
||||
{"key": "add", "values": ["add"]},
|
||||
{"key": "delete", "values": ["delete", "remove"]},
|
||||
{"key": "delete", "values": ["delete", "remove", "clear", "clean",]},
|
||||
{"key": "send", "values": ["send", "dispatch", "mail", "forward", "post", "submit", "mark", "set"]},
|
||||
{"key": "repeat", "values": ["repeat", "retry", "pause",]},
|
||||
{"key": "execute", "values": ["execute", "run", "play", "raise",]},
|
||||
|
||||
@@ -51,7 +51,8 @@ var baseimagetagsuffix = os.Getenv("SHUFFLE_BASE_IMAGE_TAG_SUFFIX")
|
||||
|
||||
var orgId = os.Getenv("ORG_ID")
|
||||
var baseUrl = os.Getenv("BASE_URL")
|
||||
var environment = os.Getenv("ENVIRONMENT_NAME")
|
||||
|
||||
//var environment = os.Getenv("ENVIRONMENT_NAME")
|
||||
var dockerApiVersion = os.Getenv("DOCKER_API_VERSION")
|
||||
var runningMode = strings.ToLower(os.Getenv("RUNNING_MODE"))
|
||||
var cleanupEnv = strings.ToLower(os.Getenv("CLEANUP"))
|
||||
|
||||
Reference in New Issue
Block a user