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(cmd): support plainHTTP opt for Pull&Push func #153

Merged
merged 1 commit into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cmd/ormb-storage-initializer/cmd/pull-and-export.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var pullExportCmd = &cobra.Command{
}

// Pull the model from the remote registry.
if err := ormbClient.Pull(modelURI); err != nil {
if err := ormbClient.Pull(modelURI, false); err != nil {
return err
}
// Export it to the specified directory.
Expand Down
3 changes: 2 additions & 1 deletion cmd/ormb/cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ This will store the model in the local registry cache to be used later.`,
PreRunE: preRunE,
RunE: func(cmd *cobra.Command, args []string) error {
// TODO(gaocegege): Validate.
return ormbClient.Pull(args[0])

return ormbClient.Pull(args[0], plainHTTPOpt)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/ormb/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Must first run "ormb save" or "ormb pull".`,
PreRunE: preRunE,
RunE: func(cmd *cobra.Command, args []string) error {
// TODO(gaocegege): Validate.
return ormbClient.Push(args[0])
return ormbClient.Push(args[0], plainHTTPOpt)
},
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/oras/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ func NewClient(opts ...ClientOption) (Interface, error) {
return client, nil
}

// AddOption add opt to Client.
func (c *Client) AddOption(opts ...ClientOption) {
for _, opt := range opts {
opt(c)
}
}

// Login logs into a registry
func (c *Client) Login(hostname string, username string, password string, insecure bool) error {
if insecure {
Expand Down
2 changes: 2 additions & 0 deletions pkg/oras/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

// Interface is the interface of the client.
type Interface interface {
AddOption(opts ...ClientOption)

Login(hostname string, username string, password string, insecure bool) error
Logout(hostname string) error
SaveModel(ch *model.Model, ref *oci.Reference) error
Expand Down
12 changes: 8 additions & 4 deletions pkg/ormb/ormb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
// models with a remote registry.
type Interface interface {
Login(hostname, username, password string, insecureOpt bool) error
Push(refStr string) error
Pull(refStr string) error
Push(refStr string, plainHTTP bool) error
Pull(refStr string, plainHTTP bool) error
Export(refStr, dst string) error
Save(src, refStr string) error
Tag(refStr, targetStr string) error
Expand Down Expand Up @@ -45,15 +45,19 @@ func (o ORMB) Login(hostname, username, password string, insecureOpt bool) error
return o.client.Login(hostname, username, password, insecureOpt)
}

func (o ORMB) Push(refStr string) error {
func (o ORMB) Push(refStr string, plainHTTP bool) error {
o.client.AddOption(oras.ClientOptPlainHTTP(plainHTTP))

ref, err := oci.ParseReference(refStr)
if err != nil {
return err
}
return o.client.PushModel(ref)
}

func (o ORMB) Pull(refStr string) error {
func (o ORMB) Pull(refStr string, plainHTTP bool) error {
o.client.AddOption(oras.ClientOptPlainHTTP(plainHTTP))

ref, err := oci.ParseReference(refStr)
if err != nil {
return err
Expand Down