Skip to content

Commit

Permalink
chore: add tls option to client initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
felipejfc committed Aug 1, 2024
1 parent d18fbe4 commit e193155
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
30 changes: 9 additions & 21 deletions xk6-pitaya/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,26 @@ type Client struct {
pushes map[string]chan []byte
timeout time.Duration
metrics *pitayaMetrics
useTLS bool
}

// ConnectTls connects to the server with a basic tls config
// Connect connects to the server
// addr is the address of the server to connect to
func (c *Client) ConnectTls(addr string) error {
func (c *Client) Connect(addr string) error {
vuState := c.vu.State()

if vuState == nil {
return errors.New("connecting to a pitaya server in the init context is not supported")
}

config := &tls.Config{GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) { return nil, nil }, InsecureSkipVerify: true}

err := c.client.ConnectTo(addr, config)
if err != nil {
return err
}
go c.listen()

return err
}

// Connect connects to the server
// addr is the address of the server to connect to
func (c *Client) Connect(addr string) error { //TODO: tls Options
vuState := c.vu.State()

if vuState == nil {
return errors.New("connecting to a pitaya server in the init context is not supported")
var err error
if c.useTLS {
tlsConfig := &tls.Config{GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) { return nil, nil }, InsecureSkipVerify: true}
err = c.client.ConnectTo(addr, tlsConfig)
} else {
err = c.client.ConnectTo(addr)
}

err := c.client.ConnectTo(addr)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions xk6-pitaya/examples/scenario1.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const opts = {
}
},
requestTimeoutMs: 1000,
useTLS: false,
}

const pitayaClient = new pitaya.Client(opts)
Expand Down

0 comments on commit e193155

Please sign in to comment.