Skip to content

Commit 4fe21ec

Browse files
Merge pull request #261 from rh-amarin/audit-email-not-required
HYPERLFEET-1278 - feat: audit fields do not require email
2 parents 97ceaa1 + bc0d8df commit 4fe21ec

14 files changed

Lines changed: 54 additions & 61 deletions

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/mendsley/gojwk v0.0.0-20141217222730-4d5ec6e58103
2121
github.com/oapi-codegen/runtime v1.4.2
2222
github.com/onsi/gomega v1.42.0
23-
github.com/openshift-hyperfleet/hyperfleet-api-spec v1.0.24
23+
github.com/openshift-hyperfleet/hyperfleet-api-spec v1.0.25
2424
github.com/prometheus/client_golang v1.16.0
2525
github.com/prometheus/client_model v0.3.0
2626
github.com/spf13/cobra v1.10.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJw
203203
github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M=
204204
github.com/openshift-hyperfleet/hyperfleet-api-spec v1.0.24 h1:ACdI09b1TAqsTehVG0eNaAJhWfybMKt87nx/bZ1Dgwk=
205205
github.com/openshift-hyperfleet/hyperfleet-api-spec v1.0.24/go.mod h1:KITzIAd8HcMpH5lXdHFjgk45dvL6XLpP3wwz8iK+KCI=
206+
github.com/openshift-hyperfleet/hyperfleet-api-spec v1.0.25 h1:vqJeoo0Xr/ynX1rKOOKJxX2nC4wdSXw6mP730ETGRaE=
207+
github.com/openshift-hyperfleet/hyperfleet-api-spec v1.0.25/go.mod h1:KITzIAd8HcMpH5lXdHFjgk45dvL6XLpP3wwz8iK+KCI=
206208
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
207209
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
208210
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=

hack/tools.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build tools
2-
31
package hack
42

53
import _ "github.com/openshift-hyperfleet/hyperfleet-api-spec/schemas"

pkg/api/presenters/cluster.go

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66

7-
openapi_types "github.com/oapi-codegen/runtime/types"
87
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/api"
98
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/api/openapi"
109
)
@@ -43,20 +42,6 @@ func ConvertCluster(req *openapi.ClusterCreateRequest) (*api.Cluster, error) {
4342
}, nil
4443
}
4544

46-
// Helper to convert string to openapi_types.Email
47-
func toEmail(s string) openapi_types.Email {
48-
return openapi_types.Email(s)
49-
}
50-
51-
// Helper to convert *string to *openapi_types.Email (for optional email fields)
52-
func toEmailPtr(s *string) *openapi_types.Email {
53-
if s == nil || *s == "" {
54-
return nil
55-
}
56-
e := openapi_types.Email(*s)
57-
return &e
58-
}
59-
6045
// PresentCluster converts api.Cluster (GORM model) to openapi.Cluster
6146
func PresentCluster(cluster *api.Cluster) (openapi.Cluster, error) {
6247
// Unmarshal Spec
@@ -105,9 +90,9 @@ func PresentCluster(cluster *api.Cluster) (openapi.Cluster, error) {
10590
}
10691

10792
result := openapi.Cluster{
108-
CreatedBy: toEmail(cluster.CreatedBy),
93+
CreatedBy: cluster.CreatedBy,
10994
CreatedTime: cluster.CreatedTime,
110-
DeletedBy: toEmailPtr(cluster.DeletedBy),
95+
DeletedBy: cluster.DeletedBy,
11196
DeletedTime: cluster.DeletedTime,
11297
Generation: cluster.Generation,
11398
Href: &href,
@@ -119,7 +104,7 @@ func PresentCluster(cluster *api.Cluster) (openapi.Cluster, error) {
119104
Status: openapi.ClusterStatus{
120105
Conditions: openapiConditions,
121106
},
122-
UpdatedBy: toEmail(cluster.UpdatedBy),
107+
UpdatedBy: cluster.UpdatedBy,
123108
UpdatedTime: cluster.UpdatedTime,
124109
}
125110

pkg/api/presenters/cluster_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66
"time"
77

8-
openapi_types "github.com/oapi-codegen/runtime/types"
98
. "github.com/onsi/gomega"
109
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/api"
1110
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/api/openapi"
@@ -206,8 +205,8 @@ func TestPresentCluster_Complete(t *testing.T) {
206205
Expect(*result.Href).To(Equal("/api/hyperfleet/v1/clusters/cluster-abc123"))
207206
Expect(result.Name).To(Equal("presented-cluster"))
208207
Expect(result.Generation).To(Equal(int32(10)))
209-
Expect(result.CreatedBy).To(Equal(openapi_types.Email("user123@example.com")))
210-
Expect(result.UpdatedBy).To(Equal(openapi_types.Email("user456@example.com")))
208+
Expect(result.CreatedBy).To(Equal("user123@example.com"))
209+
Expect(result.UpdatedBy).To(Equal("user456@example.com"))
211210

212211
// Verify Spec unmarshaled correctly
213212
Expect(result.Spec["region"]).To(Equal("us-west1"))

pkg/api/presenters/node_pool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ func PresentNodePool(nodePool *api.NodePool) (openapi.NodePool, error) {
9797
}
9898

9999
result := openapi.NodePool{
100-
CreatedBy: toEmail(nodePool.CreatedBy),
100+
CreatedBy: nodePool.CreatedBy,
101101
CreatedTime: nodePool.CreatedTime,
102-
DeletedBy: toEmailPtr(nodePool.DeletedBy),
102+
DeletedBy: nodePool.DeletedBy,
103103
DeletedTime: nodePool.DeletedTime,
104104
Generation: nodePool.Generation,
105105
Href: &href,
@@ -116,7 +116,7 @@ func PresentNodePool(nodePool *api.NodePool) (openapi.NodePool, error) {
116116
Status: openapi.NodePoolStatus{
117117
Conditions: openapiConditions,
118118
},
119-
UpdatedBy: toEmail(nodePool.UpdatedBy),
119+
UpdatedBy: nodePool.UpdatedBy,
120120
UpdatedTime: nodePool.UpdatedTime,
121121
}
122122

pkg/api/presenters/node_pool_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66
"time"
77

8-
openapi_types "github.com/oapi-codegen/runtime/types"
98
. "github.com/onsi/gomega"
109
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/api"
1110
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/api/openapi"
@@ -192,8 +191,8 @@ func TestPresentNodePool_Complete(t *testing.T) {
192191
Expect(result.Kind).To(Equal("NodePool"))
193192
Expect(*result.Href).To(Equal("/api/hyperfleet/v1/clusters/cluster-abc/nodepools/nodepool-xyz"))
194193
Expect(result.Name).To(Equal("presented-nodepool"))
195-
Expect(result.CreatedBy).To(Equal(openapi_types.Email("user123@example.com")))
196-
Expect(result.UpdatedBy).To(Equal(openapi_types.Email("user456@example.com")))
194+
Expect(result.CreatedBy).To(Equal("user123@example.com"))
195+
Expect(result.UpdatedBy).To(Equal("user456@example.com"))
197196

198197
// Verify Spec unmarshaled correctly
199198
Expect(result.Spec["replicas"]).To(BeNumerically("==", 5))

pkg/api/presenters/resource.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66

7-
openapi_types "github.com/oapi-codegen/runtime/types"
87
"gorm.io/datatypes"
98

109
"github.com/openshift-hyperfleet/hyperfleet-api/pkg/api"
@@ -67,17 +66,16 @@ func PresentResource(r *api.Resource) openapi.Resource {
6766
Generation: r.Generation,
6867
CreatedTime: r.CreatedTime,
6968
UpdatedTime: r.UpdatedTime,
70-
CreatedBy: openapi_types.Email(r.CreatedBy),
71-
UpdatedBy: openapi_types.Email(r.UpdatedBy),
69+
CreatedBy: r.CreatedBy,
70+
UpdatedBy: r.UpdatedBy,
7271
DeletedTime: r.DeletedTime,
7372
Status: openapi.ResourceStatus{
7473
Conditions: []openapi.ResourceCondition{},
7574
},
7675
}
7776

7877
if r.DeletedBy != nil {
79-
email := openapi_types.Email(*r.DeletedBy)
80-
resp.DeletedBy = &email
78+
resp.DeletedBy = r.DeletedBy
8179
}
8280

8381
if r.OwnerID != nil && *r.OwnerID != "" {
@@ -103,8 +101,8 @@ func PresentResourceList(resources api.ResourceList, paging *api.PagingMeta) ope
103101
}
104102
return openapi.ResourceList{
105103
Items: items,
106-
Page: int32(paging.Page),
107-
Size: int32(paging.Size),
104+
Page: int32(paging.Page), //nolint:gosec
105+
Size: int32(paging.Size), //nolint:gosec
108106
Total: paging.Total,
109107
}
110108
}

pkg/api/presenters/resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestPresentResource(t *testing.T) {
8888
Expect(resp.Spec).To(HaveKeyWithValue("is_default", true))
8989
Expect(*resp.Labels).To(HaveKeyWithValue("env", "prod"))
9090
Expect(resp.Generation).To(Equal(int32(1)))
91-
Expect(string(resp.CreatedBy)).To(Equal("user@test.com"))
91+
Expect(resp.CreatedBy).To(Equal("user@test.com"))
9292
Expect(resp.OwnerReferences).To(BeNil())
9393
Expect(resp.Status.Conditions).NotTo(BeNil())
9494
Expect(resp.Status.Conditions).To(BeEmpty())

pkg/api/presenters/slice_filter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func SliceFilter(fields2Store []string, model interface{}) (*ProjectionList, *er
3333

3434
// Initialize result structure
3535
result := &ProjectionList{
36-
Page: int32(reflectValue.FieldByName("Page").Int()),
37-
Size: int32(reflectValue.FieldByName("Size").Int()),
38-
Total: int32(reflectValue.FieldByName("Total").Int()),
36+
Page: int32(reflectValue.FieldByName("Page").Int()), //nolint:gosec
37+
Size: int32(reflectValue.FieldByName("Size").Int()), //nolint:gosec
38+
Total: int32(reflectValue.FieldByName("Total").Int()), //nolint:gosec
3939
Items: nil,
4040
}
4141

0 commit comments

Comments
 (0)