From 137ede7b07074b70c0cdd6c5a685ea180cfabe6b Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Sat, 29 Jun 2024 10:00:56 -0700 Subject: [PATCH 1/2] first commit of proto files --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++ .gitignore | 25 ++++++++++++++++ Makefile | 18 ++++++++++++ proto/http.proto | 33 +++++++++++++++++++++ proto/kvstore.proto | 63 ++++++++++++++++++++++++++++++++++++++++ proto/metrics.proto | 28 ++++++++++++++++++ proto/sql.proto | 22 ++++++++++++++ proto/tarmac.proto | 19 ++++++++++++ 8 files changed, 246 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 proto/http.proto create mode 100644 proto/kvstore.proto create mode 100644 proto/metrics.proto create mode 100644 proto/sql.proto create mode 100644 proto/tarmac.proto diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b3a577e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: ci + +on: + push: + branches: + - main + pull_request: + +shell: bash + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + + - name: run protolint + uses: plexsystems/protolint-action@v0.7.0 + + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + + - name: Install Protoc + uses: arduino/setup-protoc@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: '1.21' + - name: Install protoc-gen-go + run: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest + + - name: generate language files + run: make all clean diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3d1484 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Ignore Protobuf compiler generated files +*.pb.go +*.pb.cc +*.pb.h +*.pb.java +*.pb.py +*.pb2.py + +# Ignore build files +/build/ +*.o +*.so +*.dylib +*.a +*.exe + +# Ignore IDE and editor-specific files +.idea/ +.vscode/ +*.iml +*.swp + +# Ignore OS-specific files +.DS_Store +Thumbs.db diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5aa0949 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +OUT_DIR=build + +# Go-specific settings +GO_OUT=$(OUT_DIR)/go + +.PHONY: all clean go + +all: go + +go: + @echo "Generating Go code..." + mkdir -p $(GO_OUT) + protoc -I=./proto --go_out=$(GO_OUT) ./proto/*.proto + +clean: + @echo "Cleaning up generated files..." + rm -rf $(OUT_DIR) + diff --git a/proto/http.proto b/proto/http.proto new file mode 100644 index 0000000..918ab62 --- /dev/null +++ b/proto/http.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; + +package tarmac.http; + +import "tarmac.proto"; +option go_package = "github.com/tarmac-project/tarmac/proto"; + +// HTTPClient is a structure used to create HTTP calls to remote systems. +message HTTPClient { + // Method is the HTTP method type for the HTTP request; valid options are GET, POST, PUT, PATCH, HEAD, & DELETE. + string method = 1; + // Headers are the HTTP headers to include in the HTTP request. + map headers = 2; + // URL is the HTTP URL to call. + string url = 3; + // Body is the user-supplied HTTP body data. This field should contain the request payload data. + bytes body = 4; + // Insecure will disable TLS host verification; this is common with self-signed certificates; however, use caution. + bool insecure = 5; +} + +// HTTPClientResponse is a structure supplied as a response message to a remote HTTP call callback function. +message HTTPClientResponse { + // Status is the human readable error message or success message for function execution. + tarmac.Status status = 1; + // Code is the HTTP Status Code returned from the target server. + int32 code = 2; + // Headers are the HTTP headers returned from the HTTP request. + map headers = 3; + // Body is the server-supplied HTTP payload data. The server-supplied payload will be a byte slice. + bytes body = 4; +} + diff --git a/proto/kvstore.proto b/proto/kvstore.proto new file mode 100644 index 0000000..c6ac78b --- /dev/null +++ b/proto/kvstore.proto @@ -0,0 +1,63 @@ +syntax = "proto3"; + +package tarmac.kvstore; + +import "tarmac.proto"; +option go_package = "github.com/tarmac-project/tarmac/proto"; + +// KVStoreGet is a structure used to create Get request callbacks to the Tarmac KVStore interface. +// This structure is a general request type used for all KVStore types provided by Tarmac. +message KVStoreGet { + // Key is the index key to use when accessing the key:value store. + string key = 1; +} + +// KVStoreGetResponse is a structure supplied as response messages to KVStore Get requests. +// This response is a general response type used for all KVStore types provided by Tarmac. +message KVStoreGetResponse { + // Status is the human readable error message or success message for function execution. + tarmac.Status status = 1; + // Data is the response data provided by the key:value store. + // This data is a byte slice to provide a simple field for arbitrary data. + bytes data = 2; +} + +// KVStoreSet is a structure used to create a Set request callback to the Tarmac KVStore interface. +// This structure is a general request type used for all KVStore types provided by Tarmac. +message KVStoreSet { + // Key is the index key used to store the data. + string key = 1; + // Data is the user-supplied key:value data. + // Tarmac expects this field to be a byte slice. + bytes data = 2; +} + +// KVStoreSetResponse is a structure supplied as a response message to the KVStore Set callback function. +// This response is a general response type used for all KVStore types provided by Tarmac. +message KVStoreSetResponse { + // Status is the human readable error message or success message for function execution. + tarmac.Status status = 1; +} + +// KVStoreDelete is a structure used to create Delete callback requests to the Tarmac KVStore interface. +// This structure is a general request type used for all KVStore types provided by Tarmac. +message KVStoreDelete { + // Key is the index key used to store the data. + string key = 1; +} + +// KVStoreDeleteResponse is a structure supplied as a response message to the KVStore Delete callback function. +// This response is a general response type used for all KVStore types provided by Tarmac. +message KVStoreDeleteResponse { + // Status is the human readable error message or success message for function execution. + tarmac.Status status = 1; +} + +// KVStoreKeysResponse is a structure supplied as a response message to the KVStore Keys callback function. +// This response is a general response type used for all KVStore types provided by Tarmac. +message KVStoreKeysResponse { + // Status is the human readable error message or success message for function execution. + tarmac.Status status = 1; + // Keys is a list of keys available within the KV Store. + repeated string keys = 2; +} diff --git a/proto/metrics.proto b/proto/metrics.proto new file mode 100644 index 0000000..4db59b1 --- /dev/null +++ b/proto/metrics.proto @@ -0,0 +1,28 @@ +syntax = "proto3"; + +package tarmac.metrics; + +option go_package = "github.com/tarmac-project/tarmac/proto"; + +// MetricsCounter is a structure used to create Counter metrics callback requests to the Tarmac Metrics interface. +message MetricsCounter { + // Name is the name of the metric as exposed via the metrics HTTP end-point. + string name = 1; +} + +// MetricsGauge is a structure used to create Gauge metrics callback requests to the Tarmac Metrics interface. +message MetricsGauge { + // Name is the name of the metric as exposed via the metrics HTTP end-point. + string name = 1; + // Action is the action to be performed for the Gauge metric. + // Valid options are inc (Increment) and dec (Decrement). + string action = 2; // inc or dec +} + +// MetricsHistogram is a structure used to create Histogram metrics callback requests to the Tarmac Metrics interface. +message MetricsHistogram { + // Name is the name of the metric as exposed via the metrics HTTP end-point. + string name = 1; + // Value is the value to Observe for the Histogram metric. + double value = 2; +} diff --git a/proto/sql.proto b/proto/sql.proto new file mode 100644 index 0000000..56c9783 --- /dev/null +++ b/proto/sql.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +package tarmac.sql; + +import "tarmac.proto"; +option go_package = "github.com/tarmac-project/tarmac/proto"; + +// SQLQuery is a structure used to create SQL queries to a SQL Database. +message SQLQuery { + // Query is the SQL Query to be executed. This field should be a byte slice to avoid conflicts with JSON encoding. + bytes query = 1; +} + +// SQLQueryResponse is a structure supplied as a response message to a SQL Database Query. +message SQLQueryResponse { + // Status is the human readable error message or success message for function execution. + tarmac.Status status = 1; + // Data is a byte slice representing a JSON structure of the returned rows. + // Each row will contain a column name based map to access data. + bytes data = 2; +} + diff --git a/proto/tarmac.proto b/proto/tarmac.proto new file mode 100644 index 0000000..9ad4b7d --- /dev/null +++ b/proto/tarmac.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package tarmac; + +option go_package = "github.com/tarmac-project/tarmac/proto"; + +// Status is used to return a status code and message to clients when performing host callbacks to Tarmac. +// The status code will indicate failure or success. +// +// Status codes are as follows: +// 000 - Success +// 100 - Failure +// +message Status { + // Code is the status code for callback execution. + int32 code = 1; + // Status is the human readable error message or success message for function execution. + string status = 2; +} From 3d1ba9332c0bade98f98415a86bbdb99b15bf6fa Mon Sep 17 00:00:00 2001 From: Benjamin Cane Date: Sat, 29 Jun 2024 10:09:03 -0700 Subject: [PATCH 2/2] chore(lint): ensuring protofiles pass linter --- proto/http.proto | 18 ++++++++----- proto/kvstore.proto | 61 ++++++++++++++++++++++++++++++++------------- proto/metrics.proto | 9 ++++--- proto/sql.proto | 9 ++++--- proto/tarmac.proto | 7 ++++-- 5 files changed, 72 insertions(+), 32 deletions(-) diff --git a/proto/http.proto b/proto/http.proto index 918ab62..f2946d4 100644 --- a/proto/http.proto +++ b/proto/http.proto @@ -7,27 +7,33 @@ option go_package = "github.com/tarmac-project/tarmac/proto"; // HTTPClient is a structure used to create HTTP calls to remote systems. message HTTPClient { - // Method is the HTTP method type for the HTTP request; valid options are GET, POST, PUT, PATCH, HEAD, & DELETE. + // Method is the HTTP method type for the HTTP request; valid options are + // GET, POST, PUT, PATCH, HEAD, & DELETE. string method = 1; // Headers are the HTTP headers to include in the HTTP request. map headers = 2; // URL is the HTTP URL to call. string url = 3; - // Body is the user-supplied HTTP body data. This field should contain the request payload data. + // Body is the user-supplied HTTP body data. This field should contain the + // request payload data. bytes body = 4; - // Insecure will disable TLS host verification; this is common with self-signed certificates; however, use caution. + // Insecure will disable TLS host verification; this is common with + // self-signed certificates; however, use caution. bool insecure = 5; } -// HTTPClientResponse is a structure supplied as a response message to a remote HTTP call callback function. +// HTTPClientResponse is a structure supplied as a response message to a remote +// HTTP call callback function. message HTTPClientResponse { - // Status is the human readable error message or success message for function execution. + // Status is the human readable error message or success message for function + // execution. tarmac.Status status = 1; // Code is the HTTP Status Code returned from the target server. int32 code = 2; // Headers are the HTTP headers returned from the HTTP request. map headers = 3; - // Body is the server-supplied HTTP payload data. The server-supplied payload will be a byte slice. + // Body is the server-supplied HTTP payload data. The server-supplied payload + // will be a byte slice. bytes body = 4; } diff --git a/proto/kvstore.proto b/proto/kvstore.proto index c6ac78b..9e76ca2 100644 --- a/proto/kvstore.proto +++ b/proto/kvstore.proto @@ -5,25 +5,35 @@ package tarmac.kvstore; import "tarmac.proto"; option go_package = "github.com/tarmac-project/tarmac/proto"; -// KVStoreGet is a structure used to create Get request callbacks to the Tarmac KVStore interface. -// This structure is a general request type used for all KVStore types provided by Tarmac. +// KVStoreGet is a structure used to create Get request callbacks to the Tarmac +// KVStore interface. +// +// This structure is a general request type used for all KVStore types provided +// by Tarmac. message KVStoreGet { // Key is the index key to use when accessing the key:value store. string key = 1; } -// KVStoreGetResponse is a structure supplied as response messages to KVStore Get requests. -// This response is a general response type used for all KVStore types provided by Tarmac. +// KVStoreGetResponse is a structure supplied as response messages to KVStore +// Get requests. +// +// This response is a general response type used for all KVStore types provided +// by Tarmac. message KVStoreGetResponse { - // Status is the human readable error message or success message for function execution. + // Status is the human readable error message or success message for function + // execution. tarmac.Status status = 1; // Data is the response data provided by the key:value store. // This data is a byte slice to provide a simple field for arbitrary data. bytes data = 2; } -// KVStoreSet is a structure used to create a Set request callback to the Tarmac KVStore interface. -// This structure is a general request type used for all KVStore types provided by Tarmac. +// KVStoreSet is a structure used to create a Set request callback to the +// Tarmac KVStore interface. +// +// This structure is a general request type used for all KVStore types provided +// by Tarmac. message KVStoreSet { // Key is the index key used to store the data. string key = 1; @@ -32,31 +42,46 @@ message KVStoreSet { bytes data = 2; } -// KVStoreSetResponse is a structure supplied as a response message to the KVStore Set callback function. -// This response is a general response type used for all KVStore types provided by Tarmac. +// KVStoreSetResponse is a structure supplied as a response message to the +// KVStore Set callback function. +// +// This response is a general response type used for all KVStore types provided +// by Tarmac. message KVStoreSetResponse { - // Status is the human readable error message or success message for function execution. + // Status is the human readable error message or success message for function + // execution. tarmac.Status status = 1; } -// KVStoreDelete is a structure used to create Delete callback requests to the Tarmac KVStore interface. -// This structure is a general request type used for all KVStore types provided by Tarmac. +// KVStoreDelete is a structure used to create Delete callback requests to the +// Tarmac KVStore interface. +// +// This structure is a general request type used for all KVStore types provided +// by Tarmac. message KVStoreDelete { // Key is the index key used to store the data. string key = 1; } -// KVStoreDeleteResponse is a structure supplied as a response message to the KVStore Delete callback function. -// This response is a general response type used for all KVStore types provided by Tarmac. +// KVStoreDeleteResponse is a structure supplied as a response message to the +// KVStore Delete callback function. +// +// This response is a general response type used for all KVStore types provided +// by Tarmac. message KVStoreDeleteResponse { - // Status is the human readable error message or success message for function execution. + // Status is the human readable error message or success message for function + // execution. tarmac.Status status = 1; } -// KVStoreKeysResponse is a structure supplied as a response message to the KVStore Keys callback function. -// This response is a general response type used for all KVStore types provided by Tarmac. +// KVStoreKeysResponse is a structure supplied as a response message to the +// KVStore Keys callback function. + +// This response is a general response type used for all KVStore types provided +// by Tarmac. message KVStoreKeysResponse { - // Status is the human readable error message or success message for function execution. + // Status is the human readable error message or success message for function + // execution. tarmac.Status status = 1; // Keys is a list of keys available within the KV Store. repeated string keys = 2; diff --git a/proto/metrics.proto b/proto/metrics.proto index 4db59b1..f22496c 100644 --- a/proto/metrics.proto +++ b/proto/metrics.proto @@ -4,13 +4,15 @@ package tarmac.metrics; option go_package = "github.com/tarmac-project/tarmac/proto"; -// MetricsCounter is a structure used to create Counter metrics callback requests to the Tarmac Metrics interface. +// MetricsCounter is a structure used to create Counter metrics callback +// requests to the Tarmac Metrics interface. message MetricsCounter { // Name is the name of the metric as exposed via the metrics HTTP end-point. string name = 1; } -// MetricsGauge is a structure used to create Gauge metrics callback requests to the Tarmac Metrics interface. +// MetricsGauge is a structure used to create Gauge metrics callback requests +// to the Tarmac Metrics interface. message MetricsGauge { // Name is the name of the metric as exposed via the metrics HTTP end-point. string name = 1; @@ -19,7 +21,8 @@ message MetricsGauge { string action = 2; // inc or dec } -// MetricsHistogram is a structure used to create Histogram metrics callback requests to the Tarmac Metrics interface. +// MetricsHistogram is a structure used to create Histogram metrics callback +// requests to the Tarmac Metrics interface. message MetricsHistogram { // Name is the name of the metric as exposed via the metrics HTTP end-point. string name = 1; diff --git a/proto/sql.proto b/proto/sql.proto index 56c9783..abbe40c 100644 --- a/proto/sql.proto +++ b/proto/sql.proto @@ -7,13 +7,16 @@ option go_package = "github.com/tarmac-project/tarmac/proto"; // SQLQuery is a structure used to create SQL queries to a SQL Database. message SQLQuery { - // Query is the SQL Query to be executed. This field should be a byte slice to avoid conflicts with JSON encoding. + // Query is the SQL Query to be executed. This field should be a byte slice + // to avoid conflicts with JSON encoding. bytes query = 1; } -// SQLQueryResponse is a structure supplied as a response message to a SQL Database Query. +// SQLQueryResponse is a structure supplied as a response message to a SQL +// Database Query. message SQLQueryResponse { - // Status is the human readable error message or success message for function execution. + // Status is the human readable error message or success message for function + // execution. tarmac.Status status = 1; // Data is a byte slice representing a JSON structure of the returned rows. // Each row will contain a column name based map to access data. diff --git a/proto/tarmac.proto b/proto/tarmac.proto index 9ad4b7d..acf66a0 100644 --- a/proto/tarmac.proto +++ b/proto/tarmac.proto @@ -4,7 +4,9 @@ package tarmac; option go_package = "github.com/tarmac-project/tarmac/proto"; -// Status is used to return a status code and message to clients when performing host callbacks to Tarmac. +// Status is used to return a status code and message to clients when +// performing host callbacks to Tarmac. +// // The status code will indicate failure or success. // // Status codes are as follows: @@ -14,6 +16,7 @@ option go_package = "github.com/tarmac-project/tarmac/proto"; message Status { // Code is the status code for callback execution. int32 code = 1; - // Status is the human readable error message or success message for function execution. + // Status is the human readable error message or success message for function + // execution. string status = 2; }