Skip to content

Commit 4f97d12

Browse files
authored
feat: change public key value to string (#328)
1 parent 960fd7d commit 4f97d12

File tree

6 files changed

+8
-26
lines changed

6 files changed

+8
-26
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ COPY main.go main.go
1414
COPY api/ api/
1515
COPY controllers/ controllers/
1616
COPY pkg/ pkg/
17+
COPY internal/ internal/
1718

1819
# Build
1920
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go

api/v1alpha1/componentversion_types.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
package v1alpha1
66

77
import (
8-
"bytes"
98
"encoding/base64"
109
"fmt"
11-
"io"
1210
"time"
1311

1412
"github.com/fluxcd/pkg/apis/meta"
@@ -93,22 +91,15 @@ type PublicKey struct {
9391

9492
// Value defines a PEM/base64 encoded public key value.
9593
// +optional
96-
Value []byte `json:"value,omitempty"`
94+
Value string `json:"value,omitempty"`
9795
}
9896

9997
func (p *PublicKey) DecodePublicValue() ([]byte, error) {
10098
if len(p.Value) == 0 {
10199
return nil, fmt.Errorf("key value not provided")
102100
}
103101

104-
decoder := base64.NewDecoder(base64.StdEncoding, bytes.NewBuffer(p.Value))
105-
106-
content, err := io.ReadAll(decoder)
107-
if err != nil {
108-
return nil, fmt.Errorf("failed to decode public key pem: %w", err)
109-
}
110-
111-
return content, nil
102+
return base64.StdEncoding.DecodeString(p.Value)
112103
}
113104

114105
// Version specifies version information that can be used to resolve a Component Version.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/delivery.ocm.software_componentversions.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ spec:
126126
value:
127127
description: Value defines a PEM/base64 encoded public key
128128
value.
129-
format: byte
130129
type: string
131130
type: object
132131
required:

pkg/ocm/ocm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func (c *Client) VerifyComponent(
326326
err error
327327
)
328328

329-
if signature.PublicKey.Value != nil {
329+
if signature.PublicKey.Value != "" {
330330
cert, err = signature.PublicKey.DecodePublicValue()
331331
} else {
332332
if signature.PublicKey.SecretRef == nil {

pkg/ocm/ocm_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,7 @@ func TestClient_VerifyComponentWithValueKey(t *testing.T) {
613613
}
614614
require.NoError(t, octx.AddComponent(c))
615615
//var buffer []byte
616-
buf := bytes.Buffer{}
617-
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
618-
_, err = encoder.Write(publicKey1)
619-
require.NoError(t, encoder.Close())
620-
require.NoError(t, err)
616+
pubKey := base64.StdEncoding.EncodeToString(publicKey1)
621617
cv := &v1alpha1.ComponentVersion{
622618
ObjectMeta: metav1.ObjectMeta{
623619
Name: "test-name",
@@ -635,7 +631,7 @@ func TestClient_VerifyComponentWithValueKey(t *testing.T) {
635631
{
636632
Name: Signature,
637633
PublicKey: v1alpha1.PublicKey{
638-
Value: buf.Bytes(),
634+
Value: pubKey,
639635
},
640636
},
641637
},
@@ -688,15 +684,15 @@ func TestClient_VerifyComponentWithValueKeyFailsIfValueIsEmpty(t *testing.T) {
688684
{
689685
Name: Signature,
690686
PublicKey: v1alpha1.PublicKey{
691-
Value: []byte{},
687+
Value: "",
692688
},
693689
},
694690
},
695691
},
696692
}
697693

698694
_, err = ocmClient.VerifyComponent(context.Background(), octx, cv, "v0.0.1")
699-
assert.EqualError(t, err, "failed to get public key for verification: key value not provided")
695+
assert.EqualError(t, err, "kubernetes secret reference not provided")
700696
}
701697

702698
func TestClient_VerifyComponentDifferentPublicKey(t *testing.T) {

0 commit comments

Comments
 (0)