From e35cb361c8411ab23c0e42d75192f5a71974cd7e Mon Sep 17 00:00:00 2001 From: Krzysztof Ostrowski Date: Tue, 2 Nov 2021 17:10:56 +0100 Subject: [PATCH] add comments to satisfy linter Signed-off-by: Krzysztof Ostrowski Co-authored-by: Irbe Krumina --- internal/apis/certmanager/types_issuer.go | 6 ++++++ internal/vault/fake/vault.go | 1 + pkg/api/util/names.go | 8 +++++--- pkg/controller/certificaterequests/fake/fake.go | 1 + pkg/issuer/acme/dns/akamai/akamai.go | 15 ++++++++++----- pkg/issuer/acme/dns/akamai/akamai_test.go | 4 ++-- pkg/issuer/ca/setup.go | 1 + pkg/issuer/helper.go | 2 ++ pkg/issuer/vault/setup.go | 1 + pkg/metrics/metrics.go | 2 ++ 10 files changed, 31 insertions(+), 10 deletions(-) diff --git a/internal/apis/certmanager/types_issuer.go b/internal/apis/certmanager/types_issuer.go index 077e7dd12..29448d551 100644 --- a/internal/apis/certmanager/types_issuer.go +++ b/internal/apis/certmanager/types_issuer.go @@ -84,6 +84,7 @@ type IssuerSpec struct { IssuerConfig } +// IssuerConfig is a generic wrapper around custom issuer types type IssuerConfig struct { // ACME configures this issuer to communicate with a RFC8555 (ACME) server // to obtain signed x509 certificates. @@ -240,6 +241,11 @@ type VaultKubernetesAuth struct { Role string } +// CAIssuer configures an issuer that can issue certificates from its provided +// CA certificate. It contains the name of the private key to sign certificates, +// holds the location for Certificate Revocation Lists (CRL) distribution +// points and list of URLs of Online Certificate Status Protocol (OCSP) +// responders. type CAIssuer struct { // SecretName is the name of the secret used to sign Certificates issued // by this Issuer. diff --git a/internal/vault/fake/vault.go b/internal/vault/fake/vault.go index c87bbcfab..881277b1a 100644 --- a/internal/vault/fake/vault.go +++ b/internal/vault/fake/vault.go @@ -26,6 +26,7 @@ import ( v1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1" ) +// Vault is a mock implementation of the Vault interface type Vault struct { NewFn func(string, corelisters.SecretLister, v1.GenericIssuer) (*Vault, error) SignFn func([]byte, time.Duration) ([]byte, []byte, error) diff --git a/pkg/api/util/names.go b/pkg/api/util/names.go index 25759434f..fdeb82758 100644 --- a/pkg/api/util/names.go +++ b/pkg/api/util/names.go @@ -24,6 +24,10 @@ import ( "regexp" ) +// ComputeName hashes the given object and prefixes it with prefix. +// The algorithm in use is Fowler–Noll–Vo hash function and is not +// cryptographically secure. Using a cryptographically secure hash is +// not necessary. func ComputeName(prefix string, obj interface{}) (string, error) { objectBytes, err := json.Marshal(obj) if err != nil { @@ -43,11 +47,9 @@ func ComputeName(prefix string, obj interface{}) (string, error) { return fmt.Sprintf("%s-%d", prefix, hashF.Sum32()), nil } +// DNSSafeShortenTo52Characters shortens the input string to 52 chars and ensures the last char is an alpha-numeric character. func DNSSafeShortenTo52Characters(in string) string { if len(in) >= 52 { - // shorten the cert name to 52 chars to ensure the total length of the name - // also shorten the 52 char string to the last non-symbol character - // is less than or equal to 64 characters validCharIndexes := regexp.MustCompile(`[a-zA-Z\d]`).FindAllStringIndex(fmt.Sprintf("%.52s", in), -1) in = in[:validCharIndexes[len(validCharIndexes)-1][1]] } diff --git a/pkg/controller/certificaterequests/fake/fake.go b/pkg/controller/certificaterequests/fake/fake.go index 1994518c6..6270da24d 100644 --- a/pkg/controller/certificaterequests/fake/fake.go +++ b/pkg/controller/certificaterequests/fake/fake.go @@ -23,6 +23,7 @@ import ( "github.com/jetstack/cert-manager/pkg/issuer" ) +// Issuer is a mock implementation of an Issuer. type Issuer struct { FakeSign func(context.Context, *cmapi.CertificateRequest, cmapi.GenericIssuer) (*issuer.IssueResponse, error) } diff --git a/pkg/issuer/acme/dns/akamai/akamai.go b/pkg/issuer/acme/dns/akamai/akamai.go index d3bc44311..0fcb08614 100644 --- a/pkg/issuer/acme/dns/akamai/akamai.go +++ b/pkg/issuer/acme/dns/akamai/akamai.go @@ -17,7 +17,6 @@ limitations under the License. // Package akamai implements a DNS provider for solving the DNS-01 // challenge using Akamai Edge DNS. // See https://developer.akamai.com/api/cloud_security/edge_dns_zone_management/v2.html - package akamai import ( @@ -34,14 +33,15 @@ import ( logf "github.com/jetstack/cert-manager/pkg/logs" ) -// Interface defined to enable mocking and required functions +// OpenEdgegridDNSService enables mocking and required functions type OpenEdgegridDNSService interface { - GetRecord(zone string, name string, record_type string) (*dns.RecordBody, error) + GetRecord(zone string, name string, recordType string) (*dns.RecordBody, error) RecordSave(rec *dns.RecordBody, zone string) error RecordUpdate(rec *dns.RecordBody, zone string) error RecordDelete(rec *dns.RecordBody, zone string) error } +//OpenDNSConfig contains akamai's config to create authorization header. type OpenDNSConfig struct { config edgegrid.Config } @@ -258,23 +258,28 @@ func makeTxtRecordName(fqdn, hostedDomain string) (string, error) { return recName, nil } -func (o OpenDNSConfig) GetRecord(zone string, name string, record_type string) (*dns.RecordBody, error) { +// GetRecord gets a single Recordset as RecordBody. Sets Akamai OPEN Edgegrid API +// global variable. +func (o OpenDNSConfig) GetRecord(zone string, name string, recordType string) (*dns.RecordBody, error) { dns.Config = o.config - return dns.GetRecord(zone, name, record_type) + return dns.GetRecord(zone, name, recordType) } +// RecordSave is a function that saves the given zone in the given RecordBody. func (o OpenDNSConfig) RecordSave(rec *dns.RecordBody, zone string) error { return rec.Save(zone) } +// RecordUpdate is a function that updates the given zone in the given RecordBody. func (o OpenDNSConfig) RecordUpdate(rec *dns.RecordBody, zone string) error { return rec.Update(zone) } +// RecordDelete is a function that deletes the given zone in the given RecordBody. func (o OpenDNSConfig) RecordDelete(rec *dns.RecordBody, zone string) error { return rec.Delete(zone) diff --git a/pkg/issuer/acme/dns/akamai/akamai_test.go b/pkg/issuer/acme/dns/akamai/akamai_test.go index e121095ee..d91567b51 100644 --- a/pkg/issuer/acme/dns/akamai/akamai_test.go +++ b/pkg/issuer/acme/dns/akamai/akamai_test.go @@ -303,7 +303,7 @@ func TestCleanUpFailDeleteRecord(t *testing.T) { } // Stub Get Record -func (o StubOpenDNSConfig) GetRecord(zone string, name string, record_type string) (*dns.RecordBody, error) { +func (o StubOpenDNSConfig) GetRecord(zone string, name string, recordType string) (*dns.RecordBody, error) { var rec *dns.RecordBody @@ -322,7 +322,7 @@ func (o StubOpenDNSConfig) GetRecord(zone string, name string, record_type strin if name != rec.Name { return nil, fmt.Errorf("GetRecord: expected/actual Name don't match") } - if record_type != rec.RecordType { + if recordType != rec.RecordType { return nil, fmt.Errorf("GetRecord: expected/actual Record Type don't match") } } diff --git a/pkg/issuer/ca/setup.go b/pkg/issuer/ca/setup.go index 606374782..3484a935c 100644 --- a/pkg/issuer/ca/setup.go +++ b/pkg/issuer/ca/setup.go @@ -39,6 +39,7 @@ const ( messageKeyPairVerified = "Signing CA verified" ) +// Setup verifies signing CA. func (c *CA) Setup(ctx context.Context) error { log := logf.FromContext(ctx, "setup") diff --git a/pkg/issuer/helper.go b/pkg/issuer/helper.go index 0e58e01a3..db32ecf95 100644 --- a/pkg/issuer/helper.go +++ b/pkg/issuer/helper.go @@ -24,6 +24,8 @@ import ( cmlisters "github.com/jetstack/cert-manager/pkg/client/listers/certmanager/v1" ) +// Helper is an interface that defines a method that returns an issuer for the given +// IssuerRef and namespace. type Helper interface { GetGenericIssuer(ref cmmeta.ObjectReference, ns string) (cmapi.GenericIssuer, error) } diff --git a/pkg/issuer/vault/setup.go b/pkg/issuer/vault/setup.go index bf30012e4..fa8ee9bff 100644 --- a/pkg/issuer/vault/setup.go +++ b/pkg/issuer/vault/setup.go @@ -45,6 +45,7 @@ const ( messageAppRoleAuthFieldsRequired = "Vault AppRole auth requires both roleId and tokenSecretRef.name" ) +// Setup creates a new Vault client and attempts to authenticate with the Vault instance and sets the issuer's conditions to reflect the success of the setup. func (v *Vault) Setup(ctx context.Context) error { if v.issuer.GetSpec().Vault == nil { logf.V(logf.WarnLevel).Infof("%s: %s", v.issuer.GetObjectMeta().Name, messageVaultConfigRequired) diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index a420d7a8a..38616b6fe 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -64,6 +64,7 @@ type Metrics struct { var readyConditionStatuses = [...]cmmeta.ConditionStatus{cmmeta.ConditionTrue, cmmeta.ConditionFalse, cmmeta.ConditionUnknown} +// New creates a Metrics struct and populates it with prometheus metric types. func New(log logr.Logger, c clock.Clock) *Metrics { var ( clockTimeSeconds = prometheus.NewCounterFunc( @@ -176,6 +177,7 @@ func (m *Metrics) NewServer(ln net.Listener) *http.Server { MaxHeaderBytes: prometheusMetricsServerMaxHeaderBytes, Handler: mux, } + return server }