-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install multiple plugins by passing in a file argument to porter plug…
…ins install (#2504) Signed-off-by: Yingrong Zhao <[email protected]>
- Loading branch information
Showing
10 changed files
with
282 additions
and
28 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
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
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 |
---|---|---|
@@ -1,14 +1,81 @@ | ||
package plugins | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
|
||
"get.porter.sh/porter/pkg/pkgmgmt" | ||
"get.porter.sh/porter/pkg/portercontext" | ||
) | ||
|
||
type InstallOptions struct { | ||
pkgmgmt.InstallOptions | ||
|
||
File string | ||
} | ||
|
||
func (o *InstallOptions) Validate(args []string) error { | ||
func (o *InstallOptions) Validate(args []string, cxt *portercontext.Context) error { | ||
o.PackageType = "plugin" | ||
if o.File != "" { | ||
if len(args) > 0 { | ||
return fmt.Errorf("plugin name should not be specified when --file is provided") | ||
} | ||
|
||
if o.URL != "" { | ||
return fmt.Errorf("plugin URL should not be specified when --file is provided") | ||
} | ||
|
||
if o.Version != "" { | ||
return fmt.Errorf("plugin version should not be specified when --file is provided") | ||
} | ||
|
||
if _, err := cxt.FileSystem.Stat(o.File); err != nil { | ||
return fmt.Errorf("unable to access --file %s: %w", o.File, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
return o.InstallOptions.Validate(args) | ||
} | ||
|
||
// InstallFileOption is the go representation of plugin installation file format. | ||
type InstallFileOption map[string]pkgmgmt.InstallOptions | ||
|
||
// InstallPluginsConfig is a sorted list of InstallationFileOption in alphabetical order. | ||
type InstallPluginsConfig struct { | ||
data InstallFileOption | ||
keys []string | ||
} | ||
|
||
// NewInstallPluginConfigs returns a new instance of InstallPluginConfigs with plugins sorted in alphabetical order | ||
// using their names. | ||
func NewInstallPluginConfigs(opt InstallFileOption) InstallPluginsConfig { | ||
keys := make([]string, 0, len(opt)) | ||
data := make(InstallFileOption, len(opt)) | ||
for k, v := range opt { | ||
keys = append(keys, k) | ||
|
||
v.Name = k | ||
v.PackageType = "plugin" | ||
data[k] = v | ||
} | ||
|
||
sort.SliceStable(keys, func(i, j int) bool { | ||
return keys[i] < keys[j] | ||
}) | ||
|
||
return InstallPluginsConfig{ | ||
data: data, | ||
keys: keys, | ||
} | ||
} | ||
|
||
// Configs returns InstallOptions list in alphabetical order. | ||
func (pc InstallPluginsConfig) Configs() []pkgmgmt.InstallOptions { | ||
value := make([]pkgmgmt.InstallOptions, 0, len(pc.keys)) | ||
for _, k := range pc.keys { | ||
value = append(value, pc.data[k]) | ||
} | ||
return value | ||
} |
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
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,8 @@ | ||
{ | ||
"plugin1": { | ||
"version": "v1.0" | ||
}, | ||
"plugin2": { | ||
"version": "v1.0" | ||
} | ||
} |
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,4 @@ | ||
plugin1: | ||
version: v1.0 | ||
plugin2: | ||
version: v1.0 |
Oops, something went wrong.