From 9be34f49f530746fdc767edb82c1421be7dbefc8 Mon Sep 17 00:00:00 2001 From: Daniel Cleyrat Date: Tue, 28 Mar 2023 07:39:03 -0700 Subject: [PATCH] use KubectlConfig for insecure --- README.md | 4 ++-- cmd/datactl/app/sources/add/add_dataservice.go | 7 +++++-- cmd/datactl/app/sources/add/add_datasource_test.go | 12 +++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b764e54..3f8e922 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Recommended approach is to run the commands in this order: // Must be logged in to the cluster // Add the dataservice as a source, to which you are logged into with your current context -datactl sources add dataservice --use-default-context --allow-self-signed=true --namespace=redhat-marketplace +datactl sources add dataservice --use-default-context --insecure-skip-tls-verify=true --allow-self-signed=true --namespace=redhat-marketplace // Pull the data from dataservice sources oc datactl export pull --source-type=dataservice @@ -78,7 +78,7 @@ oc datactl export commit Let's break down what each one is doing. -`oc datactl sources add dataservice --use-default-context --allow-self-signed=true --namespace=redhat-marketplace` +`oc datactl sources add dataservice --use-default-context --insecure-skip-tls-verify=true --allow-self-signed=true --namespace=redhat-marketplace` - Adds the default-context cluster's dataservice as a source for pulling - Writes the source data-service-endpoint to `~/.datactl/config` diff --git a/cmd/datactl/app/sources/add/add_dataservice.go b/cmd/datactl/app/sources/add/add_dataservice.go index 68c1623..8651081 100644 --- a/cmd/datactl/app/sources/add/add_dataservice.go +++ b/cmd/datactl/app/sources/add/add_dataservice.go @@ -33,8 +33,11 @@ var ( The command will attempt to resolve the Dataservice URL using the kubernetes context provided.`)) configInitExample = templates.Examples(i18n.T(` - # Initialize the source, using the default context and a self signed cert. - {{ .cmd }} sources add dataservice --use-default-context --allow-self-signed=true --namespace=redhat-marketplace + # Initialize the source, using the default context. + {{ .cmd }} sources add dataservice --use-default-context --namespace=redhat-marketplace + + # Initialize the source, using the default context and insecure self signed cert. + {{ .cmd }} sources add dataservice --use-default-context --insecure-skip-tls-verify=true --allow-self-signed=true --namespace=redhat-marketplace # Initialize the config, prompting for a context to select. {{ .cmd }} sources add dataservice diff --git a/cmd/datactl/app/sources/add/add_datasource_test.go b/cmd/datactl/app/sources/add/add_datasource_test.go index 135f3ce..d792120 100644 --- a/cmd/datactl/app/sources/add/add_datasource_test.go +++ b/cmd/datactl/app/sources/add/add_datasource_test.go @@ -4,13 +4,17 @@ import ( "crypto/x509" "strings" + "github.com/gotidy/ptr" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/onsi/gomega/ghttp" "github.com/redhat-marketplace/datactl/pkg/datactl/api" + "github.com/redhat-marketplace/datactl/pkg/datactl/config" + "k8s.io/cli-runtime/pkg/genericclioptions" ) var _ = Describe("config init", func() { + It("should handle self signed certificates", func() { server := ghttp.NewTLSServer() @@ -18,6 +22,13 @@ var _ = Describe("config init", func() { url = strings.TrimPrefix(url, "https://") init := &addDataServiceOptions{} + + init.rhmConfigFlags = &config.ConfigFlags{} + + init.rhmConfigFlags.KubectlConfig = &genericclioptions.ConfigFlags{ + Insecure: ptr.Bool(true), + } + init.dataServiceConfig = &api.DataServiceEndpoint{ Host: url, } @@ -26,7 +37,6 @@ var _ = Describe("config init", func() { Expect(err).To(HaveOccurred()) init.allowSelfsigned = true - init.dataServiceConfig.InsecureSkipTLSVerify = true err = init.discoverDataServiceCA() Expect(err).To(Succeed()) Expect(init.dataServiceConfig.CertificateAuthorityData).ToNot(BeEmpty())