Skip to content

Commit 15bdd28

Browse files
AlekSitalos-bot
authored andcommitted
chore: minor updates
* bump Go version; * update kres; * fix linter warnings. Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
1 parent 4f80b97 commit 15bdd28

File tree

11 files changed

+88
-51
lines changed

11 files changed

+88
-51
lines changed

.codecov.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2020-08-13T17:14:02Z by kres f4c4987.
3+
# Generated on 2021-05-20T11:41:34Z by kres latest.
44

55
codecov:
6-
require_ci_to_pass: false
6+
require_ci_to_pass: false
77

88
coverage:
9-
status:
10-
project:
11-
default:
12-
target: 50%
13-
threshold: 0.5%
14-
base: auto
15-
if_ci_failed: success
16-
patch: off
9+
status:
10+
project:
11+
default:
12+
target: 50%
13+
threshold: 0.5%
14+
base: auto
15+
if_ci_failed: success
16+
patch: off
1717

1818
comment: false

.conform.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2020-11-11T19:39:46Z by kres latest.
3+
# Generated on 2021-05-20T11:41:34Z by kres latest.
44

55
policies:
66
- type: commit
@@ -28,6 +28,7 @@ policies:
2828
- .go
2929
excludeSuffixes:
3030
- .pb.go
31+
- .pb.gw.go
3132
header: |
3233
// This Source Code Form is subject to the terms of the Mozilla Public
3334
// License, v. 2.0. If a copy of the MPL was not distributed with this

.golangci.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2020-08-13T17:14:02Z by kres f4c4987.
3+
# Generated on 2021-05-20T11:41:34Z by kres latest.
44

55

66
# options for analysis running
@@ -75,8 +75,6 @@ linters-settings:
7575
lll:
7676
line-length: 200
7777
tab-width: 4
78-
maligned:
79-
suggest-new: true
8078
misspell:
8179
locale: US
8280
ignore-words: []
@@ -112,6 +110,9 @@ linters-settings:
112110
allow-separated-leading-comment: false
113111
gofumpt:
114112
extra-rules: false
113+
cyclop:
114+
# the maximal code complexity to report
115+
max-complexity: 20
115116

116117
linters:
117118
enable-all: true
@@ -125,6 +126,10 @@ linters:
125126
- gomnd
126127
- goerr113
127128
- nestif
129+
- wrapcheck
130+
- paralleltest
131+
- exhaustivestruct
132+
- forbidigo
128133
disable-all: false
129134
fast: false
130135

Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# syntax = docker/dockerfile-upstream:1.1.7-experimental
1+
# syntax = docker/dockerfile-upstream:1.2.0-labs
22

33
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
44
#
5-
# Generated on 2020-11-11T19:39:46Z by kres latest.
5+
# Generated on 2021-05-20T11:41:34Z by kres latest.
66

77
ARG TOOLCHAIN
88

9+
# cleaned up specs and compiled versions
10+
FROM scratch AS generate
11+
912
# runs markdownlint
1013
FROM node:14.8.0-alpine AS lint-markdown
1114
RUN npm i -g markdownlint-cli@0.23.2
@@ -17,14 +20,14 @@ RUN markdownlint --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --ru
1720

1821
# base toolchain image
1922
FROM ${TOOLCHAIN} AS toolchain
20-
RUN apk --update --no-cache add bash curl build-base
23+
RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev
2124

2225
# build tools
2326
FROM toolchain AS tools
2427
ENV GO111MODULE on
2528
ENV CGO_ENABLED 0
2629
ENV GOPATH /go
27-
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.30.0
30+
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.38.0
2831
ARG GOFUMPT_VERSION
2932
RUN cd $(mktemp -d) \
3033
&& go mod init tmp \
@@ -45,6 +48,7 @@ RUN --mount=type=cache,target=/go/pkg go list -mod=readonly all >/dev/null
4548
# runs gofumpt
4649
FROM base AS lint-gofumpt
4750
RUN find . -name '*.pb.go' | xargs -r rm
51+
RUN find . -name '*.pb.gw.go' | xargs -r rm
4852
RUN FILES="$(gofumports -l -local github.com/talos-systems/crypto .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumports -w -local github.com/talos-systems/crypto .':\n${FILES}"; exit 1)
4953

5054
# runs golangci-lint
@@ -61,7 +65,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/g
6165
# runs unit-tests
6266
FROM base AS unit-tests-run
6367
ARG TESTPKGS
64-
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp go test -v -covermode=atomic -coverprofile=coverage.txt -count 1 ${TESTPKGS}
68+
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp go test -v -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} -count 1 ${TESTPKGS}
6569

6670
FROM scratch AS unit-tests
6771
COPY --from=unit-tests-run /src/coverage.txt /coverage.txt

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2020-11-11T19:40:41Z by kres latest.
3+
# Generated on 2021-05-20T11:52:28Z by kres latest.
44

55
# common variables
66

@@ -12,7 +12,10 @@ REGISTRY ?= ghcr.io
1212
USERNAME ?= talos-systems
1313
REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME)
1414
GOFUMPT_VERSION ?= abc0db2c416aca0f60ea33c23c76665f6e7ba0b6
15-
GO_VERSION ?= 1.14
15+
GO_VERSION ?= 1.16
16+
PROTOBUF_GO_VERSION ?= 1.25.0
17+
GRPC_GO_VERSION ?= 1.1.0
18+
GRPC_GATEWAY_VERSION ?= 2.4.0
1619
TESTPKGS ?= ./...
1720
KRES_IMAGE ?= ghcr.io/talos-systems/kres:latest
1821

@@ -33,12 +36,15 @@ COMMON_ARGS += --build-arg=TAG=$(TAG)
3336
COMMON_ARGS += --build-arg=USERNAME=$(USERNAME)
3437
COMMON_ARGS += --build-arg=TOOLCHAIN=$(TOOLCHAIN)
3538
COMMON_ARGS += --build-arg=GOFUMPT_VERSION=$(GOFUMPT_VERSION)
39+
COMMON_ARGS += --build-arg=PROTOBUF_GO_VERSION=$(PROTOBUF_GO_VERSION)
40+
COMMON_ARGS += --build-arg=GRPC_GO_VERSION=$(GRPC_GO_VERSION)
41+
COMMON_ARGS += --build-arg=GRPC_GATEWAY_VERSION=$(GRPC_GATEWAY_VERSION)
3642
COMMON_ARGS += --build-arg=TESTPKGS=$(TESTPKGS)
37-
TOOLCHAIN ?= docker.io/golang:1.15-alpine
43+
TOOLCHAIN ?= docker.io/golang:1.16-alpine
3844

3945
# help menu
4046

41-
export define HELP_MENU_HEADER
47+
define HELP_MENU_HEADER
4248
# Getting Started
4349

4450
To build this project, you must have the following installed:
@@ -126,4 +132,3 @@ rekres:
126132
help: ## This help menu.
127133
@echo "$$HELP_MENU_HEADER"
128134
@grep -E '^[a-zA-Z%_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
129-

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/talos-systems/crypto
22

3-
go 1.14
3+
go 1.16
44

55
require (
66
github.com/stretchr/testify v1.7.0

tls/provider.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ type Generator interface {
3535
Identity(csr *talosx509.CertificateSigningRequest) (ca, crt []byte, err error)
3636
}
3737

38+
//nolint:govet
3839
type certificateProvider struct {
39-
sync.RWMutex
40+
rw sync.RWMutex
4041

4142
generator Generator
4243

@@ -68,8 +69,7 @@ func NewRenewingCertificateProvider(generator Generator, dnsNames []string, ips
6869

6970
provider.updateCertificates(ca, &cert)
7071

71-
//nolint: errcheck
72-
go provider.manageUpdates(context.TODO())
72+
go provider.manageUpdates(context.TODO()) //nolint:errcheck
7373

7474
return provider, nil
7575
}
@@ -105,8 +105,8 @@ func (p *certificateProvider) GetCA() ([]byte, error) {
105105
return nil, errors.New("no provider")
106106
}
107107

108-
p.RLock()
109-
defer p.RUnlock()
108+
p.rw.RLock()
109+
defer p.rw.RUnlock()
110110

111111
return p.ca, nil
112112
}
@@ -116,8 +116,8 @@ func (p *certificateProvider) GetCertificate(h *tls.ClientHelloInfo) (*tls.Certi
116116
return nil, errors.New("no provider")
117117
}
118118

119-
p.RLock()
120-
defer p.RUnlock()
119+
p.rw.RLock()
120+
defer p.rw.RUnlock()
121121

122122
return p.crt, nil
123123
}
@@ -127,8 +127,8 @@ func (p *certificateProvider) GetClientCertificate(*tls.CertificateRequestInfo)
127127
}
128128

129129
func (p *certificateProvider) updateCertificates(ca []byte, cert *tls.Certificate) {
130-
p.Lock()
131-
defer p.Unlock()
130+
p.rw.Lock()
131+
defer p.rw.Unlock()
132132

133133
p.ca = ca
134134
p.crt = cert
@@ -138,8 +138,7 @@ func (p *certificateProvider) manageUpdates(ctx context.Context) (err error) {
138138
nextRenewal := talosx509.DefaultCertificateValidityDuration
139139

140140
for ctx.Err() == nil {
141-
//nolint: errcheck
142-
if c, _ := p.GetCertificate(nil); c != nil {
141+
if c, _ := p.GetCertificate(nil); c != nil { //nolint:errcheck
143142
if len(c.Certificate) > 0 {
144143
var crt *x509.Certificate
145144
crt, err = x509.ParseCertificate(c.Certificate[0])

x509/fingerprint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func SPKIFingerprintFromDER(certDER []byte) (Fingerprint, error) {
5555
// SPKIFingerprint computes SPKI certificate fingerprint.
5656
func SPKIFingerprint(cert *x509.Certificate) Fingerprint {
5757
hash := sha256.New()
58-
hash.Write(cert.RawSubjectPublicKeyInfo) //nolint: errcheck
58+
hash.Write(cert.RawSubjectPublicKeyInfo)
5959

6060
return Fingerprint(hash.Sum(nil))
6161
}

x509/fingerprint_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ yuGnBXj8ytqU0CwIPX4WecigUCAkVDNx
6464
-----END CERTIFICATE-----`
6565

6666
func TestSPKIFingerprints(t *testing.T) {
67+
t.Parallel()
68+
6769
fingerprint1, err := x509.SPKIFingerprintFromPEM([]byte(certPEM1))
6870
if err != nil {
6971
t.Fatal(err)

x509/x509.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ type PEMEncodedKey struct {
9696
}
9797

9898
// Options is the functional options struct.
99+
//
100+
//nolint:govet
99101
type Options struct {
100102
CommonName string
101103
Organization string
@@ -247,7 +249,7 @@ func NewSelfSignedCertificateAuthority(setters ...Option) (ca *CertificateAuthor
247249
DNSNames: opts.DNSNames,
248250
}
249251

250-
switch opts.SignatureAlgorithm { //nolint: exhaustive
252+
switch opts.SignatureAlgorithm { //nolint:exhaustive
251253
case x509.SHA512WithRSA:
252254
return RSACertificateAuthority(crt, opts)
253255
case x509.PureEd25519:
@@ -576,7 +578,7 @@ func NewKeyPair(ca *CertificateAuthority, setters ...Option) (keypair *KeyPair,
576578
identity *PEMEncodedCertificateAndKey
577579
)
578580

579-
switch ca.Crt.SignatureAlgorithm { //nolint: exhaustive
581+
switch ca.Crt.SignatureAlgorithm { //nolint:exhaustive
580582
case x509.SHA512WithRSA:
581583
csr, identity, err = NewRSACSRAndIdentity(setters...)
582584
if err != nil {
@@ -1005,8 +1007,6 @@ func (p *PEMEncodedKey) GetECDSAKey() (*ECDSAKey, error) {
10051007
}
10061008

10071009
// NewCertficateAndKey generates a new key and certificate signed by a CA.
1008-
//
1009-
//nolint: gocyclo
10101010
func NewCertficateAndKey(crt *x509.Certificate, key interface{}, setters ...Option) (p *PEMEncodedCertificateAndKey, err error) {
10111011
var (
10121012
c *Certificate
@@ -1081,8 +1081,8 @@ func Hash(crt *x509.Certificate) string {
10811081

10821082
// RSACertificateAuthority creates an RSA CA.
10831083
func RSACertificateAuthority(template *x509.Certificate, opts *Options) (ca *CertificateAuthority, err error) {
1084-
key, e := rsa.GenerateKey(rand.Reader, opts.Bits)
1085-
if e != nil {
1084+
key, err := rsa.GenerateKey(rand.Reader, opts.Bits)
1085+
if err != nil {
10861086
return
10871087
}
10881088

@@ -1092,8 +1092,8 @@ func RSACertificateAuthority(template *x509.Certificate, opts *Options) (ca *Cer
10921092
Bytes: keyBytes,
10931093
})
10941094

1095-
crtDER, e := x509.CreateCertificate(rand.Reader, template, template, &key.PublicKey, key)
1096-
if e != nil {
1095+
crtDER, err := x509.CreateCertificate(rand.Reader, template, template, &key.PublicKey, key)
1096+
if err != nil {
10971097
return
10981098
}
10991099

@@ -1119,13 +1119,13 @@ func RSACertificateAuthority(template *x509.Certificate, opts *Options) (ca *Cer
11191119

11201120
// ECDSACertificateAuthority creates an ECDSA CA.
11211121
func ECDSACertificateAuthority(template *x509.Certificate) (ca *CertificateAuthority, err error) {
1122-
key, e := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
1123-
if e != nil {
1122+
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
1123+
if err != nil {
11241124
return
11251125
}
11261126

1127-
keyBytes, e := x509.MarshalECPrivateKey(key)
1128-
if e != nil {
1127+
keyBytes, err := x509.MarshalECPrivateKey(key)
1128+
if err != nil {
11291129
return
11301130
}
11311131

0 commit comments

Comments
 (0)