mirror of
https://github.com/dokku/dokku.git
synced 2026-07-10 20:40:43 +02:00
Every Go-implemented plugin's `:report --format json` now emits keys without the redundant `<plugin>-` head segment, matching the shape bash plugins have always emitted. The CLI flag names and `:set` semantics are unchanged. For backwards compatibility during the 0.38.x patch series, the legacy `<plugin>-<property>` keys are emitted side-by-side with the new keys, and a future major release will drop the legacy keys. `common.ReportSingleApp` is refactored to accept a `ReportSingleAppInput` struct with a `Validate()` method so the input is checked before any work runs, which also catches the latent `"docker options"` reportType bug at the API boundary.
167 lines
5.3 KiB
Go
167 lines
5.3 KiB
Go
package network
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
)
|
|
|
|
// ReportSingleApp is an internal function that displays the network report for one or more apps
|
|
func ReportSingleApp(appName string, format string, infoFlag string) error {
|
|
if appName != "--global" {
|
|
if err := common.VerifyAppName(appName); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
var flags map[string]common.ReportFunc
|
|
if appName == "--global" {
|
|
flags = map[string]common.ReportFunc{
|
|
"--network-computed-attach-post-create": reportComputedAttachPostCreate,
|
|
"--network-computed-attach-post-deploy": reportComputedAttachPostDeploy,
|
|
"--network-computed-bind-all-interfaces": reportComputedBindAllInterfaces,
|
|
"--network-computed-initial-network": reportComputedInitialNetwork,
|
|
"--network-computed-tld": reportComputedTld,
|
|
"--network-global-attach-post-create": reportGlobalAttachPostCreate,
|
|
"--network-global-attach-post-deploy": reportGlobalAttachPostDeploy,
|
|
"--network-global-bind-all-interfaces": reportGlobalBindAllInterfaces,
|
|
"--network-global-initial-network": reportGlobalInitialNetwork,
|
|
"--network-global-tld": reportGlobalTld,
|
|
}
|
|
} else {
|
|
flags = map[string]common.ReportFunc{
|
|
"--network-bind-all-interfaces": reportBindAllInterfaces,
|
|
"--network-attach-post-create": reportAttachPostCreate,
|
|
"--network-attach-post-deploy": reportAttachPostDeploy,
|
|
"--network-computed-attach-post-create": reportComputedAttachPostCreate,
|
|
"--network-computed-attach-post-deploy": reportComputedAttachPostDeploy,
|
|
"--network-computed-bind-all-interfaces": reportComputedBindAllInterfaces,
|
|
"--network-computed-initial-network": reportComputedInitialNetwork,
|
|
"--network-computed-tld": reportComputedTld,
|
|
"--network-global-attach-post-create": reportGlobalAttachPostCreate,
|
|
"--network-global-attach-post-deploy": reportGlobalAttachPostDeploy,
|
|
"--network-global-bind-all-interfaces": reportGlobalBindAllInterfaces,
|
|
"--network-global-initial-network": reportGlobalInitialNetwork,
|
|
"--network-global-tld": reportGlobalTld,
|
|
"--network-initial-network": reportInitialNetwork,
|
|
"--network-static-web-listener": reportStaticWebListener,
|
|
"--network-tld": reportTld,
|
|
"--network-web-listeners": reportWebListeners,
|
|
}
|
|
}
|
|
|
|
flagKeys := []string{}
|
|
for flagKey := range flags {
|
|
flagKeys = append(flagKeys, flagKey)
|
|
}
|
|
|
|
infoFlags := common.CollectReport(appName, infoFlag, flags)
|
|
return common.ReportSingleApp(common.ReportSingleAppInput{
|
|
ReportType: "network",
|
|
AppName: appName,
|
|
InfoFlag: infoFlag,
|
|
InfoFlags: infoFlags,
|
|
InfoFlagKeys: flagKeys,
|
|
Format: format,
|
|
TrimPrefix: true,
|
|
UppercaseFirstCharacter: true,
|
|
EmitLegacyPrefix: true,
|
|
})
|
|
}
|
|
|
|
func reportAttachPostCreate(appName string) string {
|
|
return common.PropertyGet("network", appName, "attach-post-create")
|
|
}
|
|
|
|
func reportAttachPostDeploy(appName string) string {
|
|
return common.PropertyGet("network", appName, "attach-post-deploy")
|
|
}
|
|
|
|
func reportBindAllInterfaces(appName string) string {
|
|
return common.PropertyGet("network", appName, "bind-all-interfaces")
|
|
}
|
|
|
|
func reportComputedAttachPostCreate(appName string) string {
|
|
value := reportAttachPostCreate(appName)
|
|
if value == "" {
|
|
value = reportGlobalAttachPostCreate(appName)
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func reportComputedAttachPostDeploy(appName string) string {
|
|
value := reportAttachPostDeploy(appName)
|
|
if value == "" {
|
|
value = reportGlobalAttachPostDeploy(appName)
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func reportComputedBindAllInterfaces(appName string) string {
|
|
value := reportBindAllInterfaces(appName)
|
|
if value == "" {
|
|
value = reportGlobalBindAllInterfaces(appName)
|
|
}
|
|
if value == "" {
|
|
value = "false"
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func reportComputedInitialNetwork(appName string) string {
|
|
value := reportInitialNetwork(appName)
|
|
if value == "" {
|
|
value = reportGlobalInitialNetwork(appName)
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func reportComputedTld(appName string) string {
|
|
value := reportTld(appName)
|
|
if value == "" {
|
|
value = reportGlobalTld(appName)
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
func reportGlobalAttachPostCreate(appName string) string {
|
|
return common.PropertyGet("network", "--global", "attach-post-create")
|
|
}
|
|
|
|
func reportGlobalAttachPostDeploy(appName string) string {
|
|
return common.PropertyGet("network", "--global", "attach-post-deploy")
|
|
}
|
|
|
|
func reportGlobalBindAllInterfaces(appName string) string {
|
|
return common.PropertyGet("network", "--global", "bind-all-interfaces")
|
|
}
|
|
|
|
func reportGlobalInitialNetwork(appName string) string {
|
|
return common.PropertyGet("network", "--global", "initial-network")
|
|
}
|
|
|
|
func reportGlobalTld(appName string) string {
|
|
return common.PropertyGet("network", "--global", "tld")
|
|
}
|
|
|
|
func reportInitialNetwork(appName string) string {
|
|
return common.PropertyGet("network", appName, "initial-network")
|
|
}
|
|
|
|
func reportStaticWebListener(appName string) string {
|
|
return common.PropertyGet("network", appName, "static-web-listener")
|
|
}
|
|
|
|
func reportTld(appName string) string {
|
|
return common.PropertyGet("network", appName, "tld")
|
|
}
|
|
|
|
func reportWebListeners(appName string) string {
|
|
return strings.Join(GetListeners(appName, "web"), " ")
|
|
}
|