Skip to content

Commit 1828126

Browse files
committed
chore(comments): Write function comments and update license header
1 parent 579442e commit 1828126

15 files changed

+47
-14
lines changed

api/v1alpha1/clusterissuer_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 The Keyfactor Command Authors.
2+
Copyright © 2023 Keyfactor
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

api/v1alpha1/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 The Keyfactor Command Authors.
2+
Copyright © 2023 Keyfactor
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

api/v1alpha1/issuer_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 The Keyfactor Command Authors.
2+
Copyright © 2023 Keyfactor
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

internal/controllers/certificaterequest_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ func (r *CertificateRequestReconciler) Reconcile(ctx context.Context, req ctrl.R
268268
return ctrl.Result{}, nil
269269
}
270270

271+
// SetupWithManager registers the CertificateRequestReconciler with the controller manager.
272+
// It configures controller-runtime to reconcile cert-manager CertificateRequests in the cluster.
271273
func (r *CertificateRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
272274
return ctrl.NewControllerManagedBy(mgr).
273275
For(&cmapi.CertificateRequest{}).

internal/controllers/certificaterequest_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 The Keyfactor Command Authors.
2+
Copyright © 2023 Keyfactor
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

internal/controllers/fake_configclient_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 The Keyfactor Command Authors.
2+
Copyright © 2023 Keyfactor
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

internal/controllers/issuer_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 The Keyfactor Command Authors.
2+
Copyright © 2023 Keyfactor
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -162,7 +162,8 @@ func (r *IssuerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
162162
return ctrl.Result{RequeueAfter: defaultHealthCheckInterval}, nil
163163
}
164164

165-
// SetupWithManager sets up the controller with the Manager.
165+
// SetupWithManager registers the IssuerReconciler with the controller manager.
166+
// It configures controller-runtime to reconcile Keyfactor Command Issuers/ClusterIssuers in the cluster.
166167
func (r *IssuerReconciler) SetupWithManager(mgr ctrl.Manager) error {
167168
issuerType, err := r.newIssuer()
168169
if err != nil {

internal/controllers/issuer_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 The Keyfactor Command Authors.
2+
Copyright © 2023 Keyfactor
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

internal/controllers/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2023 The Keyfactor Command Authors.
2+
Copyright © 2023 Keyfactor
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.

internal/issuer/signer/signer.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
6970
func 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
8285
func 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
8690
func 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
135140
func 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
147153
func (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
172179
func (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
258267
func 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
317327
func 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
386397
func 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
403415
func 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
412425
func 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
422436
func ptr[T any](v T) *T {
423437
return &v
424438
}

0 commit comments

Comments
 (0)