mirror of
https://github.com/ribbybibby/ssl_exporter.git
synced 2026-08-26 02:57:19 +00:00
Move to a modules/probers model, like the blackbox_exporter. (#34)
There are a number of reasons for this change: - Modules allow a single instance of the exporter to be configured with numerous different tls configs. Previously you had to run a different exporter for each combination. - Adding new and more complicated options to the exporter should be easier with modules than if I was to go down the route of accepting configuration directly through url params - I prefer defining a specific prober (https,tcp) over using the URL to guess what the user wants
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SetupHTTPSServer sets up a server for testing with a generated cert and key
|
||||
// pair. It returns the server, the cert and key, the path to the ca file and a
|
||||
// function to clean up the server.
|
||||
func SetupHTTPSServer() (*httptest.Server, []byte, []byte, string, func(), error) {
|
||||
var teardown func()
|
||||
|
||||
testcertPEM, testkeyPEM := GenerateTestCertificate(time.Now().AddDate(0, 0, 1))
|
||||
|
||||
caFile, err := WriteFile("certfile.pem", testcertPEM)
|
||||
if err != nil {
|
||||
return nil, testcertPEM, testkeyPEM, caFile, teardown, err
|
||||
}
|
||||
|
||||
teardown = func() {
|
||||
os.Remove(caFile)
|
||||
}
|
||||
|
||||
// Create server
|
||||
testcert, err := tls.X509KeyPair(testcertPEM, testkeyPEM)
|
||||
if err != nil {
|
||||
return nil, testcertPEM, testkeyPEM, caFile, teardown, err
|
||||
}
|
||||
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "Hello world")
|
||||
}))
|
||||
server.TLS = &tls.Config{
|
||||
Certificates: []tls.Certificate{testcert},
|
||||
}
|
||||
|
||||
return server, testcertPEM, testkeyPEM, caFile, teardown, nil
|
||||
}
|
||||
Reference in New Issue
Block a user