You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rootCmd.PersistentFlags().BoolVar(&logHTTP, "log-http", false, "Set to true to log HTTP requests. This can be helpful when attempting to write your own code or debug.")
66
67
rootCmd.PersistentFlags().BoolVar(&dryRun, "dry-run", false, "Set to true to not make any changes. This can be helpful when paired with log-http to just view http requests instead of perform them.")
67
68
rootCmd.PersistentFlags().BoolVar(&insecure, "insecure", false, "Set to true to skip TLS certificate verification. Use with caution.")
69
+
rootCmd.PersistentFlags().StringVar(&caCertPath, "ca-cert", "", "Path to custom CA certificate file (PEM format) to add to the trusted certificate pool")
68
70
rootCmd.PersistentFlags().StringVar(&pathPrefix, "path-prefix", "", "Specify a path prefix that is prepended to all paths in the openapi schema. This will strip them when evaluating the resource hierarchy paths.")
69
71
rootCmd.PersistentFlags().StringVar(&serverURL, "server-url", "", "Specify a URL to use for the server. If not specified, the first server URL in the OpenAPI definition will be used.")
70
72
rootCmd.PersistentFlags().StringVar(&configFileVar, "config", "", "Path to config file")
// Return system CA pool when no custom CA is specified
16
+
returnx509.SystemCertPool()
17
+
}
18
+
19
+
slog.Debug("Loading custom CA certificate", "path", caCertPath)
20
+
21
+
// Read the CA certificate file
22
+
caCertData, err:=os.ReadFile(caCertPath)
23
+
iferr!=nil {
24
+
ifos.IsNotExist(err) {
25
+
returnnil, fmt.Errorf("Failed to read CA certificate from %s: file does not exist\n\nTo fix this issue:\n 1. Verify the file path is correct\n 2. Ensure the file exists and is readable", caCertPath)
26
+
}
27
+
ifos.IsPermission(err) {
28
+
returnnil, fmt.Errorf("Failed to read CA certificate from %s: permission denied\n\nTo fix this issue:\n 1. Verify you have read permissions for the file\n 2. Check file permissions with: ls -l %s", caCertPath, caCertPath)
29
+
}
30
+
returnnil, fmt.Errorf("Failed to read CA certificate from %s: %v", caCertPath, err)
31
+
}
32
+
33
+
// Start with system CA certificates
34
+
caCertPool, err:=x509.SystemCertPool()
35
+
iferr!=nil {
36
+
slog.Warn("Failed to load system CA certificates, using empty pool", "error", err)
37
+
caCertPool=x509.NewCertPool()
38
+
} else {
39
+
slog.Debug("System CA certificates loaded from system trust store")
40
+
}
41
+
42
+
// Parse the PEM block first to validate format
43
+
block, _:=pem.Decode(caCertData)
44
+
ifblock==nil||block.Type!="CERTIFICATE" {
45
+
returnnil, fmt.Errorf("Failed to parse CA certificate from %s: not valid PEM format\n\nExpected format:\n -----BEGIN CERTIFICATE-----\n ...\n -----END CERTIFICATE-----\n\nUse 'openssl x509 -in %s -text -noout' to verify the certificate.", caCertPath, caCertPath)
46
+
}
47
+
48
+
// Parse the certificate to ensure it's valid
49
+
_, err=x509.ParseCertificate(block.Bytes)
50
+
iferr!=nil {
51
+
returnnil, fmt.Errorf("Failed to parse CA certificate from %s: invalid certificate data: %v\n\nUse 'openssl x509 -in %s -text -noout' to verify the certificate.", caCertPath, err, caCertPath)
52
+
}
53
+
54
+
// Add the custom CA certificate
55
+
if!caCertPool.AppendCertsFromPEM(caCertData) {
56
+
returnnil, fmt.Errorf("Failed to add CA certificate from %s to certificate pool", caCertPath)
57
+
}
58
+
59
+
slog.Debug("Custom CA certificate loaded", "path", caCertPath)
0 commit comments