Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add install method to plugin CLIManager #364

Merged
merged 38 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e561df3
added install to plugin CLIManager
Two-Hearts Nov 24, 2023
6aabbeb
update
Two-Hearts Nov 24, 2023
aa458a8
update
Two-Hearts Nov 24, 2023
59101ed
updated error messages
Two-Hearts Nov 24, 2023
24aef8a
updated error messages
Two-Hearts Nov 24, 2023
b1e0084
updated err msg
Two-Hearts Nov 27, 2023
67bf256
Merge branch 'notaryproject:main' into plugin
Two-Hearts Nov 27, 2023
75a090e
update per code review
Two-Hearts Nov 28, 2023
bd92473
updated per code review
Two-Hearts Dec 6, 2023
c2f7ef8
fix tests
Two-Hearts Dec 6, 2023
371eaa1
updated function doc
Two-Hearts Dec 6, 2023
b845115
updated function doc
Two-Hearts Dec 6, 2023
3eae658
Merge branch 'notaryproject:main' into plugin
Two-Hearts Dec 11, 2023
002fd51
update
Two-Hearts Dec 11, 2023
14aaaa9
updated per code review
Two-Hearts Dec 11, 2023
b179d54
update
Two-Hearts Dec 11, 2023
c44b738
update
Two-Hearts Dec 11, 2023
c9aa8f1
fix tests
Two-Hearts Dec 11, 2023
6fb5ac6
fix test
Two-Hearts Dec 11, 2023
3f4aa31
add tests
Two-Hearts Dec 12, 2023
dd24043
fix tests
Two-Hearts Dec 12, 2023
1fca1b4
update error msg
Two-Hearts Dec 12, 2023
e8ee2ba
update
Two-Hearts Dec 12, 2023
79ea6b7
fix tests
Two-Hearts Dec 12, 2023
a611ee9
fix tests
Two-Hearts Dec 12, 2023
edd0166
fix tests
Two-Hearts Dec 12, 2023
50ba674
update
Two-Hearts Dec 12, 2023
90bfb95
added clean up before installation
Two-Hearts Dec 12, 2023
c8b1d6e
updated comments
Two-Hearts Dec 12, 2023
f939964
added clean up on failure
Two-Hearts Dec 14, 2023
c7ded4a
update
Two-Hearts Dec 14, 2023
d6eb530
update
Two-Hearts Dec 14, 2023
f623ed9
updated per code review
Two-Hearts Dec 15, 2023
f339741
updated per code review
Two-Hearts Dec 15, 2023
c16b6c3
updated per code review
Two-Hearts Dec 15, 2023
cb32182
updated per code review
Two-Hearts Dec 15, 2023
67d267e
updated per code review
Two-Hearts Dec 18, 2023
d6ab20f
updated error message
Two-Hearts Dec 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"golang.org/x/mod/semver"
)

// semVerRegEx is takenfrom https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
// semVerRegEx is taken from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
var semVerRegEx = regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)

// IsValidSemver returns true if version is a valid semantic version
func IsValidSemver(version string) bool {
// IsValid returns true if version is a valid semantic version
func IsValid(version string) bool {
return semVerRegEx.MatchString(version)
}

Expand All @@ -35,10 +35,10 @@ func IsValidSemver(version string) bool {
// The result will be 0 if v == w, -1 if v < w, or +1 if v > w.
func ComparePluginVersion(v, w string) (int, error) {
// sanity check
if !IsValidSemver(v) {
if !IsValid(v) {
return 0, fmt.Errorf("%s is not a valid semantic version", v)
}
if !IsValidSemver(w) {
if !IsValid(w) {
return 0, fmt.Errorf("%s is not a valid semantic version", w)
}

Expand Down
19 changes: 11 additions & 8 deletions plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ func (m *CLIManager) Install(ctx context.Context, installOpts CLIInstallOptions)
return nil, nil, fmt.Errorf("failed to get the system path of plugin %s: %w", pluginName, err)
}
// clean up before installation, this guarantees idempotent for install
if err := os.RemoveAll(pluginDirPath); err != nil {
return nil, nil, fmt.Errorf("failed to clean up %s before installation: %w", pluginDirPath, err)
if err := m.Uninstall(ctx, pluginName); err != nil {
if !errors.Is(err, os.ErrNotExist) {
return nil, nil, fmt.Errorf("failed to clean up plugin %s before installation: %w", pluginName, err)
}
}
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
if installFromNonDir {
if err := file.CopyToDir(pluginExecutableFile, pluginDirPath); err != nil {
Expand Down Expand Up @@ -258,13 +260,14 @@ func parsePluginFromDir(path string) (string, string, error) {
if err != nil {
return err
}
if isExec {
if foundPluginExecutableFile {
return errors.New("found more than one plugin executable files")
}
foundPluginExecutableFile = true
pluginExecutableFile = p
if !isExec {
return nil
}
if foundPluginExecutableFile {
return errors.New("found more than one plugin executable files")
}
foundPluginExecutableFile = true
pluginExecutableFile = p
}
return nil
}); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions plugin/manager_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func isExecutableFile(filePath string) (bool, error) {
if err != nil {
return false, err
}
if !fi.Mode().IsRegular() {
mode := fi.Mode()
if !mode.IsRegular() {
return false, ErrNotRegularFile
}
return fi.Mode()&0100 != 0, nil
return mode.Perm()&0100 != 0, nil
}
3 changes: 2 additions & 1 deletion plugin/manager_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package plugin
import (
"os"
"path/filepath"
"strings"

"github.com/notaryproject/notation-go/plugin/proto"
)
Expand All @@ -33,5 +34,5 @@ func isExecutableFile(filePath string) (bool, error) {
if !fi.Mode().IsRegular() {
return false, ErrNotRegularFile
}
return filepath.Ext(filepath.Base(filePath)) == ".exe", nil
return strings.EqualFold(filepath.Ext(filepath.Base(filePath)), ".exe"), nil
}
2 changes: 1 addition & 1 deletion verifier/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func getVerificationPluginMinVersion(signerInfo *signature.SignerInfo) (string,
if strings.TrimSpace(version) == "" {
return "", fmt.Errorf("%v from extended attribute is an empty string", HeaderVerificationPluginMinVersion)
}
if !notationsemver.IsValidSemver(version) {
if !notationsemver.IsValid(version) {
return "", fmt.Errorf("%v from extended attribute is not a valid SemVer", HeaderVerificationPluginMinVersion)
}
return version, nil
Expand Down
2 changes: 1 addition & 1 deletion verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (v *verifier) processSignature(ctx context.Context, sigBlob []byte, envelop
pluginVersion := metadata.Version

//checking if the plugin version is in valid semver format
if !notationsemver.IsValidSemver(pluginVersion) {
if !notationsemver.IsValid(pluginVersion) {
return notation.ErrorVerificationInconclusive{Msg: fmt.Sprintf("plugin %s has pluginVersion %s which is not in valid semver format", verificationPluginName, pluginVersion)}
}

Expand Down
Loading