Skip to content

Commit 7fd7267

Browse files
committed
Add insecure flag for insecure TLS connections
1 parent c672623 commit 7fd7267

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Flags:
5050
-d, --debug print out request and response objects
5151
-h, --help help for cyclone
5252
--image-web-download use Glance web-download image import method
53+
-k, --insecure Allow insecure server connections (use if you understand the risks)
5354
-n, --no assume "no" to all questions
5455
--timeout-backup string timeout to wait for a backup status (default "24h")
5556
--timeout-image string timeout to wait for an image status (default "24h")

pkg/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func initRootCmdFlags() {
108108
RootCmd.PersistentFlags().StringP("timeout-secret", "", "24h", "timeout to wait for a secret status")
109109
RootCmd.PersistentFlags().StringP("timeout-security-group", "", "24h", "timeout to wait for a security group status")
110110
RootCmd.PersistentFlags().BoolP("image-web-download", "", false, "use Glance web-download image import method")
111+
RootCmd.PersistentFlags().BoolP("insecure", "k", false, "Allow insecure server connections (use if you understand the risks)")
111112

112113
err := viper.BindPFlag("debug", RootCmd.PersistentFlags().Lookup("debug"))
113114
if err != nil {
@@ -201,6 +202,10 @@ func initRootCmdFlags() {
201202
if err != nil {
202203
panic(err)
203204
}
205+
err = viper.BindPFlag("insecure", RootCmd.PersistentFlags().Lookup("insecure"))
206+
if err != nil {
207+
panic(err)
208+
}
204209
}
205210

206211
func parseTimeoutArg(arg string, dst *float64, errors *[]error) {

pkg/utils.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package pkg
22

33
import (
44
"context"
5+
"crypto/tls"
56
"fmt"
67
"net/http"
78
"os"
89
"strings"
910
"sync"
1011
"time"
1112

13+
"github.com/spf13/viper"
1214
"golang.org/x/term"
1315

1416
"github.com/gophercloud/gophercloud/v2"
@@ -84,12 +86,19 @@ func newOpenStackClient(ctx context.Context, loc Location) (*gophercloud.Provide
8486
}
8587
provider.UserAgent.Prepend("cyclone/" + Version)
8688

89+
insecure := viper.GetBool("insecure")
90+
tlsConfig := &tls.Config{
91+
InsecureSkipVerify: insecure,
92+
}
93+
8794
// debug logger is enabled by default and writes logs into a cyclone temp dir
8895
provider.HTTPClient = http.Client{
8996
Transport: &client.RoundTripper{
9097
MaxRetries: 5,
91-
Rt: &http.Transport{},
92-
Logger: &logger{Prefix: loc.Origin},
98+
Rt: &http.Transport{
99+
TLSClientConfig: tlsConfig,
100+
},
101+
Logger: &logger{Prefix: loc.Origin},
93102
},
94103
}
95104

0 commit comments

Comments
 (0)