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: notation plugin install command #827

Merged
merged 88 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
fb763d9
added zip suport
Two-Hearts Oct 19, 2023
dd75b5d
Merge branch 'notaryproject:main' into plugin-1.1.0
Two-Hearts Oct 19, 2023
c326db2
added tar.gz support
Two-Hearts Oct 20, 2023
d19ec82
updated
Two-Hearts Oct 23, 2023
bf3d6e9
added uninstall
Two-Hearts Oct 23, 2023
a6379c1
added install from URL
Two-Hearts Oct 23, 2023
4b5989c
updated
Two-Hearts Oct 24, 2023
1550236
fix
Two-Hearts Oct 24, 2023
ea75514
updated
Two-Hearts Oct 24, 2023
ce9439f
Merge branch 'notaryproject:main' into plugin-1.1.0
Two-Hearts Oct 31, 2023
236a8aa
notation plugin install
Two-Hearts Oct 31, 2023
4ae38c8
Merge branch 'notaryproject:main' into plugin-install
Two-Hearts Nov 7, 2023
3c6ca5f
update
Two-Hearts Nov 2, 2023
121b783
updated
Two-Hearts Nov 3, 2023
0743cb0
updated unit tests
Two-Hearts Nov 3, 2023
932e89a
updated based on spec changes
Two-Hearts Nov 7, 2023
981cef3
fixed unit tests
Two-Hearts Nov 7, 2023
e641eb5
e2e tests
Two-Hearts Nov 7, 2023
7983bd9
fixing e2e tests
Two-Hearts Nov 7, 2023
56612a6
fixing e2e tests
Two-Hearts Nov 7, 2023
1c070ee
fixing e2e tests
Two-Hearts Nov 7, 2023
5d2d27c
fixing e2e tests
Two-Hearts Nov 8, 2023
26366bc
fixing e2e tests
Two-Hearts Nov 8, 2023
0e5a109
fixing e2e tests
Two-Hearts Nov 8, 2023
73d1aeb
fixing e2e tests
Two-Hearts Nov 8, 2023
4f21480
clean up
Two-Hearts Nov 8, 2023
e275eab
fix CI
Two-Hearts Nov 8, 2023
fccef51
added license headers
Two-Hearts Nov 8, 2023
31a7dc1
updates
Two-Hearts Nov 15, 2023
5f893dc
fix: fix the license check (#826)
Two-Hearts Nov 15, 2023
d5a68ee
updates
Two-Hearts Nov 15, 2023
ff41ceb
fixed tests
Two-Hearts Nov 15, 2023
320b2e3
updates
Two-Hearts Nov 15, 2023
f8747a4
updates
Two-Hearts Nov 15, 2023
c400f10
updates
Two-Hearts Nov 16, 2023
327172e
updates
Two-Hearts Nov 16, 2023
ba587a3
updates
Two-Hearts Nov 16, 2023
93da0fc
updates e2e
Two-Hearts Nov 16, 2023
5dcb505
updates
Two-Hearts Nov 17, 2023
3618d4b
fixed bug
Two-Hearts Nov 17, 2023
1375a85
fix e2e
Two-Hearts Nov 17, 2023
0145452
updated based on spec
Two-Hearts Nov 17, 2023
c8d9c51
fixed e2e
Two-Hearts Nov 17, 2023
364d680
updated based on spec
Two-Hearts Nov 20, 2023
c045bd5
updated based on spec
Two-Hearts Nov 20, 2023
129daa0
bump: bump up to go version 1.21 (#833)
Two-Hearts Nov 20, 2023
84e60aa
updated per code review
Two-Hearts Nov 20, 2023
125b169
updated per code review
Two-Hearts Nov 20, 2023
dfbbba4
updated per code review
Two-Hearts Nov 20, 2023
8cef5eb
doc: update plugin spec (#809)
FeynmanZhou Nov 20, 2023
583ff98
build(deps): Bump github.com/spf13/cobra from 1.7.0 to 1.8.0 (#823)
dependabot[bot] Nov 21, 2023
2624fe7
update
Two-Hearts Nov 21, 2023
a272fdf
updated per code review
Two-Hearts Nov 23, 2023
d3ff85a
updated per code review
Two-Hearts Nov 23, 2023
dbf5adb
fixing unit tests
Two-Hearts Nov 23, 2023
5031090
fixing e2e tests
Two-Hearts Nov 23, 2023
b2b66c4
refactored the code
Two-Hearts Nov 24, 2023
029317b
build(deps): Bump github/codeql-action from 2.22.5 to 2.22.7 (#835)
dependabot[bot] Nov 22, 2023
ed93044
Correct broken link to quick start guide (#831)
rcrozean Nov 22, 2023
0d7170a
updated err msg
Two-Hearts Nov 27, 2023
303dac5
updated dependency
Two-Hearts Nov 28, 2023
d27414b
chore: update tag to digest (#837)
yizha1 Nov 28, 2023
3e07ac8
updated comments
Two-Hearts Nov 28, 2023
bcb2f5f
resolved conflicts
Two-Hearts Dec 14, 2023
80f18a7
chore: update references with the tag version (#836)
yizha1 Dec 7, 2023
a5e4398
resolved conflicts
Two-Hearts Dec 14, 2023
30651d5
build(deps): Bump actions/setup-go from 4.1.0 to 5.0.0 (#845)
dependabot[bot] Dec 13, 2023
a5fa33f
build(deps): Bump github/codeql-action from 2.22.7 to 2.22.9 (#846)
dependabot[bot] Dec 13, 2023
7550dad
added install from executable file directly
Two-Hearts Dec 14, 2023
4adfb46
fixing e2e tests
Two-Hearts Dec 14, 2023
9fdc455
fixing e2e tests
Two-Hearts Dec 14, 2023
f70f736
fixing e2e tests
Two-Hearts Dec 14, 2023
9ac03bf
resolved conflicts
Two-Hearts Dec 14, 2023
4257e06
updated per code review
Two-Hearts Dec 14, 2023
1357ed3
updated dependency
Two-Hearts Dec 15, 2023
34be1e1
updated per code review
Two-Hearts Dec 18, 2023
69b33e0
updated error message
Two-Hearts Dec 18, 2023
3266871
updated notation-go dependency
Two-Hearts Dec 18, 2023
9a6bc30
updated func doc
Two-Hearts Dec 18, 2023
489136a
updated per code review
Two-Hearts Dec 20, 2023
534199f
updated per code review
Two-Hearts Dec 20, 2023
0d510bc
updated per code review
Two-Hearts Dec 20, 2023
0e8b51a
resolved conflicts
Two-Hearts Dec 20, 2023
a68d098
update
Two-Hearts Dec 20, 2023
49a3bcb
added printouts to show dowloading plugin from URL
Two-Hearts Dec 21, 2023
af4b648
fix E2E test
Two-Hearts Dec 21, 2023
57c6b35
fix E2E test
Two-Hearts Dec 21, 2023
45788ae
update
Two-Hearts Dec 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 81 additions & 0 deletions cmd/notation/internal/plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright The Notary Project Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package plugin

import (
"context"
"fmt"
"io"
"net/http"
"time"

"github.com/notaryproject/notation/internal/httputil"
)

// MaxPluginSourceBytes specifies the limit on how many bytes are allowed in the
// server's response to the download from URL request.
//
// The plugin source size must be strictly less than this value.
var MaxPluginSourceBytes int64 = 256 * 1024 * 1024 // 256 MiB

// PluginSourceType is an enum for plugin source
type PluginSourceType int

const (
// PluginSourceTypeFile means plugin source is file
PluginSourceTypeFile PluginSourceType = 1 + iota

// PluginSourceTypeURL means plugin source is URL
PluginSourceTypeURL
)

const (
// MediaTypeZip means plugin file is zip
MediaTypeZip = "application/zip"

// MediaTypeGzip means plugin file is gzip
MediaTypeGzip = "application/x-gzip"
)

// DownloadPluginFromURL downloads plugin file from url to a tmp directory
func DownloadPluginFromURL(ctx context.Context, pluginURL string, tmpFile io.Writer) error {
// Get the data
client := httputil.NewAuthClient(ctx, &http.Client{Timeout: 10 * time.Minute})
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
req, err := http.NewRequest(http.MethodGet, pluginURL, nil)
if err != nil {
return err
}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
// Check server response
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("%s %q: https response bad status: %s", resp.Request.Method, resp.Request.URL, resp.Status)
}
// Write the body to file
lr := &io.LimitedReader{
R: resp.Body,
N: MaxPluginSourceBytes,
}
_, err = io.Copy(tmpFile, lr)
if err != nil {
return err
}
if lr.N == 0 {
return fmt.Errorf("%s %q: https response reaches the %d MiB size limit", resp.Request.Method, resp.Request.URL, MaxPluginSourceBytes)
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
}
return nil
}
1 change: 1 addition & 0 deletions cmd/notation/plugin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Cmd() *cobra.Command {

command.AddCommand(
listCommand(),
installCommand(nil),
uninstallCommand(nil),
)

Expand Down