@@ -19,6 +19,7 @@ package main
1919import (
2020 "bufio"
2121 "context"
22+ "crypto/tls"
2223 "errors"
2324 "fmt"
2425 "io"
@@ -33,7 +34,9 @@ import (
3334 "github.com/chzyer/readline"
3435 "github.com/olekukonko/tablewriter"
3536 "google.golang.org/api/option"
37+ "google.golang.org/grpc"
3638 "google.golang.org/grpc/codes"
39+ "google.golang.org/grpc/credentials"
3740)
3841
3942type DisplayMode int
@@ -58,25 +61,26 @@ var (
5861)
5962
6063type Cli struct {
61- Session * Session
62- Prompt string
63- HistoryFile string
64- Credential []byte
65- InStream io.ReadCloser
66- OutStream io.Writer
67- ErrStream io.Writer
68- Verbose bool
69- Priority pb.RequestOptions_Priority
70- Endpoint string
64+ Session * Session
65+ Prompt string
66+ HistoryFile string
67+ Credential []byte
68+ InStream io.ReadCloser
69+ OutStream io.Writer
70+ ErrStream io.Writer
71+ Verbose bool
72+ Priority pb.RequestOptions_Priority
73+ Endpoint string
74+ SkipTLSVerify bool
7175}
7276
7377type command struct {
7478 Stmt Statement
7579 Vertical bool
7680}
7781
78- func NewCli (projectId , instanceId , databaseId , prompt , historyFile string , credential []byte , inStream io.ReadCloser , outStream io.Writer , errStream io.Writer , verbose bool , priority pb.RequestOptions_Priority , role string , endpoint string , directedRead * pb.DirectedReadOptions ) (* Cli , error ) {
79- session , err := createSession (projectId , instanceId , databaseId , credential , priority , role , endpoint , directedRead )
82+ func NewCli (projectId , instanceId , databaseId , prompt , historyFile string , credential []byte , inStream io.ReadCloser , outStream io.Writer , errStream io.Writer , verbose bool , priority pb.RequestOptions_Priority , role string , endpoint string , directedRead * pb.DirectedReadOptions , skipTLSVerify bool ) (* Cli , error ) {
83+ session , err := createSession (projectId , instanceId , databaseId , credential , priority , role , endpoint , directedRead , skipTLSVerify )
8084 if err != nil {
8185 return nil , err
8286 }
@@ -90,15 +94,16 @@ func NewCli(projectId, instanceId, databaseId, prompt, historyFile string, crede
9094 }
9195
9296 return & Cli {
93- Session : session ,
94- Prompt : prompt ,
95- HistoryFile : historyFile ,
96- Credential : credential ,
97- InStream : inStream ,
98- OutStream : outStream ,
99- ErrStream : errStream ,
100- Verbose : verbose ,
101- Endpoint : endpoint ,
97+ Session : session ,
98+ Prompt : prompt ,
99+ HistoryFile : historyFile ,
100+ Credential : credential ,
101+ InStream : inStream ,
102+ OutStream : outStream ,
103+ ErrStream : errStream ,
104+ Verbose : verbose ,
105+ Endpoint : endpoint ,
106+ SkipTLSVerify : skipTLSVerify ,
102107 }, nil
103108}
104109
@@ -148,7 +153,7 @@ func (c *Cli) RunInteractive() int {
148153 }
149154
150155 if s , ok := stmt .(* UseStatement ); ok {
151- newSession , err := createSession (c .Session .projectId , c .Session .instanceId , s .Database , c .Credential , c .Priority , s .Role , c .Endpoint , c .Session .directedRead )
156+ newSession , err := createSession (c .Session .projectId , c .Session .instanceId , s .Database , c .Credential , c .Priority , s .Role , c .Endpoint , c .Session .directedRead , c . SkipTLSVerify )
152157 if err != nil {
153158 c .PrintInteractiveError (err )
154159 continue
@@ -310,14 +315,18 @@ func (c *Cli) getInterpolatedPrompt() string {
310315 return prompt
311316}
312317
313- func createSession (projectId string , instanceId string , databaseId string , credential []byte , priority pb.RequestOptions_Priority , role string , endpoint string , directedRead * pb.DirectedReadOptions ) (* Session , error ) {
318+ func createSession (projectId string , instanceId string , databaseId string , credential []byte , priority pb.RequestOptions_Priority , role string , endpoint string , directedRead * pb.DirectedReadOptions , skipTLSVerify bool ) (* Session , error ) {
314319 var opts []option.ClientOption
315320 if credential != nil {
316321 opts = append (opts , option .WithCredentialsJSON (credential ))
317322 }
318323 if endpoint != "" {
319324 opts = append (opts , option .WithEndpoint (endpoint ))
320325 }
326+ if skipTLSVerify {
327+ creds := credentials .NewTLS (& tls.Config {InsecureSkipVerify : true })
328+ opts = append (opts , option .WithGRPCDialOption (grpc .WithTransportCredentials (creds )))
329+ }
321330 return NewSession (projectId , instanceId , databaseId , priority , role , directedRead , opts ... )
322331}
323332
0 commit comments