Skip to content

Commit cbcba27

Browse files
committed
Moved app auth and git-auth settings to app metadata instead of app settings
1 parent 9278865 commit cbcba27

File tree

17 files changed

+205
-193
lines changed

17 files changed

+205
-193
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1111

1212
- Added `openrun_admin` plugin with apis to manage `sync` jobs, for use by manage_sync app
1313

14+
### Changed
15+
16+
- Changed app authentication setting and git auth setting to be stored in app metadata instead of in app settings. This allows those properties to be updated through declarative config. The property is moved over as part of a migration. Also, `app update-metadata` CLI command is renamed to `app update`.
17+
1418
## [0.15.13] - 2025-10-28
1519

1620
### Added
@@ -54,4 +58,4 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5458

5559
- Enable CSRF protection for internal APIs and for apps. App level CSRF protection is enabled by default.
5660
Use `security.disable_csrf_protection = true` to disable. Disable in app metadata by running
57-
`openrun app update-metadata conf --promote 'security.disable_csrf_protection=true' /myapp`
61+
`openrun app update conf --promote 'security.disable_csrf_protection=true' /myapp`

cmd/openrun/app_cmds.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,15 @@ func appType(app types.AppResponse) string {
366366
}
367367

368368
func authType(app types.AppResponse) string {
369-
switch app.Settings.AuthnType {
369+
switch app.Metadata.AuthnType {
370370
case types.AppAuthnNone:
371371
return "NONE"
372372
case types.AppAuthnSystem:
373373
return "SYSTEM"
374374
case types.AppAuthnDefault, "":
375375
return "DEFAULT"
376376
default:
377-
return string(app.Settings.AuthnType)
377+
return string(app.Metadata.AuthnType)
378378
}
379379
}
380380

cmd/openrun/app_update_cmds.go

Lines changed: 20 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ func appUpdateSettingsCommand(commonFlags []cli.Flag, clientConfig *types.Client
2121
Subcommands: []*cli.Command{
2222
appUpdateStageWrite(commonFlags, clientConfig),
2323
appUpdatePreviewWrite(commonFlags, clientConfig),
24-
appUpdateAuthnType(commonFlags, clientConfig),
25-
appUpdateGitAuth(commonFlags, clientConfig),
2624
},
2725
}
2826
}
@@ -151,123 +149,18 @@ The second required argument is <appPathGlob>. ` + PATH_SPEC_HELP + `
151149
}
152150
}
153151

154-
func appUpdateAuthnType(commonFlags []cli.Flag, clientConfig *types.ClientConfig) *cli.Command {
155-
flags := make([]cli.Flag, 0, len(commonFlags)+2)
156-
flags = append(flags, commonFlags...)
157-
flags = append(flags, dryRunFlag())
158-
159-
return &cli.Command{
160-
Name: "auth",
161-
Usage: "Update authentication mode for apps",
162-
Flags: flags,
163-
Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewTomlSourceFromFlagFunc(configFileFlagName)),
164-
ArgsUsage: "<value:system|default|none|custom> <appPathGlob>",
165-
166-
UsageText: `args: <value:default|none> <appPathGlob>
167-
168-
The first required argument <value> is a string, system, default, none or OAuth entry name.
169-
The second required argument is <appPathGlob>. ` + PATH_SPEC_HELP + `
170-
171-
Examples:
172-
Update all apps, across domains: openrun app update-settings auth default all
173-
Update apps in the example.com domain: openrun app update-settings auth none "example.com:**"`,
174-
175-
Action: func(cCtx *cli.Context) error {
176-
if cCtx.NArg() != 2 {
177-
return fmt.Errorf("requires two arguments: <value> <appPathGlob>")
178-
}
179-
180-
client := system.NewHttpClient(clientConfig.ServerUri, clientConfig.AdminUser, clientConfig.Client.AdminPassword, clientConfig.Client.SkipCertCheck)
181-
values := url.Values{}
182-
values.Add("appPathGlob", cCtx.Args().Get(1))
183-
values.Add(DRY_RUN_ARG, strconv.FormatBool(cCtx.Bool(DRY_RUN_FLAG)))
184-
185-
body := types.CreateUpdateAppRequest()
186-
body.AuthnType = types.StringValue(cCtx.Args().Get(0))
187-
188-
var updateResponse types.AppUpdateSettingsResponse
189-
if err := client.Post("/_openrun/app_settings", values, body, &updateResponse); err != nil {
190-
return err
191-
}
192-
193-
for _, updateResult := range updateResponse.UpdateResults {
194-
fmt.Printf("Updating %s\n", updateResult)
195-
}
196-
printStdout(cCtx, "%d app(s) updated.\n", len(updateResponse.UpdateResults))
197-
198-
if updateResponse.DryRun {
199-
fmt.Print(DRY_RUN_MESSAGE)
200-
}
201-
202-
return nil
203-
},
204-
}
205-
}
206-
207-
func appUpdateGitAuth(commonFlags []cli.Flag, clientConfig *types.ClientConfig) *cli.Command {
208-
flags := make([]cli.Flag, 0, len(commonFlags)+2)
209-
flags = append(flags, commonFlags...)
210-
flags = append(flags, dryRunFlag())
211-
212-
return &cli.Command{
213-
Name: "git-auth",
214-
Usage: "Update git-auth entry for apps",
215-
Flags: flags,
216-
Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewTomlSourceFromFlagFunc(configFileFlagName)),
217-
ArgsUsage: "<entryName> <appPathGlob>",
218-
219-
UsageText: `args: <entryName> <appPathGlob>
220-
221-
The first required argument <entryName> is a string. Specify the git_auth entry key name as configured in the openrun.toml config.
222-
Set to "-" to remove the git_auth entry.
223-
The second required argument is <appPathGlob>. ` + PATH_SPEC_HELP + `
224-
225-
Examples:
226-
Update all apps, across domains: openrun app update-settings git-auth mygit all
227-
Update apps in the example.com domain: openrun app git-auth gitentrykey "example.com:**"`,
228-
229-
Action: func(cCtx *cli.Context) error {
230-
if cCtx.NArg() != 2 {
231-
return fmt.Errorf("requires two arguments: <entryName> <appPathGlob>")
232-
}
233-
234-
client := system.NewHttpClient(clientConfig.ServerUri, clientConfig.AdminUser, clientConfig.Client.AdminPassword, clientConfig.Client.SkipCertCheck)
235-
values := url.Values{}
236-
values.Add("appPathGlob", cCtx.Args().Get(1))
237-
values.Add(DRY_RUN_ARG, strconv.FormatBool(cCtx.Bool(DRY_RUN_FLAG)))
238-
239-
body := types.CreateUpdateAppRequest()
240-
body.GitAuthName = types.StringValue(cCtx.Args().Get(0))
241-
242-
var updateResponse types.AppUpdateSettingsResponse
243-
if err := client.Post("/_openrun/app_settings", values, body, &updateResponse); err != nil {
244-
return err
245-
}
246-
247-
for _, updateResult := range updateResponse.UpdateResults {
248-
fmt.Printf("Updating %s\n", updateResult)
249-
}
250-
printStdout(cCtx, "%d app(s) updated.\n", len(updateResponse.UpdateResults))
251-
252-
if updateResponse.DryRun {
253-
fmt.Print(DRY_RUN_MESSAGE)
254-
}
255-
256-
return nil
257-
},
258-
}
259-
}
260-
261152
func appUpdateMetadataCommand(commonFlags []cli.Flag, clientConfig *types.ClientConfig) *cli.Command {
262153
return &cli.Command{
263-
Name: "update-metadata",
154+
Name: "update",
264155
Usage: `Update OpenRun app metadata. Metadata updates are staged and have to be promoted to prod. Use "openrun param" to update app parameter metadata.`,
265156
Subcommands: []*cli.Command{
266157
appUpdateAppSpec(commonFlags, clientConfig),
267-
appUpdateConfig(commonFlags, clientConfig, "container-option", "copt", types.AppMetadataContainerOptions),
268-
appUpdateConfig(commonFlags, clientConfig, "container-arg", "carg", types.AppMetadataContainerArgs),
269-
appUpdateConfig(commonFlags, clientConfig, "container-volumes", "cvol", types.AppMetadataContainerVolumes),
270-
appUpdateConfig(commonFlags, clientConfig, "app-config", "conf", types.AppMetadataAppConfig),
158+
appUpdateConfig(commonFlags, clientConfig, "container-option", "copt", types.AppMetadataContainerOptions, "option"),
159+
appUpdateConfig(commonFlags, clientConfig, "container-arg", "carg", types.AppMetadataContainerArgs, "arg"),
160+
appUpdateConfig(commonFlags, clientConfig, "container-volumes", "cvol", types.AppMetadataContainerVolumes, "volume"),
161+
appUpdateConfig(commonFlags, clientConfig, "app-config", "conf", types.AppMetadataAppConfig, "config"),
162+
appUpdateConfig(commonFlags, clientConfig, "auth", "", types.AppMetadataAuthnType, "<auth_type>"),
163+
appUpdateConfig(commonFlags, clientConfig, "git-auth", "", types.AppMetadataGitAuthName, "<git_auth>"),
271164
},
272165
}
273166
}
@@ -291,8 +184,8 @@ The first required argument <value> is a string, a valid app spec name or - (to
291184
The last required argument is <appPathGlob>. ` + PATH_SPEC_HELP + `
292185
293186
Examples:
294-
Update all apps, across domains: openrun app update-metadata spec - all
295-
Update apps in the example.com domain: openrun app update-metadata spec proxy "example.com:**"`,
187+
Update all apps, across domains: openrun app update spec - all
188+
Update apps in the example.com domain: openrun app update spec proxy "example.com:**"`,
296189

297190
Action: func(cCtx *cli.Context) error {
298191
if cCtx.NArg() != 2 {
@@ -340,27 +233,25 @@ The last required argument is <appPathGlob>. ` + PATH_SPEC_HELP + `
340233
}
341234

342235
// appUpdateConfig creates a command to update app metadata config
343-
func appUpdateConfig(commonFlags []cli.Flag, clientConfig *types.ClientConfig, arg string, shortFlag string, configType types.AppMetadataConfigType) *cli.Command {
236+
func appUpdateConfig(commonFlags []cli.Flag, clientConfig *types.ClientConfig, arg string, shortFlag string, configType types.AppMetadataConfigType, valName string) *cli.Command {
344237
flags := make([]cli.Flag, 0, len(commonFlags)+2)
345238
flags = append(flags, commonFlags...)
346239
flags = append(flags, dryRunFlag())
347240
flags = append(flags, newBoolFlag(PROMOTE_FLAG, "p", "Promote the change from stage to prod", false))
348241

349-
return &cli.Command{
242+
cmd := &cli.Command{
350243
Name: arg,
351-
Aliases: []string{shortFlag},
352244
Usage: fmt.Sprintf("Update %s metadata for apps", arg),
353245
Flags: flags,
354246
Before: altsrc.InitInputSourceWithContext(flags, altsrc.NewTomlSourceFromFlagFunc(configFileFlagName)),
355-
ArgsUsage: "key=value <appPathGlob>",
247+
ArgsUsage: valName + " <appPathGlob>",
356248

357-
UsageText: fmt.Sprintf(`args: key=value [key=value ...] <appPathGlob>
358-
The initial arguments key=value are strings, the key to set and the value to use delimited by =. The value is optional for
359-
container options. The last argument is <appPathGlob>. `+PATH_SPEC_HELP+`
249+
UsageText: fmt.Sprintf(`args: `+valName+` <appPathGlob>
250+
The initial argument are strings. The last argument is <appPathGlob>. `+PATH_SPEC_HELP+`
360251
361252
Examples:
362-
Update all apps, across domains: openrun app update-metadata %s key=value all
363-
Update apps in the example.com domain: openrun app update-metadata %s key=value "example.com:**"`, arg, arg),
253+
Update all apps, across domains: openrun app update %s %s all
254+
Update apps in the example.com domain: openrun app update %s %s "example.com:**"`, arg, valName, arg, valName),
364255

365256
Action: func(cCtx *cli.Context) error {
366257
if cCtx.NArg() < 2 {
@@ -407,4 +298,8 @@ container options. The last argument is <appPathGlob>. `+PATH_SPEC_HELP+`
407298
return nil
408299
},
409300
}
301+
if shortFlag != "" {
302+
cmd.Aliases = []string{shortFlag}
303+
}
304+
return cmd
410305
}

0 commit comments

Comments
 (0)