Skip to content

Commit

Permalink
Merge pull request #18 from Infisical/feature/allow-custom-ca-certifi…
Browse files Browse the repository at this point in the history
…cate

feat: allow custom ca certificate
  • Loading branch information
sheensantoscapadngan authored Oct 28, 2024
2 parents c408b17 + 324dcb1 commit 97d50fa
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package infisical

import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"reflect"
Expand Down Expand Up @@ -43,6 +45,7 @@ type InfisicalClientInterface interface {

type Config struct {
SiteUrl string `default:"https://app.infisical.com"`
CaCertificate string
UserAgent string `default:"infisical-go-sdk"` // User-Agent header to be used on requests sent by the SDK. Defaults to `infisical-go-sdk`. Do not modify this unless you have a reason to do so.
AutoTokenRefresh bool `default:"true"` // Wether or not to automatically refresh the auth token after using one of the .Auth() methods. Defaults to `true`.
SilentMode bool `default:"false"` // If enabled, the SDK will not print any warnings to the console.
Expand Down Expand Up @@ -135,11 +138,29 @@ func (c *InfisicalClient) UpdateConfiguration(config Config) {
c.httpClient = resty.New().
SetHeader("User-Agent", config.UserAgent).
SetBaseURL(config.SiteUrl)

} else {
c.httpClient.
SetHeader("User-Agent", config.UserAgent).
SetBaseURL(config.SiteUrl)
}

if config.CaCertificate != "" {
caCertPool, err := x509.SystemCertPool()
if err != nil && !config.SilentMode {
util.PrintWarning(fmt.Sprintf("failed to load system root CA pool: %v", err))
}

if ok := caCertPool.AppendCertsFromPEM([]byte(config.CaCertificate)); !ok && !config.SilentMode {
util.PrintWarning("failed to append CA certificate")
}

tlsConfig := &tls.Config{
RootCAs: caCertPool,
}

c.httpClient.SetTLSClientConfig(tlsConfig)
}
}

func (c *InfisicalClient) Secrets() SecretsInterface {
Expand Down

0 comments on commit 97d50fa

Please sign in to comment.