From 744d6bb05404baada9da397a33556cd94286f9ed Mon Sep 17 00:00:00 2001 From: AlexsJones Date: Mon, 5 Aug 2024 11:13:30 +0100 Subject: [PATCH] feat: reworking protobuf files Signed-off-by: AlexsJones --- protobuf/schema/v1/analyzer.proto | 17 ----- protobuf/schema/v1/custom_analyzer.proto | 25 +++++++ .../schema/v1/server_analyzer_service.proto | 66 +++++++++++++++++ ...vice.proto => server_config_service.proto} | 73 +++++-------------- 4 files changed, 109 insertions(+), 72 deletions(-) delete mode 100644 protobuf/schema/v1/analyzer.proto create mode 100644 protobuf/schema/v1/custom_analyzer.proto create mode 100644 protobuf/schema/v1/server_analyzer_service.proto rename protobuf/schema/v1/{server-service.proto => server_config_service.proto} (63%) diff --git a/protobuf/schema/v1/analyzer.proto b/protobuf/schema/v1/analyzer.proto deleted file mode 100644 index 95c2555..0000000 --- a/protobuf/schema/v1/analyzer.proto +++ /dev/null @@ -1,17 +0,0 @@ -syntax = "proto3"; - -package schema.v1; - -import "schema/v1/server-service.proto"; - -option go_package = "schema/service/v1"; - -message AnalyzerRunRequest {} - -message AnalyzerRunResponse { - Result result = 1; -} - -service AnalyzerService { - rpc Run(AnalyzerRunRequest) returns (AnalyzerRunResponse) {} -} diff --git a/protobuf/schema/v1/custom_analyzer.proto b/protobuf/schema/v1/custom_analyzer.proto new file mode 100644 index 0000000..d8a131b --- /dev/null +++ b/protobuf/schema/v1/custom_analyzer.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; + +package schema.v1; +// well know type by google, gRPC gateway uses HTTP annotation. +import "google/api/annotations.proto"; + +import "schema/v1/server_analyzer_service.proto"; + +option go_package = "schema/service/v1"; + +message RunRequest {} + +message RunResponse { + schema.v1.Result result = 1; +} + +service CustomAnalyzerService { + + rpc Run (RunRequest) returns (RunResponse) { + option (google.api.http) = { + post: "/v1/run" + body: "*" + }; + } +} diff --git a/protobuf/schema/v1/server_analyzer_service.proto b/protobuf/schema/v1/server_analyzer_service.proto new file mode 100644 index 0000000..ddf9cdc --- /dev/null +++ b/protobuf/schema/v1/server_analyzer_service.proto @@ -0,0 +1,66 @@ +syntax = "proto3"; + +package schema.v1; + +// well know type by google, gRPC gateway uses HTTP annotation. +import "google/api/annotations.proto"; + +option go_package = "schema/service/v1"; + +message AnalyzeRequest { + string backend = 1; + string namespace = 2; + bool explain = 3; + bool anonymize = 4; + bool nocache = 5; + string language = 6; + int32 max_concurrency = 7; + string output = 8; + repeated string filters = 9; + string label_selector = 10; +} + +message SensitiveData { + string unmasked = 1; + string masked = 2; +} + +message ErrorDetail { + string text = 1; + repeated SensitiveData sensitive = 2; +} + +message Result { + string kind = 1; + string name = 2; + repeated ErrorDetail error = 3; + string details = 4; + string parent_object = 5; +} + +message AnalyzeResponse { + Error error = 1; + repeated string errors = 2; + string status = 3; + int32 problems = 4; + repeated Result results = 5; +} + +message Error { + string message = 1; + int32 code = 2; +} + + +service ServerAnalyzerService { + rpc Analyze(AnalyzeRequest) returns (AnalyzeResponse) { + // option type is http + option (google.api.http) = { + // this is url, for RESTfull/JSON api and method + // this line means when a HTTP post request comes with "/v1/analyze" call this rpc method over this service + // the request body AnalyzeRequest can be passed in to parameterize the request + post: "/v1/analyze" + body: "*" + }; + } +}; \ No newline at end of file diff --git a/protobuf/schema/v1/server-service.proto b/protobuf/schema/v1/server_config_service.proto similarity index 63% rename from protobuf/schema/v1/server-service.proto rename to protobuf/schema/v1/server_config_service.proto index 9a2de1b..c88f2d9 100644 --- a/protobuf/schema/v1/server-service.proto +++ b/protobuf/schema/v1/server_config_service.proto @@ -7,50 +7,6 @@ import "google/api/annotations.proto"; option go_package = "schema/service/v1"; -message AnalyzeRequest { - string backend = 1; - string namespace = 2; - bool explain = 3; - bool anonymize = 4; - bool nocache = 5; - string language = 6; - int32 max_concurrency = 7; - string output = 8; - repeated string filters = 9; - string label_selector = 10; -} - -message SensitiveData { - string unmasked = 1; - string masked = 2; -} - -message ErrorDetail { - string text = 1; - repeated SensitiveData sensitive = 2; -} - -message Result { - string kind = 1; - string name = 2; - repeated ErrorDetail error = 3; - string details = 4; - string parent_object = 5; -} - -message AnalyzeResponse { - Error error = 1; - repeated string errors = 2; - string status = 3; - int32 problems = 4; - repeated Result results = 5; -} - -message Error { - string message = 1; - int32 code = 2; -} - message Analysis { repeated AnalysisItem analysis = 1; } @@ -133,17 +89,14 @@ message ListIntegrationsResponse { Trivy trivy = 1; } -service ServerService { - rpc Analyze(AnalyzeRequest) returns (AnalyzeResponse) { - // option type is http - option (google.api.http) = { - // this is url, for RESTfull/JSON api and method - // this line means when a HTTP post request comes with "/v1/analyze" call this rpc method over this service - // the request body AnalyzeRequest can be passed in to parameterize the request - post: "/v1/analyze" - body: "*" - }; - } +message ShutdownRequest {} + +message ShutdownResponse { + string status = 1; +} + +service ServerConfigService { + rpc AddConfig(AddConfigRequest) returns (AddConfigResponse) {} rpc RemoveConfig(RemoveConfigRequest) returns (RemoveConfigResponse) {} rpc ListIntegrations(ListIntegrationsRequest) returns (ListIntegrationsResponse) { @@ -153,4 +106,14 @@ service ServerService { get: "/v1/list" }; } + // This command when run against the k8sgpt serve process will terminate it + // When that process is run in a Kubernetes pod it will restart it + rpc Shutdown(ShutdownRequest) returns (ShutdownResponse) { + // option type is http + option (google.api.http) = { + // this line means when a HTTP POST request comes with "/v1/shutdown" call this rpc method over this service + post: "/v1/shutdown" + body: "*" + }; + } }