Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions api/client/secreport/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,36 +115,20 @@ func (c *Client) GetSecurityAuditQueryResult(ctx context.Context, resultID, next
return resp, nil
}

// GetSecurityReportsStates returns all security reports states.
func (c *Client) GetSecurityReportsStates(ctx context.Context) ([]*secreports.ReportState, error) {
return nil, trace.NotImplemented("GetSecurityReportsStates is not supported in the gRPC client")
}

// UpsertSecurityReportsState upserts security reports state.
func (c *Client) UpsertSecurityReportsState(ctx context.Context, item *secreports.ReportState) error {
return trace.NotImplemented("UpsertSecurityReportsState is not supported in the gRPC client")
}

// DeleteSecurityReportsState deletes security reports state by name.
func (c *Client) DeleteSecurityReportsState(ctx context.Context, name string) error {
return trace.NotImplemented("DeleteSecurityReportsState is not supported in the gRPC client")
}

// DeleteAllSecurityReportsStates deletes all security reports states.
func (c *Client) DeleteAllSecurityReportsStates(ctx context.Context) error {
return trace.NotImplemented("DeleteAllSecurityReportsStates is not supported in the gRPC client")
}

// DeleteAllSecurityReports deletes all security reports.
func (c *Client) DeleteAllSecurityReports(ctx context.Context) error {
return trace.NotImplemented("DeleteAllSecurityReportsStates is not supported in the gRPC client")
}

// DeleteAllSecurityAuditQueries deletes all security audit queries.
func (c *Client) DeleteAllSecurityAuditQueries(ctx context.Context) error {
return trace.NotImplemented("DeleteAllSecurityAuditQueries is not supported in the gRPC client")
}

func (c *Client) GetSecurityReportState(ctx context.Context, name string) (*secreports.ReportState, error) {
return nil, trace.NotImplemented("GetSecurityReportState is not supported in the gRPC client")
resp, err := c.grpcClient.GetReportState(ctx, &pb.GetReportStateRequest{Name: name})
if err != nil {
return nil, trace.Wrap(err)
}

out, err := v1.FromProtoReportState(resp)
if err != nil {
return nil, trace.Wrap(err)
}
return out, nil
}
28 changes: 28 additions & 0 deletions api/types/header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package header

import (
"maps"
"slices"
"time"

Expand Down Expand Up @@ -50,6 +51,19 @@ type ResourceHeader struct {
Metadata Metadata `json:"metadata,omitempty"`
}

func (h *ResourceHeader) Clone() *ResourceHeader {
if h == nil {
return nil
}

return &ResourceHeader{
Kind: h.Kind,
SubKind: h.SubKind,
Version: h.Version,
Metadata: *h.Metadata.Clone(),
}
}

// GetVersion returns the resource version.
func (h *ResourceHeader) GetVersion() string {
return h.Version
Expand Down Expand Up @@ -179,6 +193,20 @@ type Metadata struct {
Revision string `json:"revision,omitempty" yaml:"revision,omitempty"`
}

func (m *Metadata) Clone() *Metadata {
if m == nil {
return nil
}

return &Metadata{
Name: m.Name,
Description: m.Description,
Labels: maps.Clone(m.Labels),
Expires: m.Expires,
Revision: m.Revision,
}
}

// GetRevision returns the revision
func (m *Metadata) GetRevision() string {
return m.Revision
Expand Down
73 changes: 73 additions & 0 deletions api/types/secreports/secreports.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ type Report struct {
Spec ReportSpec `json:"spec" yaml:"spec"`
}

func (a *Report) Clone() *Report {
if a == nil {
return nil
}
return &Report{
ResourceHeader: *a.ResourceHeader.Clone(),
Spec: *a.Spec.Clone(),
}
}

// ReportSpec is the security report spec.
type ReportSpec struct {
// Name is the Report name.
Expand All @@ -49,6 +59,26 @@ type ReportSpec struct {
Version string `json:"version,omitempty" yaml:"version,omitempty"`
}

func (s *ReportSpec) Clone() *ReportSpec {
if s == nil {
return nil
}
var auditQueries []*AuditQuerySpec
if s.AuditQueries != nil {
auditQueries = make([]*AuditQuerySpec, 0, len(s.AuditQueries))
for _, auditQuery := range s.AuditQueries {
auditQueries = append(auditQueries, auditQuery.Clone())
}
}
return &ReportSpec{
Name: s.Name,
Title: s.Title,
Description: s.Description,
AuditQueries: auditQueries,
Version: s.Version,
}
}

// AuditQuery is the audit query resource.
type AuditQuery struct {
// ResourceHeader is the resource header.
Expand All @@ -57,6 +87,16 @@ type AuditQuery struct {
Spec AuditQuerySpec `json:"spec" yaml:"spec"`
}

func (a *AuditQuery) Clone() *AuditQuery {
if a == nil {
return nil
}
return &AuditQuery{
ResourceHeader: *a.ResourceHeader.Clone(),
Spec: *a.Spec.Clone(),
}
}

// AuditQuerySpec is the audit query specification.
type AuditQuerySpec struct {
// Name is the AuditQuery name.
Expand All @@ -69,6 +109,18 @@ type AuditQuerySpec struct {
Query string `json:"query,omitempty" yaml:"query,omitempty"`
}

func (s *AuditQuerySpec) Clone() *AuditQuerySpec {
if s == nil {
return nil
}
return &AuditQuerySpec{
Name: s.Name,
Title: s.Title,
Description: s.Description,
Query: s.Query,
}
}

// CheckAndSetDefaults validates fields and populates empty fields with default values.
func (a *AuditQuery) CheckAndSetDefaults() error {
a.SetKind(types.KindAuditQuery)
Expand Down Expand Up @@ -147,6 +199,17 @@ type ReportState struct {
Spec ReportStateSpec `json:"spec,omitempty" yaml:"spec,omitempty"`
}

func (a *ReportState) Clone() *ReportState {
if a == nil {
return nil
}

return &ReportState{
ResourceHeader: *a.ResourceHeader.Clone(),
Spec: *a.Spec.Clone(),
}
}

// ReportStateSpec is the security report state specification.
type ReportStateSpec struct {
// Name is the Report name.
Expand All @@ -155,6 +218,16 @@ type ReportStateSpec struct {
UpdatedAt time.Time `json:"updated_at,omitempty" yaml:"updated_at,omitempty"`
}

func (s *ReportStateSpec) Clone() *ReportStateSpec {
if s == nil {
return nil
}
return &ReportStateSpec{
Status: s.Status,
UpdatedAt: s.UpdatedAt,
}
}

// GetMetadata returns metadata. This is specifically for conforming to the Resource interface,
// and should be removed when possible.
func (a *ReportState) GetMetadata() types.Metadata {
Expand Down
Loading
Loading