Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 5edcd80

Browse files
author
Ian Campbell
committed
Define constants for all custom actions
There is one small semantic change here which is that the `prepareCustomAction` helper now takes the full qualified/namespaced name and not just the suffix. This is no longer valid to be used as the argument to `claim.New(...)` however as far as I can tell that string is completely arbitrary and is never used (we never store this claim) so it might as well be some hardcoded string. Signed-off-by: Ian Campbell <ijc@docker.com>
1 parent 2361065 commit 5edcd80

7 files changed

Lines changed: 25 additions & 17 deletions

File tree

cmd/cnab-run/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ type cnabAction func(string) error
1212

1313
var (
1414
cnabActions = map[string]cnabAction{
15-
"install": installAction,
16-
"upgrade": installAction,
17-
"uninstall": uninstallAction,
18-
internal.Namespace + "status": statusAction,
19-
internal.Namespace + "inspect": inspectAction,
20-
internal.Namespace + "render": renderAction,
15+
"install": installAction,
16+
"upgrade": installAction,
17+
"uninstall": uninstallAction,
18+
internal.ActionStatusName: statusAction,
19+
internal.ActionInspectName: inspectAction,
20+
internal.ActionRenderName: renderAction,
2121
}
2222
)
2323

internal/commands/cnab.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func isDockerHostLocal(host string) bool {
253253
func prepareCustomAction(actionName string, dockerCli command.Cli, appname string, stdout io.Writer,
254254
registryOpts registryOptions, pullOpts pullOptions, paramsOpts parametersOptions) (*action.RunCustom, *claim.Claim, *bytes.Buffer, error) {
255255

256-
c, err := claim.New(actionName)
256+
c, err := claim.New("custom-action")
257257
if err != nil {
258258
return nil, nil, nil, err
259259
}
@@ -277,7 +277,7 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
277277
c.Parameters = parameters
278278

279279
a := &action.RunCustom{
280-
Action: internal.Namespace + actionName,
280+
Action: actionName,
281281
Driver: driverImpl,
282282
}
283283
return a, c, errBuf, nil

internal/commands/inspect.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package commands
33
import (
44
"fmt"
55

6+
"github.com/docker/app/internal"
67
"github.com/docker/cli/cli"
78
"github.com/docker/cli/cli/command"
89
"github.com/spf13/cobra"
@@ -32,7 +33,7 @@ func inspectCmd(dockerCli command.Cli) *cobra.Command {
3233

3334
func runInspect(dockerCli command.Cli, appname string, opts inspectOptions) error {
3435
defer muteDockerCli(dockerCli)()
35-
a, c, errBuf, err := prepareCustomAction("inspect", dockerCli, appname, nil, opts.registryOptions, opts.pullOptions, opts.parametersOptions)
36+
a, c, errBuf, err := prepareCustomAction(internal.ActionInspectName, dockerCli, appname, nil, opts.registryOptions, opts.pullOptions, opts.parametersOptions)
3637
if err != nil {
3738
return err
3839
}

internal/commands/render.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions) error
5353
w = f
5454
}
5555

56-
a, c, errBuf, err := prepareCustomAction("render", dockerCli, appname, w, opts.registryOptions, opts.pullOptions, opts.parametersOptions)
56+
a, c, errBuf, err := prepareCustomAction(internal.ActionRenderName, dockerCli, appname, w, opts.registryOptions, opts.pullOptions, opts.parametersOptions)
5757
if err != nil {
5858
return err
5959
}

internal/commands/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func runStatus(dockerCli command.Cli, claimName string, opts credentialOptions)
5555
return err
5656
}
5757
status := &action.RunCustom{
58-
Action: internal.Namespace + "status",
58+
Action: internal.ActionStatusName,
5959
Driver: driverImpl,
6060
}
6161
if err := status.Run(&c, creds, dockerCli.Out()); err != nil {

internal/names.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const (
2525
// Namespace is the reverse DNS namespace used with labels and CNAB custom actions.
2626
Namespace = "com.docker.app."
2727

28+
// ActionStatusName is the name of the custom "status" action
29+
ActionStatusName = Namespace + "status"
30+
// ActionInspectName is the name of the custom "inspect" action
31+
ActionInspectName = Namespace + "inspect"
32+
// ActionRenderName is the name of the custom "render" action
33+
ActionRenderName = Namespace + "render"
34+
2835
// DockerStackOrchestratorEnvVar is the environment variable set by the CNAB runtime to select
2936
// the stack orchestrator.
3037
DockerStackOrchestratorEnvVar = "DOCKER_STACK_ORCHESTRATOR"

internal/packager/cnab.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
3030
"install",
3131
"upgrade",
3232
"uninstall",
33-
internal.Namespace + "status",
33+
internal.ActionStatusName,
3434
},
3535
},
3636
internal.Namespace + "kubernetes-namespace": {
@@ -46,7 +46,7 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
4646
"install",
4747
"upgrade",
4848
"uninstall",
49-
internal.Namespace + "status",
49+
internal.ActionStatusName,
5050
},
5151
},
5252
internal.Namespace + "render-format": {
@@ -63,7 +63,7 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
6363
Description: "Output format for the render command",
6464
},
6565
ApplyTo: []string{
66-
internal.Namespace + "render",
66+
internal.ActionRenderName,
6767
},
6868
},
6969
}
@@ -109,15 +109,15 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
109109
Version: app.Metadata().Version,
110110
Parameters: parameters,
111111
Actions: map[string]bundle.Action{
112-
internal.Namespace + "inspect": {
112+
internal.ActionInspectName: {
113113
Modifies: false,
114114
Stateless: true,
115115
},
116-
internal.Namespace + "render": {
116+
internal.ActionRenderName: {
117117
Modifies: false,
118118
Stateless: true,
119119
},
120-
internal.Namespace + "status": {
120+
internal.ActionStatusName: {
121121
Modifies: false,
122122
},
123123
},

0 commit comments

Comments
 (0)