Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ca cert #35

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CDK_TOKEN=<admin-token>
````
You need to define the CDK_TOKEN and CDK_BASE_URL environment variables to use this tool.
You can also use the CDK_KEY,CDK_CERT to use a certificate for tls authentication.
If you have an untrusted certificate you can use the CDK_INSECURE=true variable to disable tls verification
If you have an untrusted certificate you can use the CDK_INSECURE=true variable to disable tls verification or you can use CACERT.

Usage:
conduktor [flags]
Expand Down
9 changes: 7 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Client struct {
kinds schema.KindCatalog
}

func Make(token string, baseUrl string, debug bool, key, cert string, insecure bool) (*Client, error) {
func Make(token string, baseUrl string, debug bool, key, cert, cacert string, insecure bool) (*Client, error) {
//token is set later because it's not mandatory for getting the openapi and parsing different kind
restyClient := resty.New().SetDebug(debug).SetHeader("X-CDK-CLIENT", "CLI/"+utils.GetConduktorVersion())

Expand All @@ -34,6 +34,10 @@ func Make(token string, baseUrl string, debug bool, key, cert string, insecure b
}
}

if cacert != "" {
restyClient.SetRootCertificate(cacert)
}

result := &Client{
token: token,
baseUrl: baseUrl,
Expand Down Expand Up @@ -69,9 +73,10 @@ func MakeFromEnv() (*Client, error) {
debug := strings.ToLower(os.Getenv("CDK_DEBUG")) == "true"
key := os.Getenv("CDK_KEY")
cert := os.Getenv("CDK_CERT")
cacert := os.Getenv("CDK_CACERT")
insecure := strings.ToLower(os.Getenv("CDK_INSECURE")) == "true"

client, err := Make("", baseUrl, debug, key, cert, insecure)
client, err := Make("", baseUrl, debug, key, cert, cacert, insecure)
if err != nil {
return nil, fmt.Errorf("Cannot create client: %s", err)
}
Expand Down
18 changes: 9 additions & 9 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestApplyShouldWork(t *testing.T) {
defer httpmock.Reset()
baseUrl := "http://baseUrl"
token := "aToken"
client, err := Make(token, baseUrl, false, "", "", false)
client, err := Make(token, baseUrl, false, "", "", "", false)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestApplyWithDryModeShouldWork(t *testing.T) {
defer httpmock.Reset()
baseUrl := "http://baseUrl"
token := "aToken"
client, err := Make(token, baseUrl, false, "", "", false)
client, err := Make(token, baseUrl, false, "", "", "", false)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestApplyShouldFailIfNo2xx(t *testing.T) {
defer httpmock.Reset()
baseUrl := "http://baseUrl"
token := "aToken"
client, err := Make(token, baseUrl, false, "", "", false)
client, err := Make(token, baseUrl, false, "", "", "", false)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestGetShouldWork(t *testing.T) {
defer httpmock.Reset()
baseUrl := "http://baseUrl"
token := "aToken"
client, err := Make(token, baseUrl, false, "", "", false)
client, err := Make(token, baseUrl, false, "", "", "", false)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestGetShouldFailIfN2xx(t *testing.T) {
defer httpmock.Reset()
baseUrl := "http://baseUrl"
token := "aToken"
client, err := Make(token, baseUrl, false, "", "", false)
client, err := Make(token, baseUrl, false, "", "", "", false)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestDescribeShouldWork(t *testing.T) {
defer httpmock.Reset()
baseUrl := "http://baseUrl"
token := "aToken"
client, err := Make(token, baseUrl, false, "", "", false)
client, err := Make(token, baseUrl, false, "", "", "", false)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestDescribeShouldFailIfNo2xx(t *testing.T) {
defer httpmock.Reset()
baseUrl := "http://baseUrl/api"
token := "aToken"
client, err := Make(token, baseUrl, false, "", "", false)
client, err := Make(token, baseUrl, false, "", "", "", false)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -256,7 +256,7 @@ func TestDeleteShouldWork(t *testing.T) {
defer httpmock.Reset()
baseUrl := "http://baseUrl"
token := "aToken"
client, err := Make(token, baseUrl, false, "", "", false)
client, err := Make(token, baseUrl, false, "", "", "", false)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func TestDeleteShouldFailOnNot2XX(t *testing.T) {
defer httpmock.Reset()
baseUrl := "http://baseUrl"
token := "aToken"
client, err := Make(token, baseUrl, false, "", "", false)
client, err := Make(token, baseUrl, false, "", "", "", false)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var rootCmd = &cobra.Command{
Use: "conduktor",
Short: "Command line tools for conduktor",
Long: `You need to define the CDK_TOKEN and CDK_BASE_URL environment variables to use this tool.
You can also use the CDK_KEY,CDK_CERT to use a certificate for tls authentication.
If you have an untrusted certificate you can use the CDK_INSECURE=true variable to disable tls verification`,
You can also use the CDK_KEY,CDK_CERT, CDK_CACERT to use a certificate for tls authentication.
If you have an untrusted certificate you can use the CDK_INSECURE=true variable to disable tls verification or set CDK_CACERT`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if *debug {
apiClient().ActivateDebug()
Expand Down
Loading