You've already forked ssl_exporter
mirror of
https://github.com/ribbybibby/ssl_exporter.git
synced 2025-07-15 23:54:18 +02:00
Fix golint errors
This commit is contained in:
@ -11,6 +11,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// DefaultConfig is the default configuration that is used when no
|
||||||
|
// configuration file is provided
|
||||||
DefaultConfig = &Config{
|
DefaultConfig = &Config{
|
||||||
map[string]Module{
|
map[string]Module{
|
||||||
"tcp": Module{
|
"tcp": Module{
|
||||||
@ -32,6 +34,7 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// LoadConfig loads configuration from a file
|
||||||
func LoadConfig(confFile string) (*Config, error) {
|
func LoadConfig(confFile string) (*Config, error) {
|
||||||
var c *Config
|
var c *Config
|
||||||
|
|
||||||
@ -50,10 +53,12 @@ func LoadConfig(confFile string) (*Config, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config configures the exporter
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Modules map[string]Module `yaml:"modules"`
|
Modules map[string]Module `yaml:"modules"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Module configures a prober
|
||||||
type Module struct {
|
type Module struct {
|
||||||
Prober string `yaml:"prober,omitempty"`
|
Prober string `yaml:"prober,omitempty"`
|
||||||
Timeout time.Duration `yaml:"timeout,omitempty"`
|
Timeout time.Duration `yaml:"timeout,omitempty"`
|
||||||
@ -63,14 +68,17 @@ type Module struct {
|
|||||||
Kubernetes KubernetesProbe `yaml:"kubernetes,omitempty"`
|
Kubernetes KubernetesProbe `yaml:"kubernetes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TCPProbe configures a tcp probe
|
||||||
type TCPProbe struct {
|
type TCPProbe struct {
|
||||||
StartTLS string `yaml:"starttls,omitempty"`
|
StartTLS string `yaml:"starttls,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HTTPSProbe configures a https probe
|
||||||
type HTTPSProbe struct {
|
type HTTPSProbe struct {
|
||||||
ProxyURL URL `yaml:"proxy_url,omitempty"`
|
ProxyURL URL `yaml:"proxy_url,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KubernetesProbe configures a kubernetes probe
|
||||||
type KubernetesProbe struct {
|
type KubernetesProbe struct {
|
||||||
Kubeconfig string `yaml:"kubeconfig,omitempty"`
|
Kubeconfig string `yaml:"kubeconfig,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/ribbybibby/ssl_exporter/config"
|
"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 {
|
func ProbeFile(ctx context.Context, target string, module config.Module, registry *prometheus.Registry) error {
|
||||||
errCh := make(chan error, 1)
|
errCh := make(chan error, 1)
|
||||||
|
|
||||||
|
@ -18,9 +18,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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: <namespace>/<name>")
|
ErrKubeBadTarget = fmt.Errorf("Target secret must be provided in the form: <namespace>/<name>")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ProbeKubernetes collects certificate metrics from kubernetes.io/tls Secrets
|
||||||
func ProbeKubernetes(ctx context.Context, target string, module config.Module, registry *prometheus.Registry) error {
|
func ProbeKubernetes(ctx context.Context, target string, module config.Module, registry *prometheus.Registry) error {
|
||||||
client, err := newKubeClient(module.Kubernetes.Kubeconfig)
|
client, err := newKubeClient(module.Kubernetes.Kubeconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -29,6 +29,7 @@ func GenerateTestCertificate(expiry time.Time) ([]byte, []byte) {
|
|||||||
return pemCert, pemKey
|
return pemCert, pemKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateSignedCertificate generates a certificate that is signed
|
||||||
func GenerateSignedCertificate(cert, parentCert *x509.Certificate, parentKey *rsa.PrivateKey) (*x509.Certificate, []byte, []byte) {
|
func GenerateSignedCertificate(cert, parentCert *x509.Certificate, parentKey *rsa.PrivateKey) (*x509.Certificate, []byte, []byte) {
|
||||||
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||||
if err != nil {
|
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: "CERTIFICATE", Bytes: derCert}),
|
||||||
pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privateKey)})
|
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) {
|
func GenerateSelfSignedCertificateWithPrivateKey(cert *x509.Certificate, privateKey *rsa.PrivateKey) (*x509.Certificate, []byte) {
|
||||||
derCert, err := x509.CreateCertificate(rand.Reader, cert, cert, &privateKey.PublicKey, privateKey)
|
derCert, err := x509.CreateCertificate(rand.Reader, cert, cert, &privateKey.PublicKey, privateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -63,6 +67,7 @@ func GenerateSelfSignedCertificateWithPrivateKey(cert *x509.Certificate, private
|
|||||||
return genCert, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: derCert})
|
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 {
|
func GenerateCertificateTemplate(expiry time.Time) *x509.Certificate {
|
||||||
return &x509.Certificate{
|
return &x509.Certificate{
|
||||||
BasicConstraintsValid: true,
|
BasicConstraintsValid: true,
|
||||||
|
Reference in New Issue
Block a user