Skip to content

Commit

Permalink
Merge pull request #52 from github/simon-engledew/insecure-flag
Browse files Browse the repository at this point in the history
Add an insecure flag for testing
  • Loading branch information
simon-engledew authored Jan 20, 2021
2 parents a1bc449 + 92a42a2 commit 3346397
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cmd

import (
"context"
"crypto/tls"
"net/http"
"os"
"path"
"path/filepath"
Expand All @@ -19,6 +21,7 @@ var rootCmd = &cobra.Command{

type rootFlagFields struct {
cacheDir string
insecure bool
}

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

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

cmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
cmd.PrintErrln(err)
Expand Down

0 comments on commit 3346397

Please sign in to comment.