Skip to content

Commit

Permalink
Fix golint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ribbybibby committed Nov 16, 2020
1 parent 13a03b1 commit ca7aa1f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -32,6 +34,7 @@ var (
}
)

// LoadConfig loads configuration from a file
func LoadConfig(confFile string) (*Config, error) {
var c *Config

Expand All @@ -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"`
Expand All @@ -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"`
}
Expand Down
1 change: 1 addition & 0 deletions prober/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions prober/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: <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 {
client, err := newKubeClient(module.Kubernetes.Kubeconfig)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit ca7aa1f

Please sign in to comment.