Skip to content

Commit dfc2311

Browse files
committedJan 25, 2025·
vcsim: add env var for use with ssoadmin GetTrustedCertificates
1 parent f98426f commit dfc2311

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed
 

‎ssoadmin/simulator/simulator.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
package simulator
66

77
import (
8+
"encoding/base64"
9+
"encoding/pem"
10+
"log"
811
"net/url"
12+
"os"
913
"strings"
1014

1115
"github.com/vmware/govmomi/simulator"
@@ -248,7 +252,25 @@ func (*ConfigurationManagementService) GetTrustedCertificates(ctx *simulator.Con
248252

249253
var res []string
250254

251-
if m.TLSCert != nil {
255+
// TODO: consider adding a vcsim -tlscacerts flag
256+
cacerts := os.Getenv("VCSIM_CACERTS")
257+
if cacerts != "" {
258+
pemCerts, err := os.ReadFile(cacerts)
259+
if err != nil {
260+
log.Fatal(err)
261+
}
262+
for len(pemCerts) > 0 {
263+
var block *pem.Block
264+
block, pemCerts = pem.Decode(pemCerts)
265+
if block == nil {
266+
break
267+
}
268+
if block.Type != "CERTIFICATE" || len(block.Headers) != 0 {
269+
continue
270+
}
271+
res = append(res, base64.StdEncoding.EncodeToString(block.Bytes))
272+
}
273+
} else if m.TLSCert != nil {
252274
res = append(res, m.TLSCert())
253275
}
254276

0 commit comments

Comments
 (0)
Please sign in to comment.