Skip to content

Commit 1675998

Browse files
committed
Add support for OS_INSECURE environment variable
When calling NewServiceClient it was not possible to configure TLS certificate validation using environment variables. This change adds support for the `OS_INSECURE` environment variable, which is parsed as a boolean value. When truthy, we disable certificate validation. Signed-off-by: Lars Kellogg-Stedman <lars@redhat.com>
1 parent 1d7954e commit 1675998

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

openstack/clientconfig/requests.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99
"reflect"
10+
"strconv"
1011
"strings"
1112

1213
"github.com/gophercloud/gophercloud/v2"
@@ -808,9 +809,17 @@ func NewServiceClient(ctx context.Context, service string, opts *ClientOpts) (*g
808809
}
809810

810811
// Define whether or not SSL API requests should be verified.
812+
// First, check if the INSECURE environment variable is set.
811813
var insecurePtr *bool
814+
if v := env.Getenv(envPrefix + "INSECURE"); v != "" {
815+
insecure, err := strconv.ParseBool(v)
816+
if err != nil {
817+
return nil, fmt.Errorf("failed to parse %sINSECURE: %w", envPrefix, err)
818+
}
819+
insecurePtr = &insecure
820+
}
821+
// Next, check if the cloud entry sets verify (inverted to insecure).
812822
if cloud.Verify != nil {
813-
// Here we take the boolean pointer negation.
814823
insecure := !*cloud.Verify
815824
insecurePtr = &insecure
816825
}

0 commit comments

Comments
 (0)