-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16abff3
commit f90e1bc
Showing
6 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/deislabs/porter/pkg/porter" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildBundleCommands(p *porter.Porter) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "bundle", | ||
Short: "bundle commands", | ||
} | ||
|
||
cmd.AddCommand(buildBundleInstallCommand(p)) | ||
|
||
return cmd | ||
} | ||
|
||
func buildBundleInstallCommand(p *porter.Porter) *cobra.Command { | ||
opts := porter.InstallOptions{} | ||
cmd := &cobra.Command{ | ||
Use: "install", | ||
Short: "Install a bundle", | ||
Example: ` porter install | ||
porter install --insecure | ||
porter install --file myapp/bundle.json | ||
porter install --name MyAppInDev | ||
porter install --param-file base-values.txt --param-file dev-values.txt --param test-mode=true --param header-color=blue | ||
porter install --cred azure --cred kubernetes | ||
`, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return opts.Prepare() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return p.InstallBundle(opts) | ||
}, | ||
} | ||
|
||
f := cmd.Flags() | ||
f.BoolVar(&opts.Insecure, "insecure", false, | ||
"Allow installing untrusted bundles") | ||
f.StringVarP(&opts.File, "file", "f", "bundle.json", | ||
"Path to the CNAB definition to install") | ||
f.StringVar(&opts.Name, "name", "", | ||
"Name of the claim, defaults to the name of the bundle") | ||
f.StringSliceVar(&opts.ParamFiles, "param-file", nil, | ||
"Path to a parameters definition file for the bundle, each line in the form of NAME=VALUE. May be specified multiple times.") | ||
f.StringSliceVar(&opts.RawParams, "param", nil, | ||
"Define an individual parameter in the form NAME=VALUE. Overrides parameters set with the same name using --param-file. May be specified multiple times.") | ||
f.StringSliceVarP(&opts.CredentialSets, "cred", "c", nil, "Credential to use when installing the bundle. May be either a named set of credentials or a filepath.") | ||
|
||
return cmd | ||
} | ||
|
||
func buildInstallCommand(p *porter.Porter) *cobra.Command { | ||
return buildBundleInstallCommand(p) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestValidateInstallCommand(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
args string | ||
wantError string | ||
}{ | ||
{"no args", "install", ""}, | ||
{"invalid param", "install --param A:B", "invalid parameter (A:B), must be in name=value format"}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
p := buildRootCommand() | ||
osargs := strings.Split(tc.args, " ") | ||
cmd, args, err := p.Find(osargs) | ||
require.NoError(t, err) | ||
|
||
err = cmd.ParseFlags(args) | ||
require.NoError(t, err) | ||
|
||
err = cmd.PreRunE(cmd, args) | ||
if tc.wantError == "" { | ||
require.NoError(t, err) | ||
} else { | ||
require.EqualError(t, err, tc.wantError) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCommandWiring(t *testing.T) { | ||
testcases := []string{ | ||
"build", | ||
"create", | ||
"install", | ||
"run", | ||
"schema", | ||
"bundle install", | ||
"list mixins", | ||
"version", | ||
} | ||
|
||
for _, tc := range testcases { | ||
t.Run(tc, func(t *testing.T) { | ||
osargs := strings.Split(tc, " ") | ||
|
||
rootCmd := buildRootCommand() | ||
_, _, err := rootCmd.Find(osargs) | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package porter | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/deislabs/porter/pkg/parameters" | ||
) | ||
|
||
type InstallOptions struct { | ||
// Name of the claim. | ||
Name string | ||
|
||
// File path to the CNAB bundle. | ||
File string | ||
|
||
// Insecure bundle installation allowed. | ||
Insecure bool | ||
|
||
// RawParams is the unparsed list of NAME=VALUE parameters set on the command line. | ||
RawParams []string | ||
|
||
// Params is the parsed set of parameters from RawParams. | ||
Params map[string]string | ||
|
||
// ParamFiles is a list of file paths containing lines of NAME=VALUE parameter definitions. | ||
ParamFiles []string | ||
|
||
// CredentialSets is a list of credentialset names to make available to the bundle. | ||
CredentialSets []string | ||
} | ||
|
||
func (o *InstallOptions) Prepare() error { | ||
return o.parseParams() | ||
} | ||
|
||
func (o *InstallOptions) parseParams() error { | ||
p, err := parameters.ParseVariableAssignments(o.RawParams) | ||
if err == nil { | ||
o.Params = p | ||
} | ||
return err | ||
} | ||
|
||
func (p *Porter) InstallBundle(opts InstallOptions) error { | ||
err := p.Config.LoadManifest() | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Fprintf(p.Out, "installing %s...\n", p.Manifest.Name) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package porter | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestInstallOptions_Prepare(t *testing.T) { | ||
opts := InstallOptions{ | ||
RawParams: []string{"A=1", "B=2"}, | ||
} | ||
|
||
err := opts.Prepare() | ||
require.NoError(t, err) | ||
|
||
assert.Len(t, opts.Params, 2) | ||
} |