Skip to content

Commit b07b549

Browse files
committed
Output actual version string rather than a pointer address
1 parent a00da54 commit b07b549

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

checker/checker.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ type Checker struct {
113113
issuers map[string]*x509.Certificate
114114
}
115115

116+
// storageKey is nearly analogous to storage.Key, except that the Version field
117+
// is a string
118+
type storageKey struct {
119+
Bucket string
120+
Object string
121+
Version string
122+
}
123+
116124
// crlSummary is a subset of fields from *x509.RevocationList
117125
// useful for logging, plus the number of entries and some metadata.
118126
type crlSummary struct {
@@ -121,7 +129,7 @@ type crlSummary struct {
121129
ThisUpdate time.Time
122130
NextUpdate time.Time
123131
URL string
124-
StorageKey storage.Key
132+
StorageKey storageKey
125133
}
126134

127135
func summary(crl *x509.RevocationList, key storage.Key) crlSummary {
@@ -133,7 +141,11 @@ func summary(crl *x509.RevocationList, key storage.Key) crlSummary {
133141
Number: crl.Number,
134142
NumEntries: len(crl.RevokedCertificateEntries),
135143
URL: idp,
136-
StorageKey: key,
144+
StorageKey: storageKey{
145+
Bucket: key.Bucket,
146+
Object: key.Object,
147+
Version: key.VersionString(),
148+
},
137149
}
138150
}
139151

storage/storage.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ type Key struct {
2626
Version *string
2727
}
2828

29+
// VersionString returns the version string or "unknown" if unset.
30+
func (k Key) VersionString() string {
31+
if k.Version == nil {
32+
return "unknown"
33+
}
34+
return *k.Version
35+
}
36+
2937
func New(ctx context.Context) *Storage {
3038
cfg, err := config.LoadDefaultConfig(ctx)
3139
if err != nil {
@@ -47,12 +55,12 @@ func (s *Storage) Fetch(ctx context.Context, key Key) ([]byte, string, error) {
4755
VersionId: key.Version,
4856
})
4957
if err != nil {
50-
return nil, "", fmt.Errorf("retrieving CRL %s %s version %v: %w", key.Bucket, key.Object, key.Version, err)
58+
return nil, "", fmt.Errorf("retrieving CRL %s %s version %s: %w", key.Bucket, key.Object, key.VersionString(), err)
5159
}
5260

5361
body, err := io.ReadAll(resp.Body)
5462
if err != nil {
55-
return nil, "", fmt.Errorf("reading CRL %s %s version %v: %w", key.Bucket, key.Object, key.Version, err)
63+
return nil, "", fmt.Errorf("reading CRL %s %s version %s: %w", key.Bucket, key.Object, key.VersionString(), err)
5664
}
5765

5866
return body, *resp.VersionId, err
@@ -86,7 +94,7 @@ func (s *Storage) Previous(ctx context.Context, key Key) (string, error) {
8694
}
8795

8896
if (!found || prevVersion == nil) && resp.IsTruncated != nil && *resp.IsTruncated {
89-
return "", fmt.Errorf("too many versions and pagination not implemented! %+v", key)
97+
return "", fmt.Errorf("too many versions and pagination not implemented! bucket:%s object:%s version:%s", key.Bucket, key.Object, key.VersionString())
9098
}
9199

92100
if !found {

storage/storage_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,30 @@ import (
1111
"github.com/letsencrypt/crl-monitor/storage/mock"
1212
)
1313

14+
func TestKeyVersionString(t *testing.T) {
15+
v := "abc123"
16+
for _, tt := range []struct {
17+
name string
18+
key storage.Key
19+
expected string
20+
}{
21+
{
22+
name: "version exists",
23+
key: storage.Key{Bucket: "b", Object: "o", Version: &v},
24+
expected: "abc123",
25+
},
26+
{
27+
name: "version is nil",
28+
key: storage.Key{Bucket: "b", Object: "o", Version: nil},
29+
expected: "unknown",
30+
},
31+
} {
32+
t.Run(tt.name, func(t *testing.T) {
33+
require.Equal(t, tt.expected, tt.key.VersionString())
34+
})
35+
}
36+
}
37+
1438
func TestStorage(t *testing.T) {
1539
mockStorage := mock.New(t, "somebucket", map[string][]mock.MockObject{
1640
"123/0.crl": {

0 commit comments

Comments
 (0)