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

Commit 47e1e3a

Browse files
committed
Check CNAB for action before call inspect
Checks the CNAB for the docker app inspect action before attempting to call inspect. If the action is not defined then inspect the CNAB bundle directly. Refactors the `hasAction` func to just check for the key instead of looping through the map. Signed-off-by: Nick Adcock <[email protected]>
1 parent 99c2957 commit 47e1e3a

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

internal/commands/image/inspect.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,35 @@ func runInspect(dockerCli command.Cli, appname string, opts inspectOptions) erro
6969
if err != nil {
7070
return err
7171
}
72-
installation, err := appstore.NewInstallation("custom-action", ref.String(), bndl)
73-
if err != nil {
74-
return err
75-
}
76-
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, os.Stdout)
77-
if err != nil {
78-
return err
79-
}
80-
a := &action.RunCustom{
81-
Action: internal.ActionInspectName,
82-
Driver: driverImpl,
83-
}
8472

8573
format := "json"
8674
if opts.pretty {
8775
format = "pretty"
8876
}
8977

90-
installation.SetParameter(internal.ParameterInspectFormatName, format)
91-
92-
err = a.Run(&installation.Claim, nil)
93-
if err == action.ErrUndefinedAction {
94-
err = inspect.ImageInspectCNAB(os.Stdout, bndl.Bundle, format)
78+
installation, err := appstore.NewInstallation("custom-action", ref.String(), bndl)
79+
if err != nil {
80+
return err
9581
}
9682

97-
if err != nil {
98-
return fmt.Errorf("inspect failed: %s\n%s", err, errBuf)
83+
if _, hasAction := installation.Bundle.Actions[internal.ActionInspectName]; hasAction {
84+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, os.Stdout)
85+
if err != nil {
86+
return err
87+
}
88+
a := &action.RunCustom{
89+
Action: internal.ActionInspectName,
90+
Driver: driverImpl,
91+
}
92+
93+
installation.SetParameter(internal.ParameterInspectFormatName, format)
94+
if err = a.Run(&installation.Claim, nil); err != nil {
95+
return fmt.Errorf("inspect failed: %s\n%s", err, errBuf)
96+
}
97+
} else {
98+
if err = inspect.ImageInspectCNAB(os.Stdout, bndl.Bundle, format); err != nil {
99+
return fmt.Errorf("inspect failed: %s", err)
100+
}
99101
}
100102
return nil
101103
}

internal/commands/inspect.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,6 @@ func getContextOrchestrator(dockerCli command.Cli, orchestratorFlag string) (com
132132
}
133133

134134
func hasAction(bndl *bundle.Bundle, actionName string) bool {
135-
for key := range bndl.Actions {
136-
if key == actionName {
137-
return true
138-
}
139-
}
140-
return false
135+
_, ok := bndl.Actions[actionName]
136+
return ok
141137
}

0 commit comments

Comments
 (0)