Skip to content

Commit

Permalink
use KubectlConfig for insecure
Browse files Browse the repository at this point in the history
  • Loading branch information
dacleyra committed Mar 28, 2023
1 parent 4cf5a4c commit 9be34f4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand Down
7 changes: 5 additions & 2 deletions cmd/datactl/app/sources/add/add_dataservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion cmd/datactl/app/sources/add/add_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ 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()

url := server.URL()
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,
}
Expand All @@ -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())
Expand Down

0 comments on commit 9be34f4

Please sign in to comment.