Skip to content

Commit 3346397

Browse files
Merge pull request #52 from github/simon-engledew/insecure-flag
Add an insecure flag for testing
2 parents a1bc449 + 92a42a2 commit 3346397

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cmd/root.go

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cmd
22

33
import (
44
"context"
5+
"crypto/tls"
6+
"net/http"
57
"os"
68
"path"
79
"path/filepath"
@@ -19,6 +21,7 @@ var rootCmd = &cobra.Command{
1921

2022
type rootFlagFields struct {
2123
cacheDir string
24+
insecure bool
2225
}
2326

2427
var rootFlags = rootFlagFields{}
@@ -34,6 +37,12 @@ func (f *rootFlagFields) Init(cmd *cobra.Command) error {
3437
defaultCacheDir := path.Join(executableDirectoryPath, "cache")
3538

3639
cmd.PersistentFlags().StringVar(&f.cacheDir, "cache-dir", defaultCacheDir, "The path to a local directory to cache the Action in.")
40+
cmd.PersistentFlags().BoolVar(&f.insecure, "insecure", false, "Allow insecure server connections when using TLS")
41+
cmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
42+
if f.insecure {
43+
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
44+
}
45+
}
3746

3847
cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
3948
cmd.PrintErrln(err)

0 commit comments

Comments
 (0)