@@ -66,6 +66,7 @@ type Signer interface {
6666 Sign (context.Context , []byte , K8sMetadata ) ([]byte , []byte , error )
6767}
6868
69+ // CommandHealthCheckerFromIssuerAndSecretData creates a new HealthChecker instance using the provided issuer spec and secret data
6970func CommandHealthCheckerFromIssuerAndSecretData (ctx context.Context , spec * commandissuer.IssuerSpec , authSecretData map [string ][]byte , caSecretData map [string ][]byte ) (HealthChecker , error ) {
7071 signer := commandSigner {}
7172
@@ -79,10 +80,13 @@ func CommandHealthCheckerFromIssuerAndSecretData(ctx context.Context, spec *comm
7980 return & signer , nil
8081}
8182
83+ // CommandSignerFromIssuerAndSecretData is a wrapper for commandSignerFromIssuerAndSecretData that returns a Signer interface
84+ // given the provided issuer spec and secret data
8285func CommandSignerFromIssuerAndSecretData (ctx context.Context , spec * commandissuer.IssuerSpec , annotations map [string ]string , authSecretData map [string ][]byte , caSecretData map [string ][]byte ) (Signer , error ) {
8386 return commandSignerFromIssuerAndSecretData (ctx , spec , annotations , authSecretData , caSecretData )
8487}
8588
89+ // commandSignerFromIssuerAndSecretData creates a new Signer instance using the provided issuer spec and secret data
8690func commandSignerFromIssuerAndSecretData (ctx context.Context , spec * commandissuer.IssuerSpec , annotations map [string ]string , authSecretData map [string ][]byte , caSecretData map [string ][]byte ) (* commandSigner , error ) {
8791 k8sLog := log .FromContext (ctx )
8892
@@ -132,6 +136,7 @@ func commandSignerFromIssuerAndSecretData(ctx context.Context, spec *commandissu
132136 return & signer , nil
133137}
134138
139+ // extractMetadataFromAnnotations extracts metadata from the provided annotations
135140func extractMetadataFromAnnotations (annotations map [string ]string ) map [string ]interface {} {
136141 metadata := make (map [string ]interface {})
137142
@@ -144,6 +149,7 @@ func extractMetadataFromAnnotations(annotations map[string]string) map[string]in
144149 return metadata
145150}
146151
152+ // Check checks the health of the signer by verifying that the "POST /Enrollment/CSR" endpoint exists
147153func (s * commandSigner ) Check () error {
148154 endpoints , _ , err := s .client .StatusApi .StatusGetEndpoints (context .Background ()).Execute ()
149155 if err != nil {
@@ -169,6 +175,7 @@ func (s *commandSigner) Check() error {
169175 return errors .New ("missing \" POST /Enrollment/CSR\" endpoint" )
170176}
171177
178+ // Sign signs the provided CSR using the Keyfactor Command API
172179func (s * commandSigner ) Sign (ctx context.Context , csrBytes []byte , k8sMeta K8sMetadata ) ([]byte , []byte , error ) {
173180 k8sLog := log .FromContext (ctx )
174181
@@ -255,6 +262,8 @@ func (s *commandSigner) Sign(ctx context.Context, csrBytes []byte, k8sMeta K8sMe
255262 return compileCertificatesToPemBytes (certAndChain )
256263}
257264
265+ // getCertificatesFromCertificateInformation takes a keyfactor.ModelsPkcs10CertificateResponse object and
266+ // returns a slice of x509 certificates
258267func getCertificatesFromCertificateInformation (commandResp * keyfactor.ModelsPkcs10CertificateResponse ) ([]* x509.Certificate , error ) {
259268 var certBytes []byte
260269
@@ -314,6 +323,7 @@ const (
314323 CommandMetaCertificateSigningRequestNamespace = "Certificate-Signing-Request-Namespace"
315324)
316325
326+ // createCommandClientFromSecretData creates a new Keyfactor Command client using the provided issuer spec and secret data
317327func createCommandClientFromSecretData (ctx context.Context , spec * commandissuer.IssuerSpec , authSecretData map [string ][]byte , caSecretData map [string ][]byte ) (* keyfactor.APIClient , error ) {
318328 k8sLogger := log .FromContext (ctx )
319329
@@ -383,6 +393,7 @@ func createCommandClientFromSecretData(ctx context.Context, spec *commandissuer.
383393 return client , nil
384394}
385395
396+ // decodePEMBytes takes a byte array containing PEM encoded data and returns a slice of PEM blocks and a private key PEM block
386397func decodePEMBytes (buf []byte ) ([]* pem.Block , * pem.Block ) {
387398 var privKey * pem.Block
388399 var certificates []* pem.Block
@@ -400,6 +411,7 @@ func decodePEMBytes(buf []byte) ([]*pem.Block, *pem.Block) {
400411 return certificates , privKey
401412}
402413
414+ // parseCSR takes a byte array containing a PEM encoded CSR and returns a x509.CertificateRequest object
403415func parseCSR (pemBytes []byte ) (* x509.CertificateRequest , error ) {
404416 // extract PEM from request object
405417 block , _ := pem .Decode (pemBytes )
@@ -409,6 +421,7 @@ func parseCSR(pemBytes []byte) (*x509.CertificateRequest, error) {
409421 return x509 .ParseCertificateRequest (block .Bytes )
410422}
411423
424+ // generateRandomString generates a random string of the specified length
412425func generateRandomString (length int ) string {
413426 rand .Seed (time .Now ().UnixNano ())
414427 letters := []rune ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" )
@@ -419,6 +432,7 @@ func generateRandomString(length int) string {
419432 return string (b )
420433}
421434
435+ // ptr returns a pointer to the provided value
422436func ptr [T any ](v T ) * T {
423437 return & v
424438}
0 commit comments