Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
fb763d9
added zip suport
Oct 19, 2023
dd75b5d
Merge branch 'notaryproject:main' into plugin-1.1.0
Oct 19, 2023
c326db2
added tar.gz support
Oct 20, 2023
d19ec82
updated
Oct 23, 2023
bf3d6e9
added uninstall
Oct 23, 2023
a6379c1
added install from URL
Oct 23, 2023
4b5989c
updated
Oct 24, 2023
1550236
fix
Oct 24, 2023
ea75514
updated
Oct 24, 2023
ce9439f
Merge branch 'notaryproject:main' into plugin-1.1.0
Oct 31, 2023
236a8aa
notation plugin install
Oct 31, 2023
4ae38c8
Merge branch 'notaryproject:main' into plugin-install
Nov 7, 2023
3c6ca5f
update
Nov 2, 2023
121b783
updated
Nov 3, 2023
0743cb0
updated unit tests
Nov 3, 2023
932e89a
updated based on spec changes
Nov 7, 2023
981cef3
fixed unit tests
Nov 7, 2023
e641eb5
e2e tests
Nov 7, 2023
7983bd9
fixing e2e tests
Nov 7, 2023
56612a6
fixing e2e tests
Nov 7, 2023
1c070ee
fixing e2e tests
Nov 7, 2023
5d2d27c
fixing e2e tests
Nov 8, 2023
26366bc
fixing e2e tests
Nov 8, 2023
0e5a109
fixing e2e tests
Nov 8, 2023
73d1aeb
fixing e2e tests
Nov 8, 2023
4f21480
clean up
Nov 8, 2023
e275eab
fix CI
Nov 8, 2023
fccef51
added license headers
Nov 8, 2023
31a7dc1
updates
Nov 15, 2023
5f893dc
fix: fix the license check (#826)
Nov 15, 2023
d5a68ee
updates
Nov 15, 2023
ff41ceb
fixed tests
Nov 15, 2023
320b2e3
updates
Nov 15, 2023
f8747a4
updates
Nov 15, 2023
c400f10
updates
Nov 16, 2023
327172e
updates
Nov 16, 2023
ba587a3
updates
Nov 16, 2023
93da0fc
updates e2e
Nov 16, 2023
5dcb505
updates
Nov 17, 2023
3618d4b
fixed bug
Nov 17, 2023
1375a85
fix e2e
Nov 17, 2023
0145452
updated based on spec
Nov 17, 2023
c8d9c51
fixed e2e
Nov 17, 2023
364d680
updated based on spec
Nov 20, 2023
c045bd5
updated based on spec
Nov 20, 2023
129daa0
bump: bump up to go version 1.21 (#833)
Nov 20, 2023
84e60aa
updated per code review
Nov 20, 2023
125b169
updated per code review
Nov 20, 2023
dfbbba4
updated per code review
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
Nov 21, 2023
a272fdf
updated per code review
Nov 23, 2023
d3ff85a
updated per code review
Nov 23, 2023
dbf5adb
fixing unit tests
Nov 23, 2023
5031090
fixing e2e tests
Nov 23, 2023
b2b66c4
refactored the code
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
Nov 27, 2023
303dac5
updated dependency
Nov 28, 2023
d27414b
chore: update tag to digest (#837)
yizha1 Nov 28, 2023
3e07ac8
updated comments
Nov 28, 2023
bcb2f5f
resolved conflicts
Dec 14, 2023
80f18a7
chore: update references with the tag version (#836)
yizha1 Dec 7, 2023
a5e4398
resolved conflicts
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
Dec 14, 2023
4adfb46
fixing e2e tests
Dec 14, 2023
9fdc455
fixing e2e tests
Dec 14, 2023
f70f736
fixing e2e tests
Dec 14, 2023
9ac03bf
resolved conflicts
Dec 14, 2023
4257e06
updated per code review
Dec 14, 2023
1357ed3
updated dependency
Dec 15, 2023
34be1e1
updated per code review
Dec 18, 2023
69b33e0
updated error message
Dec 18, 2023
3266871
updated notation-go dependency
Dec 18, 2023
9a6bc30
updated func doc
Dec 18, 2023
489136a
updated per code review
Dec 20, 2023
534199f
updated per code review
Dec 20, 2023
0d510bc
updated per code review
Dec 20, 2023
0e8b51a
resolved conflicts
Dec 20, 2023
a68d098
update
Dec 20, 2023
49a3bcb
added printouts to show dowloading plugin from URL
Dec 21, 2023
af4b648
fix E2E test
Dec 21, 2023
57c6b35
fix E2E test
Dec 21, 2023
45788ae
update
Dec 21, 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
85 changes: 85 additions & 0 deletions cmd/notation/internal/plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 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"
)

// DownloadPluginFromURLTimeout is the timeout when downloading plugin from a
// URL
const DownloadPluginFromURLTimeout = 10 * time.Minute

// 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: DownloadPluginFromURLTimeout})
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)
}
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
Loading