Skip to content

Commit

Permalink
Add mutual authentication settings for resty (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
razbomi authored and FrancoisPoinsot committed Jun 1, 2019
1 parent a3b9cb6 commit 0384154
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
10 changes: 10 additions & 0 deletions cli/cmd/helper.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package cmd

import (
"crypto/tls"
"encoding/json"
"fmt"
"github.com/ricardo-ch/go-kafka-connect/lib/connectors"
"log"
)

func printResponse(response interface{}) error {
Expand All @@ -23,5 +25,13 @@ func getClient() connectors.HighLevelClient {
if SSLInsecure {
client.SetInsecureSSL()
}
if len(SSLClientCertificate) > 0 && len(SSLClientPrivateKey) > 0 {
cert, err := tls.LoadX509KeyPair(SSLClientCertificate, SSLClientPrivateKey)
if err != nil {
log.Fatalf("client: loadkeys: %s", err)
} else {
client.SetClientCertificates(cert)
}
}
return client
}
26 changes: 15 additions & 11 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ import (
)

var (
url string
connector string
filePath string
configString string
sync bool
status bool
config bool
tasks bool
verbose bool
SSLInsecure bool
parallel int
url string
connector string
filePath string
configString string
sync bool
status bool
config bool
tasks bool
verbose bool
SSLInsecure bool
parallel int
SSLClientCertificate string
SSLClientPrivateKey string
)

var RootCmd = &cobra.Command{
Expand All @@ -56,4 +58,6 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&url, "url", "u", "http://localhost:8083", "kafka connect URL")
RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, `/!\ very verbose`)
RootCmd.PersistentFlags().BoolVarP(&SSLInsecure, "insecure-skip-verify", "i", false, `skip SSL/TLS verification`)
RootCmd.PersistentFlags().StringVarP(&SSLClientCertificate, "ssl-client-certificate", "C", "", `client certificate, must contain PEM encoded data`)
RootCmd.PersistentFlags().StringVarP(&SSLClientPrivateKey, "ssl-client-key", "K", "", `client private key`)
}
5 changes: 5 additions & 0 deletions lib/connectors/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type BaseClient interface {

SetInsecureSSL()
SetDebug()
SetClientCertificates(certs ...tls.Certificate)
}

type baseClient struct {
Expand All @@ -42,6 +43,10 @@ func (c *baseClient) SetDebug() {
c.restClient.SetDebug(true)
}

func (c *baseClient) SetClientCertificates(certs ...tls.Certificate) {
c.restClient.SetCertificates(certs...)
}

//ErrorResponse is generic error returned by kafka connect
type ErrorResponse struct {
ErrorCode int `json:"error_code,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions lib/connectors/highlevel_client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package connectors

import (
"crypto/tls"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -32,6 +33,7 @@ type HighLevelClient interface {
DeployMultipleConnector(connectors []CreateConnectorRequest) (err error)
SetInsecureSSL()
SetDebug()
SetClientCertificates(certs ...tls.Certificate)
SetParallelism(value int)
}

Expand Down Expand Up @@ -59,6 +61,10 @@ func (c *highLevelClient) SetDebug() {
c.client.SetDebug()
}

func (c *highLevelClient) SetClientCertificates(certs ...tls.Certificate) {
c.client.SetClientCertificates(certs...)
}

//GetAll gets the list of all active connectors
func (c *highLevelClient) GetAll() (GetAllConnectorsResponse, error) {
return c.client.GetAll()
Expand Down
5 changes: 5 additions & 0 deletions lib/connectors/mock_base_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0384154

Please sign in to comment.