github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/client/secreport/crud.go (about) 1 /* 2 Copyright 2023 Gravitational, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package secreport 18 19 import ( 20 "context" 21 22 "github.com/gravitational/trace" 23 "github.com/gravitational/trace/trail" 24 25 pb "github.com/gravitational/teleport/api/gen/proto/go/teleport/secreports/v1" 26 "github.com/gravitational/teleport/api/types/secreports" 27 v1 "github.com/gravitational/teleport/api/types/secreports/convert/v1" 28 ) 29 30 // GetSecurityAuditQuery returns audit query by name 31 func (c *Client) GetSecurityAuditQuery(ctx context.Context, name string) (*secreports.AuditQuery, error) { 32 resp, err := c.grpcClient.GetAuditQuery(ctx, &pb.GetAuditQueryRequest{Name: name}) 33 if err != nil { 34 return nil, trail.FromGRPC(err) 35 } 36 out, err := v1.FromProtoAuditQuery(resp) 37 if err != nil { 38 return nil, trace.Wrap(err) 39 } 40 return out, nil 41 } 42 43 // UpsertSecurityAuditQuery upsets audit query. 44 func (c *Client) UpsertSecurityAuditQuery(ctx context.Context, in *secreports.AuditQuery) error { 45 _, err := c.grpcClient.UpsertAuditQuery(ctx, &pb.UpsertAuditQueryRequest{AuditQuery: v1.ToProtoAuditQuery(in)}) 46 if err != nil { 47 return trail.FromGRPC(err) 48 } 49 return nil 50 } 51 52 // DeleteSecurityAuditQuery deletes audit query by name. 53 func (c *Client) DeleteSecurityAuditQuery(ctx context.Context, name string) error { 54 _, err := c.grpcClient.DeleteAuditQuery(ctx, &pb.DeleteAuditQueryRequest{Name: name}) 55 if err != nil { 56 return trail.FromGRPC(err) 57 } 58 return nil 59 } 60 61 // UpsertSecurityReport upsets security report. 62 func (c *Client) UpsertSecurityReport(ctx context.Context, item *secreports.Report) error { 63 _, err := c.grpcClient.UpsertReport(ctx, &pb.UpsertReportRequest{Report: v1.ToProtoReport(item)}) 64 if err != nil { 65 return trail.FromGRPC(err) 66 } 67 return nil 68 } 69 70 // GetSecurityReport returns security report by name. 71 func (c *Client) GetSecurityReport(ctx context.Context, name string) (*secreports.Report, error) { 72 resp, err := c.grpcClient.GetReport(ctx, &pb.GetReportRequest{Name: name}) 73 if err != nil { 74 return nil, trail.FromGRPC(err) 75 } 76 77 out, err := v1.FromProtoReport(resp) 78 if err != nil { 79 return nil, trace.Wrap(err) 80 } 81 return out, nil 82 } 83 84 // GetSecurityReportResult returns security report details by name. 85 func (c *Client) GetSecurityReportResult(ctx context.Context, name string, days int) (*pb.ReportResult, error) { 86 resp, err := c.grpcClient.GetReportResult(ctx, &pb.GetReportResultRequest{ 87 Name: name, 88 Days: uint32(days), 89 }) 90 if err != nil { 91 return nil, trail.FromGRPC(err) 92 } 93 return resp.GetResult(), nil 94 } 95 96 // RunSecurityReport runs security report by name. 97 func (c *Client) RunSecurityReport(ctx context.Context, name string, days int) error { 98 _, err := c.grpcClient.RunReport(ctx, &pb.RunReportRequest{Name: name, Days: uint32(days)}) 99 if err != nil { 100 return trail.FromGRPC(err) 101 } 102 return nil 103 } 104 105 // GetSecurityAuditQueryResult returns audit query result by id. 106 func (c *Client) GetSecurityAuditQueryResult(ctx context.Context, resultID, nextToken string, maxResults int32) (*pb.GetAuditQueryResultResponse, error) { 107 resp, err := c.grpcClient.GetAuditQueryResult(ctx, &pb.GetAuditQueryResultRequest{ 108 ResultId: resultID, 109 NextToken: nextToken, 110 MaxResults: maxResults, 111 }) 112 if err != nil { 113 return nil, trail.FromGRPC(err) 114 } 115 return resp, nil 116 } 117 118 // GetSecurityReportsStates returns all security reports states. 119 func (c *Client) GetSecurityReportsStates(ctx context.Context) ([]*secreports.ReportState, error) { 120 return nil, trace.NotImplemented("GetSecurityReportsStates is not supported in the gRPC client") 121 } 122 123 // ListSecurityReportsStates returns all security reports states. 124 func (c *Client) ListSecurityReportsStates(ctx context.Context, i int, s string) ([]*secreports.ReportState, string, error) { 125 return nil, "", trace.NotImplemented("ListSecurityReportsStates is not supported in the gRPC client") 126 } 127 128 // UpsertSecurityReportsState upserts security reports state. 129 func (c *Client) UpsertSecurityReportsState(ctx context.Context, item *secreports.ReportState) error { 130 return trace.NotImplemented("UpsertSecurityReportsState is not supported in the gRPC client") 131 } 132 133 // DeleteSecurityReportsState deletes security reports state by name. 134 func (c *Client) DeleteSecurityReportsState(ctx context.Context, name string) error { 135 return trace.NotImplemented("DeleteSecurityReportsState is not supported in the gRPC client") 136 } 137 138 // DeleteAllSecurityReportsStates deletes all security reports states. 139 func (c *Client) DeleteAllSecurityReportsStates(ctx context.Context) error { 140 return trace.NotImplemented("DeleteAllSecurityReportsStates is not supported in the gRPC client") 141 } 142 143 // DeleteAllSecurityReports deletes all security reports. 144 func (c *Client) DeleteAllSecurityReports(ctx context.Context) error { 145 return trace.NotImplemented("DeleteAllSecurityReportsStates is not supported in the gRPC client") 146 } 147 148 // DeleteAllSecurityAuditQueries deletes all security audit queries. 149 func (c *Client) DeleteAllSecurityAuditQueries(ctx context.Context) error { 150 return trace.NotImplemented("DeleteAllSecurityAuditQueries is not supported in the gRPC client") 151 } 152 153 func (c *Client) GetSecurityReportState(ctx context.Context, name string) (*secreports.ReportState, error) { 154 return nil, trace.NotImplemented("GetSecurityReportState is not supported in the gRPC client") 155 }