Skip to content

Commit b67c850

Browse files
authored
feat: add insecure options for pull (#37)
Signed-off-by: Gaius <[email protected]>
1 parent 2026bea commit b67c850

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

cmd/pull.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var pullCmd = &cobra.Command{
4646
func init() {
4747
flags := pullCmd.Flags()
4848
flags.BoolVar(&pullConfig.PlainHTTP, "plain-http", false, "use plain HTTP instead of HTTPS")
49+
flags.BoolVar(&pullConfig.Insecure, "insecure", false, "use insecure connection for the pull operation and skip TLS verification")
4950
flags.StringVar(&pullConfig.Proxy, "proxy", "", "use proxy for the pull operation")
5051
flags.StringVar(&pullConfig.ExtractDir, "extract-dir", "", "specify the extract dir for extracting the model artifact")
5152

@@ -65,7 +66,7 @@ func runPull(ctx context.Context, target string) error {
6566
return fmt.Errorf("target is required")
6667
}
6768

68-
opts := []backend.Option{}
69+
opts := []backend.Option{backend.WithInsecure(pullConfig.Insecure)}
6970
if pullConfig.PlainHTTP {
7071
opts = append(opts, backend.WithPlainHTTP())
7172
}

pkg/backend/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Option func(*Options)
2121
type Options struct {
2222
plainHTTP bool
2323
proxy string
24+
insecure bool
2425
output string
2526
}
2627

@@ -38,6 +39,13 @@ func WithProxy(proxy string) Option {
3839
}
3940
}
4041

42+
// WithInsecure sets the insecure option.
43+
func WithInsecure(insecure bool) Option {
44+
return func(opts *Options) {
45+
opts.insecure = insecure
46+
}
47+
}
48+
4149
// WithOutput sets the output option.
4250
func WithOutput(output string) Option {
4351
return func(opts *Options) {

pkg/backend/pull.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package backend
1818

1919
import (
2020
"context"
21+
"crypto/tls"
2122
"encoding/json"
2223
"fmt"
2324
"io"
@@ -70,6 +71,9 @@ func (b *backend) Pull(ctx context.Context, target string, opts ...Option) error
7071

7172
httpClient.Transport = &http.Transport{
7273
Proxy: http.ProxyURL(proxyURL),
74+
TLSClientConfig: &tls.Config{
75+
InsecureSkipVerify: options.insecure,
76+
},
7377
}
7478
}
7579

pkg/config/pull.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ package config
1919
type Pull struct {
2020
PlainHTTP bool
2121
Proxy string
22+
Insecure bool
2223
ExtractDir string
2324
}
2425

2526
func NewPull() *Pull {
2627
return &Pull{
2728
PlainHTTP: false,
2829
Proxy: "",
30+
Insecure: false,
2931
ExtractDir: "",
3032
}
3133
}

0 commit comments

Comments
 (0)