Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple certificates on same file for x509 input #6695

Merged
merged 2 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions plugins/inputs/x509_cert/x509_cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,24 @@ func (c *X509Cert) getCert(u *url.URL, timeout time.Duration) ([]*x509.Certifica
if err != nil {
return nil, err
}
var certs []*x509.Certificate
for {
block, rest := pem.Decode(content)
if block == nil {
return nil, fmt.Errorf("failed to parse certificate PEM")
jonathannegrin marked this conversation as resolved.
Show resolved Hide resolved
}

block, _ := pem.Decode(content)
if block == nil {
return nil, fmt.Errorf("failed to parse certificate PEM")
}

cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, err
cert, err := x509.ParseCertificate(block.Bytes)
if err != nil {
return nil, err
}
certs = append(certs, cert)
if rest == nil || len(rest) == 0 {
break
}
content = rest
}

return []*x509.Certificate{cert}, nil
return certs, nil
default:
return nil, fmt.Errorf("unsuported scheme '%s' in location %s", u.Scheme, u.String())
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/x509_cert/x509_cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestGatherLocal(t *testing.T) {
{name: "permission denied", mode: 0001, error: true},
{name: "not a certificate", mode: 0640, content: "test", error: true},
{name: "wrong certificate", mode: 0640, content: wrongCert, error: true},
{name: "correct certificate", mode: 0640, content: pki.ReadServerCert()},
{name: "correct certificate", mode: 0640, content: pki.ReadServerCert() + pki.ReadCACert()},
jonathannegrin marked this conversation as resolved.
Show resolved Hide resolved
}

for _, test := range tests {
Expand Down