Skip to content

Commit

Permalink
Merge pull request #2 from homedepot/rancher-cacert
Browse files Browse the repository at this point in the history
Trust Rancher Cert
  • Loading branch information
billiford authored Apr 5, 2021
2 parents a08b616 + 4d91002 commit c681122
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions cmd/arcade/arcade.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package main

import (
"crypto/tls"
"crypto/x509"
"log"
"net/http"
"os"

"github.com/gin-gonic/gin"
"github.com/homedepot/arcade/pkg/google"
"github.com/homedepot/arcade/pkg/http"
arcadehttp "github.com/homedepot/arcade/pkg/http"
"github.com/homedepot/arcade/pkg/middleware"
"github.com/homedepot/arcade/pkg/rancher"
)
Expand All @@ -29,7 +32,7 @@ func init() {
r.Use(middleware.SetRancherClient(rancherClient))
}

r.GET("/tokens", http.GetToken)
r.GET("/tokens", arcadehttp.GetToken)
}

func mustGetenv(env string) (s string) {
Expand All @@ -41,14 +44,31 @@ func mustGetenv(env string) (s string) {
}

func mustInstantiateRancherClient() rancher.Client {
rancherURL := mustGetenv("RANCHER_URL")
rancherUsername := mustGetenv("RANCHER_USERNAME")
rancherPassword := mustGetenv("RANCHER_PASSWORD")
url := mustGetenv("RANCHER_URL")
username := mustGetenv("RANCHER_USERNAME")
password := mustGetenv("RANCHER_PASSWORD")

rancherClient := rancher.NewClient()
rancherClient.WithURL(rancherURL)
rancherClient.WithUsername(rancherUsername)
rancherClient.WithPassword(rancherPassword)
rancherClient.WithURL(url)
rancherClient.WithUsername(username)
rancherClient.WithPassword(password)

if caCerts := os.Getenv("RANCHER_CACERTS"); caCerts != "" {
rootCAs, _ := x509.SystemCertPool()
if rootCAs == nil {
rootCAs = x509.NewCertPool()
}

rootCAs.AppendCertsFromPEM([]byte(caCerts))

t := &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: rootCAs,
},
}

rancherClient.WithTransport(t)
}

return rancherClient
}
Expand Down

0 comments on commit c681122

Please sign in to comment.