Commit 1c92467e authored by Derek Schaller's avatar Derek Schaller
Browse files

api: audit api - add pagination and individual event api

parent 01b52430
Showing with 1155 additions and 95 deletions
+1155 -95
......@@ -22,6 +22,14 @@ service AuditAPI {
};
option (clutch.api.v1.action).type = READ;
}
rpc GetEvent(GetEventRequest) returns (GetEventResponse) {
option (google.api.http) = {
post: "/v1/audit/getEvent",
body: "*"
};
option (clutch.api.v1.action).type = READ;
}
}
message TimeRange {
......@@ -34,6 +42,12 @@ message GetEventsRequest {
TimeRange range = 1;
google.protobuf.Duration since = 2;
}
// Currently page_token specifies the page number you wish to request.
// The rationale behind the naming is we might changes this to a cursor implentation
// in the future and did not want to break existing implementations of the API.
// https://cloud.google.com/apis/design/design_patterns#list_pagination
string page_token = 3;
uint64 limit = 4;
}
message Resource {
......@@ -89,8 +103,20 @@ message Event {
oneof event_type {
RequestEvent event = 2;
}
// The event id.
int64 id = 3;
}
message GetEventsResponse {
repeated Event events = 1;
string next_page_token = 2;
}
message GetEventRequest {
int64 event_id = 1;
}
message GetEventResponse {
Event event = 1;
}
\ No newline at end of file
This diff is collapsed.
......@@ -65,6 +65,40 @@ func local_request_AuditAPI_GetEvents_0(ctx context.Context, marshaler runtime.M
}
func request_AuditAPI_GetEvent_0(ctx context.Context, marshaler runtime.Marshaler, client AuditAPIClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetEventRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.GetEvent(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_AuditAPI_GetEvent_0(ctx context.Context, marshaler runtime.Marshaler, server AuditAPIServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetEventRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.GetEvent(ctx, &protoReq)
return msg, metadata, err
}
// RegisterAuditAPIHandlerServer registers the http handlers for service AuditAPI to "mux".
// UnaryRPC :call AuditAPIServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
......@@ -96,6 +130,31 @@ func RegisterAuditAPIHandlerServer(ctx context.Context, mux *runtime.ServeMux, s
})
mux.Handle("POST", pattern_AuditAPI_GetEvent_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/clutch.audit.v1.AuditAPI/GetEvent", runtime.WithHTTPPathPattern("/v1/audit/getEvent"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_AuditAPI_GetEvent_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_AuditAPI_GetEvent_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
......@@ -159,13 +218,39 @@ func RegisterAuditAPIHandlerClient(ctx context.Context, mux *runtime.ServeMux, c
})
mux.Handle("POST", pattern_AuditAPI_GetEvent_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/clutch.audit.v1.AuditAPI/GetEvent", runtime.WithHTTPPathPattern("/v1/audit/getEvent"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_AuditAPI_GetEvent_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_AuditAPI_GetEvent_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_AuditAPI_GetEvents_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "audit", "getEvents"}, ""))
pattern_AuditAPI_GetEvent_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "audit", "getEvent"}, ""))
)
var (
forward_AuditAPI_GetEvents_0 = runtime.ForwardResponseMessage
forward_AuditAPI_GetEvent_0 = runtime.ForwardResponseMessage
)
......@@ -200,6 +200,10 @@ func (m *GetEventsRequest) validate(all bool) error {
var errors []error
// no validation rules for PageToken
// no validation rules for Limit
switch m.Window.(type) {
case *GetEventsRequest_Range:
......@@ -1019,6 +1023,8 @@ func (m *Event) validate(all bool) error {
}
}
// no validation rules for Id
switch m.EventType.(type) {
case *Event_Event:
......@@ -1187,6 +1193,8 @@ func (m *GetEventsResponse) validate(all bool) error {
}
// no validation rules for NextPageToken
if len(errors) > 0 {
return GetEventsResponseMultiError(errors)
}
......@@ -1266,3 +1274,234 @@ var _ interface {
Cause() error
ErrorName() string
} = GetEventsResponseValidationError{}
// Validate checks the field values on GetEventRequest with the rules defined
// in the proto definition for this message. If any rules are violated, the
// first error encountered is returned, or nil if there are no violations.
func (m *GetEventRequest) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on GetEventRequest with the rules
// defined in the proto definition for this message. If any rules are
// violated, the result is a list of violation errors wrapped in
// GetEventRequestMultiError, or nil if none found.
func (m *GetEventRequest) ValidateAll() error {
return m.validate(true)
}
func (m *GetEventRequest) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
// no validation rules for EventId
if len(errors) > 0 {
return GetEventRequestMultiError(errors)
}
return nil
}
// GetEventRequestMultiError is an error wrapping multiple validation errors
// returned by GetEventRequest.ValidateAll() if the designated constraints
// aren't met.
type GetEventRequestMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m GetEventRequestMultiError) Error() string {
var msgs []string
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m GetEventRequestMultiError) AllErrors() []error { return m }
// GetEventRequestValidationError is the validation error returned by
// GetEventRequest.Validate if the designated constraints aren't met.
type GetEventRequestValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e GetEventRequestValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e GetEventRequestValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e GetEventRequestValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e GetEventRequestValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e GetEventRequestValidationError) ErrorName() string { return "GetEventRequestValidationError" }
// Error satisfies the builtin error interface
func (e GetEventRequestValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sGetEventRequest.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = GetEventRequestValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = GetEventRequestValidationError{}
// Validate checks the field values on GetEventResponse with the rules defined
// in the proto definition for this message. If any rules are violated, the
// first error encountered is returned, or nil if there are no violations.
func (m *GetEventResponse) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on GetEventResponse with the rules
// defined in the proto definition for this message. If any rules are
// violated, the result is a list of violation errors wrapped in
// GetEventResponseMultiError, or nil if none found.
func (m *GetEventResponse) ValidateAll() error {
return m.validate(true)
}
func (m *GetEventResponse) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
if all {
switch v := interface{}(m.GetEvent()).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, GetEventResponseValidationError{
field: "Event",
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, GetEventResponseValidationError{
field: "Event",
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(m.GetEvent()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return GetEventResponseValidationError{
field: "Event",
reason: "embedded message failed validation",
cause: err,
}
}
}
if len(errors) > 0 {
return GetEventResponseMultiError(errors)
}
return nil
}
// GetEventResponseMultiError is an error wrapping multiple validation errors
// returned by GetEventResponse.ValidateAll() if the designated constraints
// aren't met.
type GetEventResponseMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m GetEventResponseMultiError) Error() string {
var msgs []string
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m GetEventResponseMultiError) AllErrors() []error { return m }
// GetEventResponseValidationError is the validation error returned by
// GetEventResponse.Validate if the designated constraints aren't met.
type GetEventResponseValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e GetEventResponseValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e GetEventResponseValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e GetEventResponseValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e GetEventResponseValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e GetEventResponseValidationError) ErrorName() string { return "GetEventResponseValidationError" }
// Error satisfies the builtin error interface
func (e GetEventResponseValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sGetEventResponse.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = GetEventResponseValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = GetEventResponseValidationError{}
......@@ -23,6 +23,7 @@ const _ = grpc.SupportPackageIsVersion7
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type AuditAPIClient interface {
GetEvents(ctx context.Context, in *GetEventsRequest, opts ...grpc.CallOption) (*GetEventsResponse, error)
GetEvent(ctx context.Context, in *GetEventRequest, opts ...grpc.CallOption) (*GetEventResponse, error)
}
type auditAPIClient struct {
......@@ -42,11 +43,21 @@ func (c *auditAPIClient) GetEvents(ctx context.Context, in *GetEventsRequest, op
return out, nil
}
func (c *auditAPIClient) GetEvent(ctx context.Context, in *GetEventRequest, opts ...grpc.CallOption) (*GetEventResponse, error) {
out := new(GetEventResponse)
err := c.cc.Invoke(ctx, "/clutch.audit.v1.AuditAPI/GetEvent", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// AuditAPIServer is the server API for AuditAPI service.
// All implementations should embed UnimplementedAuditAPIServer
// for forward compatibility
type AuditAPIServer interface {
GetEvents(context.Context, *GetEventsRequest) (*GetEventsResponse, error)
GetEvent(context.Context, *GetEventRequest) (*GetEventResponse, error)
}
// UnimplementedAuditAPIServer should be embedded to have forward compatible implementations.
......@@ -56,6 +67,9 @@ type UnimplementedAuditAPIServer struct {
func (UnimplementedAuditAPIServer) GetEvents(context.Context, *GetEventsRequest) (*GetEventsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetEvents not implemented")
}
func (UnimplementedAuditAPIServer) GetEvent(context.Context, *GetEventRequest) (*GetEventResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetEvent not implemented")
}
// UnsafeAuditAPIServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to AuditAPIServer will
......@@ -86,6 +100,24 @@ func _AuditAPI_GetEvents_Handler(srv interface{}, ctx context.Context, dec func(
return interceptor(ctx, in, info, handler)
}
func _AuditAPI_GetEvent_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetEventRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(AuditAPIServer).GetEvent(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/clutch.audit.v1.AuditAPI/GetEvent",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(AuditAPIServer).GetEvent(ctx, req.(*GetEventRequest))
}
return interceptor(ctx, in, info, handler)
}
// AuditAPI_ServiceDesc is the grpc.ServiceDesc for AuditAPI service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
......@@ -97,6 +129,10 @@ var AuditAPI_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetEvents",
Handler: _AuditAPI_GetEvents_Handler,
},
{
MethodName: "GetEvent",
Handler: _AuditAPI_GetEvent_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "audit/v1/audit.proto",
......
......@@ -473,6 +473,20 @@ export namespace clutch {
* @returns Promise
*/
public getEvents(request: clutch.audit.v1.IGetEventsRequest): Promise<clutch.audit.v1.GetEventsResponse>;
/**
* Calls GetEvent.
* @param request GetEventRequest message or plain object
* @param callback Node-style callback called with the error, if any, and GetEventResponse
*/
public getEvent(request: clutch.audit.v1.IGetEventRequest, callback: clutch.audit.v1.AuditAPI.GetEventCallback): void;
/**
* Calls GetEvent.
* @param request GetEventRequest message or plain object
* @returns Promise
*/
public getEvent(request: clutch.audit.v1.IGetEventRequest): Promise<clutch.audit.v1.GetEventResponse>;
}
 
namespace AuditAPI {
......@@ -483,6 +497,13 @@ export namespace clutch {
* @param [response] GetEventsResponse
*/
type GetEventsCallback = (error: (Error|null), response?: clutch.audit.v1.GetEventsResponse) => void;
/**
* Callback as used by {@link clutch.audit.v1.AuditAPI#getEvent}.
* @param error Error, if any
* @param [response] GetEventResponse
*/
type GetEventCallback = (error: (Error|null), response?: clutch.audit.v1.GetEventResponse) => void;
}
 
/** Properties of a TimeRange. */
......@@ -547,6 +568,12 @@ export namespace clutch {
 
/** GetEventsRequest since */
since?: (google.protobuf.IDuration|null);
/** GetEventsRequest pageToken */
pageToken?: (string|null);
/** GetEventsRequest limit */
limit?: (number|Long|null);
}
 
/** Represents a GetEventsRequest. */
......@@ -564,6 +591,12 @@ export namespace clutch {
/** GetEventsRequest since. */
public since?: (google.protobuf.IDuration|null);
 
/** GetEventsRequest pageToken. */
public pageToken: string;
/** GetEventsRequest limit. */
public limit: (number|Long);
/** GetEventsRequest window. */
public window?: ("range"|"since");
 
......@@ -844,6 +877,9 @@ export namespace clutch {
 
/** Event event */
event?: (clutch.audit.v1.IRequestEvent|null);
/** Event id */
id?: (number|Long|null);
}
 
/** Represents an Event. */
......@@ -861,6 +897,9 @@ export namespace clutch {
/** Event event. */
public event?: (clutch.audit.v1.IRequestEvent|null);
 
/** Event id. */
public id: (number|Long);
/** Event eventType. */
public eventType?: "event";
 
......@@ -898,6 +937,9 @@ export namespace clutch {
 
/** GetEventsResponse events */
events?: (clutch.audit.v1.IEvent[]|null);
/** GetEventsResponse nextPageToken */
nextPageToken?: (string|null);
}
 
/** Represents a GetEventsResponse. */
......@@ -912,6 +954,9 @@ export namespace clutch {
/** GetEventsResponse events. */
public events: clutch.audit.v1.IEvent[];
 
/** GetEventsResponse nextPageToken. */
public nextPageToken: string;
/**
* Verifies a GetEventsResponse message.
* @param message Plain object to verify
......@@ -940,6 +985,102 @@ export namespace clutch {
*/
public toJSON(): { [k: string]: any };
}
/** Properties of a GetEventRequest. */
interface IGetEventRequest {
/** GetEventRequest eventId */
eventId?: (number|Long|null);
}
/** Represents a GetEventRequest. */
class GetEventRequest implements IGetEventRequest {
/**
* Constructs a new GetEventRequest.
* @param [properties] Properties to set
*/
constructor(properties?: clutch.audit.v1.IGetEventRequest);
/** GetEventRequest eventId. */
public eventId: (number|Long);
/**
* Verifies a GetEventRequest message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a GetEventRequest message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns GetEventRequest
*/
public static fromObject(object: { [k: string]: any }): clutch.audit.v1.GetEventRequest;
/**
* Creates a plain object from a GetEventRequest message. Also converts values to other types if specified.
* @param message GetEventRequest
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: clutch.audit.v1.GetEventRequest, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this GetEventRequest to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
/** Properties of a GetEventResponse. */
interface IGetEventResponse {
/** GetEventResponse event */
event?: (clutch.audit.v1.IEvent|null);
}
/** Represents a GetEventResponse. */
class GetEventResponse implements IGetEventResponse {
/**
* Constructs a new GetEventResponse.
* @param [properties] Properties to set
*/
constructor(properties?: clutch.audit.v1.IGetEventResponse);
/** GetEventResponse event. */
public event?: (clutch.audit.v1.IEvent|null);
/**
* Verifies a GetEventResponse message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a GetEventResponse message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns GetEventResponse
*/
public static fromObject(object: { [k: string]: any }): clutch.audit.v1.GetEventResponse;
/**
* Creates a plain object from a GetEventResponse message. Also converts values to other types if specified.
* @param message GetEventResponse
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: clutch.audit.v1.GetEventResponse, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this GetEventResponse to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
}
}
 
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment