From ca7aa1f14e367b79349003f5c3f96ca0d867d059 Mon Sep 17 00:00:00 2001 From: Rob Best Date: Mon, 16 Nov 2020 00:48:15 +0000 Subject: [PATCH] Fix golint errors --- config/config.go | 8 ++++++++ prober/file.go | 1 + prober/kubernetes.go | 3 +++ test/test.go | 5 +++++ 4 files changed, 17 insertions(+) diff --git a/config/config.go b/config/config.go index b9b6575..1630802 100644 --- a/config/config.go +++ b/config/config.go @@ -11,6 +11,8 @@ import ( ) var ( + // DefaultConfig is the default configuration that is used when no + // configuration file is provided DefaultConfig = &Config{ map[string]Module{ "tcp": Module{ @@ -32,6 +34,7 @@ var ( } ) +// LoadConfig loads configuration from a file func LoadConfig(confFile string) (*Config, error) { var c *Config @@ -50,10 +53,12 @@ func LoadConfig(confFile string) (*Config, error) { return c, nil } +// Config configures the exporter type Config struct { Modules map[string]Module `yaml:"modules"` } +// Module configures a prober type Module struct { Prober string `yaml:"prober,omitempty"` Timeout time.Duration `yaml:"timeout,omitempty"` @@ -63,14 +68,17 @@ type Module struct { Kubernetes KubernetesProbe `yaml:"kubernetes,omitempty"` } +// TCPProbe configures a tcp probe type TCPProbe struct { StartTLS string `yaml:"starttls,omitempty"` } +// HTTPSProbe configures a https probe type HTTPSProbe struct { ProxyURL URL `yaml:"proxy_url,omitempty"` } +// KubernetesProbe configures a kubernetes probe type KubernetesProbe struct { Kubeconfig string `yaml:"kubeconfig,omitempty"` } diff --git a/prober/file.go b/prober/file.go index 8206cd5..4df90f5 100644 --- a/prober/file.go +++ b/prober/file.go @@ -9,6 +9,7 @@ import ( "github.com/ribbybibby/ssl_exporter/config" ) +// ProbeFile collects certificate metrics from local files func ProbeFile(ctx context.Context, target string, module config.Module, registry *prometheus.Registry) error { errCh := make(chan error, 1) diff --git a/prober/kubernetes.go b/prober/kubernetes.go index 4f18017..3450e9e 100644 --- a/prober/kubernetes.go +++ b/prober/kubernetes.go @@ -18,9 +18,12 @@ import ( ) var ( + // ErrKubeBadTarget is returned when the target doesn't match the + // expected form for the kubernetes prober ErrKubeBadTarget = fmt.Errorf("Target secret must be provided in the form: /") ) +// ProbeKubernetes collects certificate metrics from kubernetes.io/tls Secrets func ProbeKubernetes(ctx context.Context, target string, module config.Module, registry *prometheus.Registry) error { client, err := newKubeClient(module.Kubernetes.Kubeconfig) if err != nil { diff --git a/test/test.go b/test/test.go index c610405..a05ca1b 100644 --- a/test/test.go +++ b/test/test.go @@ -29,6 +29,7 @@ func GenerateTestCertificate(expiry time.Time) ([]byte, []byte) { return pemCert, pemKey } +// GenerateSignedCertificate generates a certificate that is signed func GenerateSignedCertificate(cert, parentCert *x509.Certificate, parentKey *rsa.PrivateKey) (*x509.Certificate, []byte, []byte) { privateKey, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { @@ -49,6 +50,9 @@ func GenerateSignedCertificate(cert, parentCert *x509.Certificate, parentKey *rs pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: derCert}), pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privateKey)}) } + +// GenerateSelfSignedCertificateWithPrivateKey generates a self signed +// certificate with the given private key func GenerateSelfSignedCertificateWithPrivateKey(cert *x509.Certificate, privateKey *rsa.PrivateKey) (*x509.Certificate, []byte) { derCert, err := x509.CreateCertificate(rand.Reader, cert, cert, &privateKey.PublicKey, privateKey) if err != nil { @@ -63,6 +67,7 @@ func GenerateSelfSignedCertificateWithPrivateKey(cert *x509.Certificate, private return genCert, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: derCert}) } +// GenerateCertificateTemplate generates the template used to issue test certificates func GenerateCertificateTemplate(expiry time.Time) *x509.Certificate { return &x509.Certificate{ BasicConstraintsValid: true,