mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-09 14:09:52 +00:00
Reuse the x509 package
This commit is contained in:
parent
46dccb176e
commit
e2254faf15
@ -2,11 +2,8 @@ package deployer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/x509"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/pem"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@ -15,6 +12,7 @@ import (
|
|||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
|
"github.com/usual2970/certimate/internal/pkg/utils/x509"
|
||||||
)
|
)
|
||||||
|
|
||||||
type K8sSecretDeployer struct {
|
type K8sSecretDeployer struct {
|
||||||
@ -69,13 +67,10 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context) error {
|
|||||||
if secretDataKeyForKey == "" {
|
if secretDataKeyForKey == "" {
|
||||||
namespace = "tls.key"
|
namespace = "tls.key"
|
||||||
}
|
}
|
||||||
block, _ := pem.Decode([]byte(d.option.Certificate.Certificate))
|
|
||||||
if block == nil {
|
certificate, err := x509.ParseCertificateFromPEM(d.option.Certificate.Certificate)
|
||||||
return fmt.Errorf("failed to parse certificate PEM")
|
|
||||||
}
|
|
||||||
cert, err := x509.ParseCertificate(block.Bytes)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to parse certificate: " + err.Error())
|
return fmt.Errorf("failed to parse certificate: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
secretPayload := corev1.Secret{
|
secretPayload := corev1.Secret{
|
||||||
@ -87,9 +82,9 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context) error {
|
|||||||
Name: secretName,
|
Name: secretName,
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"certimate/domains": d.option.Domain,
|
"certimate/domains": d.option.Domain,
|
||||||
"certimate/alt-names": strings.Join(cert.DNSNames, ","),
|
"certimate/alt-names": strings.Join(certificate.DNSNames, ","),
|
||||||
"certimate/common-name": cert.Subject.CommonName,
|
"certimate/common-name": certificate.Subject.CommonName,
|
||||||
"certimate/issuer-organization": strings.Join(cert.Issuer.Organization, ","),
|
"certimate/issuer-organization": strings.Join(certificate.Issuer.Organization, ","),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Type: corev1.SecretType("kubernetes.io/tls"),
|
Type: corev1.SecretType("kubernetes.io/tls"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user