feat: provide app url (#1087)

This commit is contained in:
Jonas Plum
2024-07-21 09:24:06 +02:00
committed by GitHub
parent 83251af565
commit 4db718660a
5 changed files with 38 additions and 11 deletions

View File

@@ -39,6 +39,7 @@ func App(dir string, test bool) (*pocketbase.PocketBase, error) {
// Register additional commands
app.RootCmd.AddCommand(fakeDataCmd(app))
app.RootCmd.AddCommand(setFeatureFlagsCmd(app))
app.RootCmd.AddCommand(setAppURL(app))
if err := app.Bootstrap(); err != nil {
return nil, err

View File

@@ -96,3 +96,29 @@ func setFeatureFlagsCmd(app core.App) *cobra.Command {
},
}
}
func setAppURL(app core.App) *cobra.Command {
return &cobra.Command{
Use: "set-app-url",
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
app.Logger().Error("missing app url")
return
}
settings, err := app.Settings().Clone()
if err != nil {
app.Logger().Error(err.Error())
return
}
settings.Meta.AppUrl = args[0]
if err := app.Dao().SaveSettings(settings); err != nil {
app.Logger().Error(err.Error())
}
},
}
}

View File

@@ -260,7 +260,7 @@ event = json.loads(sys.argv[1])
body = json.loads(event["body"])
# Connect to the PocketBase server
client = PocketBase('http://127.0.0.1:8090')
client = PocketBase(os.environ["CATALYST_APP_URL"])
client.auth_store.save(token=os.environ["CATALYST_TOKEN"])
# Create a new ticket
@@ -281,7 +281,7 @@ from pocketbase import PocketBase
ticket = json.loads(sys.argv[1])
# Connect to the PocketBase server
client = PocketBase('http://127.0.0.1:8090')
client = PocketBase(os.environ["CATALYST_APP_URL"])
client.auth_store.save(token=os.environ["CATALYST_TOKEN"])
# Get a random user

View File

@@ -28,7 +28,10 @@ func Run(ctx context.Context, app core.App, actionName, actionData, payload stri
return nil, fmt.Errorf("failed to get system token: %w", err)
}
a.SetToken(token)
a.SetEnv([]string{
"CATALYST_APP_URL=" + app.Settings().Meta.AppUrl,
"CATALYST_TOKEN=" + token,
})
}
return action.Run(ctx, payload)
@@ -39,7 +42,7 @@ type action interface {
}
type authenticatedAction interface {
SetToken(token string)
SetEnv(env []string)
}
func decode(actionName, actionData string) (action, error) {

View File

@@ -13,11 +13,11 @@ type Python struct {
Requirements string `json:"requirements"`
Script string `json:"script"`
token string
env []string
}
func (a *Python) SetToken(token string) {
a.token = token
func (a *Python) SetEnv(env []string) {
a.env = env
}
func (a *Python) Run(ctx context.Context, payload string) ([]byte, error) {
@@ -101,10 +101,7 @@ func (a *Python) pythonRunScript(ctx context.Context, tempDir, payload string) (
cmd := exec.CommandContext(ctx, pythonPath, scriptPath, payload)
cmd.Env = []string{}
if a.token != "" {
cmd.Env = append(cmd.Env, "CATALYST_TOKEN="+a.token)
}
cmd.Env = a.env
return cmd.Output()
}