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

added proxy option for connections #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var (
trustDir string
logLevel string
timeout string
proxyURL string

insecure bool
useHTTP bool
Expand All @@ -42,6 +43,7 @@ func main() {
cmd.PersistentFlags().StringVarP(&timeout, "timeout", "t", "5s", `Timeout for the trust server`)
cmd.PersistentFlags().BoolVarP(&insecure, "insecure", "", false, "Allow connections to SSL registry without certs")
cmd.PersistentFlags().BoolVarP(&useHTTP, "use-http", "", false, "Use plain http instead of https")
cmd.PersistentFlags().StringVarP(&proxyURL, "proxy", "", "", `Allow connections to use proxy server`)

cmd.AddCommand(newPushCmd(), newPullCmd())
if err := cmd.Execute(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func newPullCmd() *cobra.Command {
}

func (p *pullOptions) run() error {
err := oci.Pull(p.ref, p.outFile, insecure, useHTTP)
err := oci.Pull(p.ref, p.outFile, proxyURL, insecure, useHTTP)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ func (p *pushOptions) run() error {

}

return oci.Push(p.ref, p.module, insecure, useHTTP)
return oci.Push(p.ref, p.module, proxyURL, insecure, useHTTP)
}
4 changes: 2 additions & 2 deletions pkg/oci/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
)

// Pull pulls a Wasm module from an OCI registry given a reference
func Pull(ref, outFile string, insecure, useHTTP bool) error {
ctx, resolver, store := newORASContext(insecure, useHTTP)
func Pull(ref, outFile string, proxyURL string, insecure, useHTTP bool) error {
ctx, resolver, store := newORASContext(proxyURL, insecure, useHTTP)

pullOpts := []oras.PullOpt{
oras.WithAllowedMediaType(ContentLayerMediaType),
Expand Down
4 changes: 2 additions & 2 deletions pkg/oci/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

// Push pushes a WASM module to an OCI registry
func Push(ref, module string, insecure, useHTTP bool) error {
ctx, resolver, store := newORASContext(insecure, useHTTP)
func Push(ref, module string, proxyURL string, insecure, useHTTP bool) error {
ctx, resolver, store := newORASContext(proxyURL, insecure, useHTTP)

contents, err := ioutil.ReadFile(module)
if err != nil {
Expand Down
19 changes: 16 additions & 3 deletions pkg/oci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"fmt"
"net/http"
"net/url"
"os"

"github.com/containerd/containerd/remotes"
Expand All @@ -14,22 +15,34 @@ import (
orasctx "oras.land/oras-go/pkg/context"
)

func newORASContext(insecure, useHTTP bool) (context.Context, remotes.Resolver, *orascnt.Memorystore) {
func newORASContext(proxyURL string, insecure, useHTTP bool) (context.Context, remotes.Resolver, *orascnt.Memorystore) {
var transport *http.Transport
ctx := orasctx.Background()
memoryStore := orascnt.NewMemoryStore()
cli, err := auth.NewClient()
if err != nil {
fmt.Fprintf(os.Stderr, "WARNING: Error loading auth file: %v\n", err)
}

client := http.DefaultClient
if insecure {
client.Transport = &http.Transport{
transport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
}
if proxyURL != "" {
if transport == nil {
transport = &http.Transport{}
}
proxyURLParse, _ := url.Parse(proxyURL)
transport.Proxy = http.ProxyURL(proxyURLParse)
}

if transport == nil {
transport = &http.Transport{}
}
client := &http.Client{Transport: transport}

resolver, err := cli.Resolver(context.Background(), client, useHTTP)
if err != nil {
Expand Down