From 3561e48f3ac37674a3e52eb5fe22cfb7aa4ecb45 Mon Sep 17 00:00:00 2001 From: solidiquis Date: Fri, 5 Apr 2024 09:27:47 -0700 Subject: [PATCH 1/6] Initial protos --- .githooks/pre-commit | 26 +++ .github/workflows/buf.yaml | 10 + buf.gen.yaml | 25 +++ protos/buf.lock | 13 ++ protos/buf.yaml | 10 + .../annotation_logs/v1/annotation_logs.proto | 147 +++++++++++++ protos/sift/annotations/v1/annotations.proto | 203 ++++++++++++++++++ protos/sift/assets/v1/assets.proto | 82 +++++++ .../common/type/v1/channel_data_type.proto | 19 ++ protos/sift/common/type/v1/organization.proto | 10 + protos/sift/common/type/v1/user.proto | 14 ++ .../sift/notifications/v1/notifications.proto | 98 +++++++++ protos/sift/runs/v2/runs.proto | 148 +++++++++++++ protos/sift/tags/v1/tags.proto | 18 ++ protos/sift/users/v2/users.proto | 43 ++++ sift_gen | 29 +++ 16 files changed, 895 insertions(+) create mode 100644 .githooks/pre-commit create mode 100644 .github/workflows/buf.yaml create mode 100644 buf.gen.yaml create mode 100644 protos/buf.lock create mode 100644 protos/buf.yaml create mode 100644 protos/sift/annotation_logs/v1/annotation_logs.proto create mode 100644 protos/sift/annotations/v1/annotations.proto create mode 100644 protos/sift/assets/v1/assets.proto create mode 100644 protos/sift/common/type/v1/channel_data_type.proto create mode 100644 protos/sift/common/type/v1/organization.proto create mode 100644 protos/sift/common/type/v1/user.proto create mode 100644 protos/sift/notifications/v1/notifications.proto create mode 100644 protos/sift/runs/v2/runs.proto create mode 100644 protos/sift/tags/v1/tags.proto create mode 100644 protos/sift/users/v2/users.proto create mode 100755 sift_gen diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 00000000..d662eb52 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +if [[ ! -f $(which buf) ]]; then + echo "Could not find 'buf' executable. Ensure that it is installed in your path." + exit 2 +fi + +# cd back to repo root +cd ../../ + +changed_files=($(git diff --cached --name-only --diff-filter=ACM | grep '^protos/' | grep '**.proto$')) + +if [[ -n "$changed_files" ]]; then + echo "running buf lint protos" + buf lint protos || { + echo -e "ERROR! protos linting failed. Please fix the errors and recommit.\n" + exit 1 + } + echo "running buf format protos" + buf format protos -w --exit-code || { + echo -e "ERROR! protos file were reformatted. Please stage the changes and recommit.\n" + exit 1 + } +fi + +exit 0 diff --git a/.github/workflows/buf.yaml b/.github/workflows/buf.yaml new file mode 100644 index 00000000..fd486350 --- /dev/null +++ b/.github/workflows/buf.yaml @@ -0,0 +1,10 @@ +name: Sift Protos + +on: pull_request +jobs: + lint-protos: + - uses: actions/checkout@v2 + - uses: bufbuild/buf-setup-action@v1 + - uses: bufbuild/buf-lint-action@v1 + with: + input: protos diff --git a/buf.gen.yaml b/buf.gen.yaml new file mode 100644 index 00000000..55f6e138 --- /dev/null +++ b/buf.gen.yaml @@ -0,0 +1,25 @@ +version: v1 +managed: + enabled: true +plugins: + - plugin: buf.build/protocolbuffers/go:v1.28.1 + out: gen/go + opt: paths=source_relative + - plugin: go-vtproto + out: gen/go + opt: paths=source_relative + - plugin: buf.build/grpc-ecosystem/gateway:v2.16.2 + out: gen/go + opt: paths=source_relative + - plugin: buf.build/grpc/java:v1.54.1 + out: gen/java + - plugin: buf.build/protocolbuffers/java:v21.7 + out: gen/java + - plugin: buf.build/grpc/python:v1.57.0 + out: gen/python + - plugin: buf.build/protocolbuffers/python:v26.1 + out: gen/python + - plugin: buf.build/community/neoeinstein-prost:v0.3.1 + out: gen/rust + - plugin: buf.build/community/neoeinstein-tonic:v0.4.0 + out: gen/rust diff --git a/protos/buf.lock b/protos/buf.lock new file mode 100644 index 00000000..4ffc27f8 --- /dev/null +++ b/protos/buf.lock @@ -0,0 +1,13 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: googleapis + repository: googleapis + commit: 7a6bc1e3207144b38e9066861e1de0ff + digest: shake256:d646836485c34192401253703c4e7ce899c826fceec060bf4b2a62c4749bd9976dc960833e134a1f814725e1ffd60b1bb3cf0335a7e99ef0e8cec34b070ffb66 + - remote: buf.build + owner: grpc-ecosystem + repository: grpc-gateway + commit: 3f42134f4c564983838425bc43c7a65f + digest: shake256:3d11d4c0fe5e05fda0131afefbce233940e27f0c31c5d4e385686aea58ccd30f72053f61af432fa83f1fc11cda57f5f18ca3da26a29064f73c5a0d076bba8d92 diff --git a/protos/buf.yaml b/protos/buf.yaml new file mode 100644 index 00000000..f68aef5e --- /dev/null +++ b/protos/buf.yaml @@ -0,0 +1,10 @@ +version: v1 +breaking: + use: + - FILE +lint: + use: + - DEFAULT +deps: + - buf.build/googleapis/googleapis + - buf.build/grpc-ecosystem/grpc-gateway diff --git a/protos/sift/annotation_logs/v1/annotation_logs.proto b/protos/sift/annotation_logs/v1/annotation_logs.proto new file mode 100644 index 00000000..a89dcb3c --- /dev/null +++ b/protos/sift/annotation_logs/v1/annotation_logs.proto @@ -0,0 +1,147 @@ +syntax = "proto3"; + +package sift.annotation_logs.v1; + +import "google/api/annotations.proto"; +import "google/api/field_behavior.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/annotation_logs/v1;annotation_logsv1pb"; + +service AnnotationLogService { + rpc CreateAnnotationLog(CreateAnnotationLogRequest) returns (CreateAnnotationLogResponse) { + option (google.api.http) = { + post: "/api/v1/annotations/{annotation_id}/logs" + body: "*" + }; + } + rpc ListAnnotationLogs(ListAnnotationLogsRequest) returns (ListAnnotationLogsResponse) { + option (google.api.http) = {get: "/api/v1/annotations/{annotation_id}/logs"}; + } + rpc DeleteAnnotationLog(DeleteAnnotationLogRequest) returns (DeleteAnnotationLogResponse) { + option (google.api.http) = {delete: "/api/v1/annotations/{annotation_id}/logs/{annotation_log_id}"}; + } +} + +// The request for a call to `AnnotationLogService_CreateAnnotationLog` to create an annotation log. +message CreateAnnotationLogRequest { + // The ID of the parent annotation associated to associate with the new annotation log. + string annotation_id = 1 [(google.api.field_behavior) = REQUIRED]; + + // The kind of annotation log to create. + AnnotationLogKind kind = 2 [(google.api.field_behavior) = REQUIRED]; + + // The properties associated with the specific kind of annotation log. + oneof properties { + AnnotationLogAssignedProperties assigned = 3; + AnnotationLogStateUpdateProperties state_update = 4; + AnnotationLogCommentProperties comment = 5; + } +} + +// The response of a call to `AnnotationLogService_CreateAnnotationLog`. +message CreateAnnotationLogResponse { + AnnotationLogSearchResult annotation_log = 1; +} + +// The request for a call to `AnnotationLogService_ListAnnotationLogs` to retrieve annotation logs. +message ListAnnotationLogsRequest { + // The ID of the parent annotation associated with the annotation logs. + string annotation_id = 1 [(google.api.field_behavior) = REQUIRED]; + + // The maximum number of annotation logs to return. + // The service may return fewer than this value. + // If unspecified, at most 50 annotation logs will be returned. + // The maximum value is 1000; values above 1000 will be coerced to 1000. + uint32 page_size = 2 [(google.api.field_behavior) = OPTIONAL]; + + // A page token, received from a previous `ListAnnotationLogs` call. + // Provide this to retrieve the subsequent page. + // When paginating, all other parameters provided to `ListAnnotationLogs` must match + // the call that provided the page token. + string page_token = 3 [(google.api.field_behavior) = OPTIONAL]; + + // A [Common Expression Language (CEL)](https://github.com/google/cel-spec) filter string. + // Available fields to filter by are `annotation_log_id`, `annotation_id`, `created_by_user_id`, + // `created_date`, `modified_date`, and `kind`. + // For further information about how to use CELs, please refer to [this guide](https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions). + // For more information about the fields used for filtering, please refer to [this definition](/ingestion/api#sift_annotation_logs_v1_annotation_logs-proto). Optional. + string filter = 4 [(google.api.field_behavior) = OPTIONAL]; +} + +// The response of a call to `AnnotationLogService_ListAnnotationLogs`. +message ListAnnotationLogsResponse { + repeated AnnotationLogSearchResult annotation_logs = 1; + string next_page_token = 2; +} + +// The request for a call to `AnnotationLogService_DeleteAnnotationLog` to delete an annotation log. +message DeleteAnnotationLogRequest { + // The ID of the parent annotation associated with the annotation log to be deleted. + string annotation_id = 1 [(google.api.field_behavior) = REQUIRED]; + // ID of the annotation log to be deleted. + string annotation_log_id = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// The Response of a call to `AnnotationLogService_DeleteAnnotationLog`. +message DeleteAnnotationLogResponse {} + +message AnnotationLogSearchResult { + string annotation_log_id = 1 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp created_date = 2 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp modified_date = 3 [(google.api.field_behavior) = REQUIRED]; + string annotation_id = 4 [(google.api.field_behavior) = REQUIRED]; + AnnotationLogKind kind = 5 [(google.api.field_behavior) = REQUIRED]; + string created_by_user_id = 6 [(google.api.field_behavior) = REQUIRED]; + string created_by_user_name = 7 [(google.api.field_behavior) = REQUIRED]; + oneof properties { + AnnotationLogAssignedProperties assigned = 8; + AnnotationLogStateUpdateProperties state_update = 9; + AnnotationLogCommentProperties comment = 10; + } +} + +enum AnnotationLogKind { + ANNOTATION_LOG_KIND_UNSPECIFIED = 0; + ANNOTATION_LOG_KIND_COMMENT = 1; + ANNOTATION_LOG_KIND_STATE_UPDATE = 2; + ANNOTATION_LOG_KIND_ASSIGNED = 3; +} + +message AnnotationLogAssignedProperties { + string assigned_to_user_id = 1 [(google.api.field_behavior) = REQUIRED]; + string assigned_to_user_email = 2 [(google.api.field_behavior) = REQUIRED]; +} + +message AnnotationLogStateUpdateProperties { + AnnotationLogState state = 1 [(google.api.field_behavior) = REQUIRED]; +} + +enum AnnotationLogState { + ANNOTATION_LOG_STATE_UNSPECIFIED = 0; + ANNOTATION_LOG_STATE_CREATED = 1; + ANNOTATION_LOG_STATE_OPEN = 2; + ANNOTATION_LOG_STATE_FLAGGED = 3; + ANNOTATION_LOG_STATE_RESOLVED = 4; +} + +message AnnotationLogCommentProperties { + repeated AnnotationCommentBodyElement body = 1; +} + +message AnnotationCommentBodyElement { + AnnotationCommentBodyElementType type = 1 [(google.api.field_behavior) = REQUIRED]; + string text = 2 [(google.api.field_behavior) = OPTIONAL]; + AnnotationCommentUserMention user_mention = 3 [(google.api.field_behavior) = OPTIONAL]; +} + +message AnnotationCommentUserMention { + string user_id = 1 [(google.api.field_behavior) = REQUIRED]; + string user_email = 2 [(google.api.field_behavior) = REQUIRED]; +} + +enum AnnotationCommentBodyElementType { + ANNOTATION_COMMENT_BODY_ELEMENT_TYPE_UNSPECIFIED = 0; + ANNOTATION_COMMENT_BODY_ELEMENT_TYPE_TEXT = 1; + ANNOTATION_COMMENT_BODY_ELEMENT_TYPE_USER_MENTION = 2; +} diff --git a/protos/sift/annotations/v1/annotations.proto b/protos/sift/annotations/v1/annotations.proto new file mode 100644 index 00000000..a39fec88 --- /dev/null +++ b/protos/sift/annotations/v1/annotations.proto @@ -0,0 +1,203 @@ +syntax = "proto3"; + +package sift.annotations.v1; + +import "google/api/annotations.proto"; +import "google/api/field_behavior.proto"; +import "google/protobuf/field_mask.proto"; +import "google/protobuf/timestamp.proto"; +import "protoc-gen-openapiv2/options/annotations.proto"; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/annotations/v1;annotationsv1pb"; + +option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { + info: {title: "Annotation service"} +}; + +service AnnotationService { + rpc CreateAnnotation(CreateAnnotationRequest) returns (CreateAnnotationResponse) { + option (google.api.http) = { + post: "/api/v1/annotations" + body: "*" + }; + } + rpc DeleteAnnotation(DeleteAnnotationRequest) returns (DeleteAnnotationResponse) { + option (google.api.http) = {delete: "/api/v1/annotations/{annotation_id}"}; + } + rpc BatchDeleteAnnotations(BatchDeleteAnnotationsRequest) returns (BatchDeleteAnnotationsResponse) { + option (google.api.http) = { + post: "/api/v1/annotations:batchDelete", + body: "*" + }; + } + rpc ListAnnotations(ListAnnotationsRequest) returns (ListAnnotationsResponse) { + option (google.api.http) = {get: "/api/v1/annotations"}; + } + rpc GetAnnotation(GetAnnotationRequest) returns (GetAnnotationResponse) { + option (google.api.http) = {get: "/api/v1/annotations/{annotation_id}"}; + } + rpc UpdateAnnotation(UpdateAnnotationRequest) returns (UpdateAnnotationResponse) { + option (google.api.http) = { + patch: "/api/v1/annotations" + body: "*" + }; + } +} + +message Annotation { + string annotation_id = 1 [(google.api.field_behavior) = REQUIRED]; + string name = 2 [(google.api.field_behavior) = REQUIRED]; + string description = 3 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp start_time = 4 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp end_time = 5 [(google.api.field_behavior) = REQUIRED]; + string created_by_user_id = 6 [(google.api.field_behavior) = REQUIRED]; + string modified_by_user_id = 7 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp created_date = 8 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp modified_date = 9 [(google.api.field_behavior) = REQUIRED]; + optional string run_id = 10 [(google.api.field_behavior) = OPTIONAL]; + optional AnnotationState state = 11 [(google.api.field_behavior) = OPTIONAL]; + string organization_id = 12 [(google.api.field_behavior) = REQUIRED]; + string assigned_to_user_id = 13 [(google.api.field_behavior) = OPTIONAL]; + AnnotationType annotation_type = 14 [(google.api.field_behavior) = REQUIRED]; + repeated string tags = 15 [(google.api.field_behavior) = REQUIRED]; + optional string legend_config = 16 [(google.api.field_behavior) = OPTIONAL]; + optional string created_by_condition_id = 17 [(google.api.field_behavior) = OPTIONAL]; +} + +enum AnnotationState { + ANNOTATION_STATE_UNSPECIFIED = 0; + ANNOTATION_STATE_OPEN = 1; + ANNOTATION_STATE_FLAGGED = 2; + ANNOTATION_STATE_RESOLVED = 3; +} +enum AnnotationType { + ANNOTATION_TYPE_UNSPECIFIED = 0; + ANNOTATION_TYPE_DATA_REVIEW = 1; + ANNOTATION_TYPE_PHASE = 2; +} + +message AnnotationLinkedChannelsChannel { + string channel_id = 1 [(google.api.field_behavior) = REQUIRED]; +} + +message AnnotationLinkedChannelsBitFieldElement { + string channel_id = 1 [(google.api.field_behavior) = REQUIRED]; + string bit_field_name = 2 [(google.api.field_behavior) = REQUIRED]; +} + +message AnnotationLinkedChannel { + oneof type { + AnnotationLinkedChannelsChannel channel = 1; + AnnotationLinkedChannelsBitFieldElement bit_field_element = 2; + } +} + +// The request for a call to `AnnotationService_CreateAnnotation` to create a new annotation. +// At least 1 asset, tag, or channel must be specified. +message CreateAnnotationRequest { + // The name assigned to the new annotation. + string name = 1 [(google.api.field_behavior) = REQUIRED]; + // A short description about the new annotation. + string description = 2 [(google.api.field_behavior) = OPTIONAL]; + // When the annotation starts. + google.protobuf.Timestamp start_time = 3 [(google.api.field_behavior) = REQUIRED]; + // When the annotation ends. + google.protobuf.Timestamp end_time = 4 [(google.api.field_behavior) = REQUIRED]; + // The names of the assets to associate with this annotation. + repeated string assets = 5 [(google.api.field_behavior) = OPTIONAL]; + // The channels to associate with this annotation. + repeated AnnotationLinkedChannel linked_channels = 6 [(google.api.field_behavior) = OPTIONAL]; + // The names of the tags to associate with this annotation. + repeated string tags = 7 [(google.api.field_behavior) = OPTIONAL]; + // The ID of the run that this annotation is associated with. + optional string run_id = 8 [(google.api.field_behavior) = OPTIONAL]; + // The ID of the user that this annotation is assigned to. + optional string assign_to_user_id = 9 [(google.api.field_behavior) = OPTIONAL]; + // The organization associated with this annotation. An organization ID is only required + // if the user belongs to multiple organizations. + string organization_id = 10 [(google.api.field_behavior) = OPTIONAL]; + // The state of the annotation. If an annotation has an `annotation_type` of `ANNOTATION_TYPE_PHASE`, then state must be + // unset, otherwise an error will be returned. + optional AnnotationState state = 11 [(google.api.field_behavior) = OPTIONAL]; + // The type of the annotation. + AnnotationType annotation_type = 12 [(google.api.field_behavior) = OPTIONAL]; + // The ID of the rule condition that created this annotation. + optional string created_by_condition_id = 14 [(google.api.field_behavior) = OPTIONAL]; + // A JSON string containing the axes configuration of the annotation's linked channels. + optional string legend_config = 13 [(google.api.field_behavior) = OPTIONAL]; +} + +// The result of a call to `AnnotationService_CreateAnnotation`. +message CreateAnnotationResponse { + Annotation annotation = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The request for a call to `AnnotationService_DeleteAnnotation`. +message DeleteAnnotationRequest { + string annotation_id = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The response of a call to `AnnotationService_DeleteAnnotation`. +message DeleteAnnotationResponse {} + +message BatchDeleteAnnotationsRequest { + repeated string annotation_ids = 1 [(google.api.field_behavior) = REQUIRED]; +} + +message BatchDeleteAnnotationsResponse {} + +// The request for a call to `AnnotationService_GetAnnotation`. +message GetAnnotationRequest { + string annotation_id = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The response of a call to `AnnotationService_GetAnnotation`. +message GetAnnotationResponse { + Annotation annotation = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The request for a call to `AnnotationService_ListAnnotations` to retrieve annotations. +message ListAnnotationsRequest { + // The maximum number of annotations to return. The service may return fewer than this value. + // If unspecified, at most 50 annotations will be returned. The maximum value is 1000; values above + // 1000 will be coerced to 1000. Optional. + uint32 page_size = 1 [(google.api.field_behavior) = OPTIONAL]; + + // A page token, received from a previous `ListAnnotations` call. + // Provide this to retrieve the subsequent page. + // When paginating, all other parameters provided to `ListAnnotations` must match + // the call that provided the page token. Optional. + string page_token = 2 [(google.api.field_behavior) = OPTIONAL]; + + // A [Common Expression Language (CEL)](https://github.com/google/cel-spec) filter string. + // Available fields to filter by are `annotation_id`, `start_time`, `end_time`, + // `created_date`, `modified_date`, `run_id`, `name`, `description`, `state`, `created_by_user_id`, `created_by_condition_id`, + // and `annotation_type`. + // For further information about how to use CELs, please refer to [this guide](https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions). + // For more information about the fields used for filtering, please refer to [this definition](/ingestion/api#sift_annotations_v1_annotations-proto). Optional. + string filter = 3 [(google.api.field_behavior) = OPTIONAL]; +} + +// The result of a call to `AnnotationService_ListAnnotations`. +message ListAnnotationsResponse { + repeated Annotation annotations = 1; + string next_page_token = 5; +} + +// The request for a call to `AnnotationService_UpdateAnnotation` to update an annotation. +message UpdateAnnotationRequest { + // The annotation to update. + Annotation annotation = 1 [(google.api.field_behavior) = REQUIRED]; + + // The list of fields to be updated. The fields available to be updated are `name`, `description`, `start_time`, + // `end_time`, `assigned_to_user_id`, `state`, and `tags`. + // + // Important Note: if `tags` is specified in the update mask and `annotation.tags` is an empty list then all associated tags on the annotation + // will be removed. + google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// The response of a call to `AnnotationService_UpdateAnnotation`. +message UpdateAnnotationResponse { + Annotation annotation = 1; +} diff --git a/protos/sift/assets/v1/assets.proto b/protos/sift/assets/v1/assets.proto new file mode 100644 index 00000000..b6266c7b --- /dev/null +++ b/protos/sift/assets/v1/assets.proto @@ -0,0 +1,82 @@ +syntax = "proto3"; + +package sift.assets.v1; + +import "google/api/annotations.proto"; +import "google/api/field_behavior.proto"; +import "google/protobuf/timestamp.proto"; +import "protoc-gen-openapiv2/options/annotations.proto"; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/assets/v1;assetsv1pb"; +option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { + info: {title: "Asset service"} +}; + +service AssetService { + rpc DeleteAsset(DeleteAssetRequest) returns (DeleteAssetResponse) { + option (google.api.http) = {delete: "/api/v1/assets/{asset_id}"}; + } + rpc GetAsset(GetAssetRequest) returns (GetAssetResponse) { + option (google.api.http) = {get: "/api/v1/assets/{asset_id}"}; + } + rpc ListAssets(ListAssetsRequest) returns (ListAssetsResponse) { + option (google.api.http) = {get: "/api/v1/assets"}; + } +} + +message Asset { + string asset_id = 1 [(google.api.field_behavior) = REQUIRED]; + string name = 2 [(google.api.field_behavior) = REQUIRED]; + string organization_id = 4 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp created_date = 5 [(google.api.field_behavior) = REQUIRED]; + string created_by_user_id = 6 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp modified_date = 7 [(google.api.field_behavior) = REQUIRED]; + string modified_by_user_id = 8 [(google.api.field_behavior) = REQUIRED]; +} + +// The request for a call to `AssetService_ListAssets` to retrieve asset(s). +message ListAssetsRequest { + // The maximum number of assets to return. + // The service may return fewer than this value. + // If unspecified, at most 50 assets will be returned. + // The maximum value is 1000; values above 1000 will be coerced to 1000. + uint32 page_size = 1 [(google.api.field_behavior) = OPTIONAL]; + + // A page token, received from a previous `ListAssets` call. + // Provide this to retrieve the subsequent page. + // When paginating, all other parameters provided to `ListAssets` must match + // the call that provided the page token. + string page_token = 2 [(google.api.field_behavior) = OPTIONAL]; + + // A [Common Expression Language (CEL)](https://github.com/google/cel-spec) filter string. + // Available fields to filter by are `asset_id`, `created_by_user_id`, `modified_by_user_id`, + // `created_date`, `modified_date`, and `name`. + // For further information about how to use CELs, please refer to [this guide](https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions). + // For more information about the fields used for filtering, please refer to [this definition](/ingestion/api#sift_assets_v1_assets-proto). Optional. + string filter = 3 [(google.api.field_behavior) = OPTIONAL]; +} + +// The result of a call to `AssetService_ListAssets`. +message ListAssetsResponse { + repeated Asset assets = 1; + string next_page_token = 5; +} + +// The request for a call to `AssetService_DeleteAsset` to delete a single existing annotation by its asset_id. +message DeleteAssetRequest { + // The id of the asset to be deleted. Required. + string asset_id = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The response of a call to `AssetService_DeleteAsset`. +message DeleteAssetResponse {} + +// The request for a call to `AssetService_GetAsset` to retrieve a single existing asset by its asset_id. +message GetAssetRequest { + // The id of the asset to be retrieved. Required. + string asset_id = 1 [(google.api.field_behavior) = REQUIRED]; +} + +message GetAssetResponse { + Asset asset = 1; +} diff --git a/protos/sift/common/type/v1/channel_data_type.proto b/protos/sift/common/type/v1/channel_data_type.proto new file mode 100644 index 00000000..7b7878ba --- /dev/null +++ b/protos/sift/common/type/v1/channel_data_type.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package sift.common.type.v1; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/common/type/v1;typev1pb"; + +enum ChannelDataType { + CHANNEL_DATA_TYPE_UNSPECIFIED = 0 [deprecated = true]; + CHANNEL_DATA_TYPE_DOUBLE = 1; + CHANNEL_DATA_TYPE_STRING = 2; + CHANNEL_DATA_TYPE_ENUM = 3; + CHANNEL_DATA_TYPE_BIT_FIELD = 4; + CHANNEL_DATA_TYPE_BOOL = 5; + CHANNEL_DATA_TYPE_FLOAT = 6; + CHANNEL_DATA_TYPE_INT_32 = 7; + CHANNEL_DATA_TYPE_UINT_32 = 8; + CHANNEL_DATA_TYPE_INT_64 = 9; + CHANNEL_DATA_TYPE_UINT_64 = 10; +} diff --git a/protos/sift/common/type/v1/organization.proto b/protos/sift/common/type/v1/organization.proto new file mode 100644 index 00000000..b23c05c0 --- /dev/null +++ b/protos/sift/common/type/v1/organization.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package sift.common.type.v1; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/common/type/v1;typev1pb"; + +message Organization { + string organization_id = 1; + string organization_name = 2; +} diff --git a/protos/sift/common/type/v1/user.proto b/protos/sift/common/type/v1/user.proto new file mode 100644 index 00000000..5e5340f1 --- /dev/null +++ b/protos/sift/common/type/v1/user.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +package sift.common.type.v1; + +import "google/api/field_behavior.proto"; +import "sift/common/type/v1/organization.proto"; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/common/type/v1;typev1pb"; + +message User { + string user_id = 1 [(google.api.field_behavior) = REQUIRED]; + string user_name = 2 [(google.api.field_behavior) = REQUIRED]; + repeated sift.common.type.v1.Organization organizations = 3; +} diff --git a/protos/sift/notifications/v1/notifications.proto b/protos/sift/notifications/v1/notifications.proto new file mode 100644 index 00000000..904d0311 --- /dev/null +++ b/protos/sift/notifications/v1/notifications.proto @@ -0,0 +1,98 @@ +syntax = "proto3"; + +package sift.notifications.v1; + +import "google/api/annotations.proto"; +import "google/api/field_behavior.proto"; +import "google/protobuf/field_mask.proto"; +import "google/protobuf/timestamp.proto"; +import "protoc-gen-openapiv2/options/annotations.proto"; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/notifications/v1;notificationsv1pb"; +option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { + info: {title: "Notification Service"} +}; + +service NotificationService { + rpc ListNotifications(ListNotificationsRequest) returns (ListNotificationsResponse) { + option (google.api.http) = {get: "/api/v1/notifications"}; + } + rpc BatchUpdateNotifications(BatchUpdateNotificationsRequest) returns (BatchUpdateNotificationsResponse) { + option (google.api.http) = { + post: "/api/v1/notifications:batchUpdate" + body: "*" + }; + } +} + +message Notification { + string notification_id = 1; + google.protobuf.Timestamp created_date = 2; + google.protobuf.Timestamp modified_date = 3; + string created_by_user_id = 4; + string modified_by_user_id = 5; + string organization_id = 6; + string recipient_user_id = 7; + bool is_read = 8; + string full_link = 9; + NotificationKind notification_type = 10; + string contents = 11; + string entity_id = 12; +} + +enum NotificationKind { + NOTIFICATION_KIND_UNSPECIFIED = 0; + NOTIFICATION_KIND_TEXT = 1; + NOTIFICATION_KIND_ANNOTATION_ASSIGNED = 2; + NOTIFICATION_KIND_MENTIONED_IN_ANNOTATION_COMMENT = 3; + NOTIFICATION_KIND_CONDITION_TRIGGERED = 4; +} + +// The request for a call to `NotificationService_ListNotifications` to retrieve notifications. +message ListNotificationsRequest { + // The maximum number of notifications to return. + // The service may return fewer than this value. + // If unspecified, at most 50 notifications will be returned. + // The maximum value is 1000; values above 1000 will be coerced to 1000. + uint32 page_size = 1 [(google.api.field_behavior) = OPTIONAL]; + + // A page token, received from a previous `ListNotifications` call. + // Provide this to retrieve the subsequent page. + // When paginating, all other parameters provided to `ListNotifications` must match + // the call that provided the page token. + string page_token = 2 [(google.api.field_behavior) = OPTIONAL]; + + // A [Common Expression Language (CEL)](https://github.com/google/cel-spec) filter string. + // Available fields to filter by are `notification_id`, `created_by_user_id`, `recipient_user_id`, + // `created_date`, `notification_type`, and `is_read`. + // For further information about how to use CELs, please refer to [this guide](https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions). + // For more information about the fields used for filtering, please refer to [this definition](/ingestion/api#sift_notifications_v1_notifications-proto). Optional. + string filter = 3 [(google.api.field_behavior) = OPTIONAL]; +} + +// The response of a call to `NotificationService_ListNotifications`. +message ListNotificationsResponse { + repeated Notification notifications = 1; + string next_page_token = 2; +} + +// The request for a call to `NotificationService_BatchUpdateNotifications` to update notifications. +// A maximum of 1000 notifications can be modified in a batch. +message BatchUpdateNotificationsRequest { + repeated UpdateNotificationRequest requests = 1 [(google.api.field_behavior) = REQUIRED]; +} + +message UpdateNotificationRequest { + // The notification to update. The notification's `notification_id` field is used to identify the notification to update + // and must be provided. + Notification notification = 1 [(google.api.field_behavior) = REQUIRED]; + + // The list of fields to be updated. Currently, the only field that can be updated is `is_read`. + google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// The response of a call to `NotificationService_BatchUpdateNotifications` containing the updated notifications. +message BatchUpdateNotificationsResponse { + // The updated notifications. + repeated Notification notifications = 1; +} diff --git a/protos/sift/runs/v2/runs.proto b/protos/sift/runs/v2/runs.proto new file mode 100644 index 00000000..48d5552e --- /dev/null +++ b/protos/sift/runs/v2/runs.proto @@ -0,0 +1,148 @@ +syntax = "proto3"; + +package sift.runs.v2; + +import "google/api/annotations.proto"; +import "google/api/field_behavior.proto"; +import "google/protobuf/field_mask.proto"; +import "google/protobuf/timestamp.proto"; +import "protoc-gen-openapiv2/options/annotations.proto"; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/runs/v2;runsv2pb"; +option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { + info: {title: "Run service"} +}; + +service RunService { + rpc GetRun(GetRunRequest) returns (GetRunResponse) { + option (google.api.http) = {get: "/api/v2/runs/{run_id}"}; + } + rpc ListRuns(ListRunsRequest) returns (ListRunsResponse) { + option (google.api.http) = {get: "/api/v2/runs"}; + } + rpc CreateRun(CreateRunRequest) returns (CreateRunResponse) { + option (google.api.http) = { + post: "/api/v2/runs" + body: "*" + }; + } + rpc UpdateRun(UpdateRunRequest) returns (UpdateRunResponse) { + option (google.api.http) = { + patch: "/api/v2/runs" + body: "*" + }; + } +} + +message Run { + string run_id = 1 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp created_date = 2 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp modified_date = 3 [(google.api.field_behavior) = REQUIRED]; + string created_by_user_id = 4 [(google.api.field_behavior) = REQUIRED]; + string modified_by_user_id = 5 [(google.api.field_behavior) = REQUIRED]; + string organization_id = 6 [(google.api.field_behavior) = REQUIRED]; + optional google.protobuf.Timestamp start_time = 7 [(google.api.field_behavior) = OPTIONAL]; + optional google.protobuf.Timestamp stop_time = 8 [(google.api.field_behavior) = OPTIONAL]; + bool is_pinned = 9 [(google.api.field_behavior) = REQUIRED]; + string name = 10 [(google.api.field_behavior) = REQUIRED]; + string description = 11 [(google.api.field_behavior) = REQUIRED]; + repeated string tags = 12 [(google.api.field_behavior) = REQUIRED]; +} + +// The request for a call to `RunService_GetRun` to retrieve run. +message GetRunRequest { + // The ID of the run to retrieve. + string run_id = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The response of a call to `RunService_GetRun` containing the requested run. +message GetRunResponse { + Run run = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The request for a call to `RunService_ListRuns` to retrieve runs. +message ListRunsRequest { + // The maximum number of runs to return. + // The service may return fewer than this value. + // If unspecified, at most 50 runs will be returned. + // The maximum value is 1000; values above 1000 will be coerced to 1000. + uint32 page_size = 1 [(google.api.field_behavior) = OPTIONAL]; + + // A page token, received from a previous `ListRuns` call. + // Provide this to retrieve the subsequent page. + // When paginating, all other parameters provided to `ListRuns` must match + // the call that provided the page token. + string page_token = 2 [(google.api.field_behavior) = OPTIONAL]; + + // A [Common Expression Language (CEL)](https://github.com/google/cel-spec) filter string. + // Available fields to filter by are `run_id`, `organization_id`, `name`, `description`, `created_by_user_id`, `modified_by_user_id`, + // `created_date`, `modified_date`, `start_time`, `stop_time`, `client_key`, and `is_pinned`. + // For further information about how to use CELs, please refer to [this guide](https://github.com/google/cel-spec/blob/master/doc/langdef.md#standard-definitions). + // For more information about the fields used for filtering, please refer to [this definition](/ingestion/api#run-proto). Optional. + string filter = 3 [(google.api.field_behavior) = OPTIONAL]; +} + +// The response of a call to `RunService_ListRuns` containing requested runs. +message ListRunsResponse { + repeated Run runs = 1 [(google.api.field_behavior) = REQUIRED]; + string next_page_token = 2; +} + +// The request of a call to `RunService_CreateRuns` to create a new run. +message CreateRunRequest { + // The name that will be assigned to the new run. + string name = 1 [(google.api.field_behavior) = REQUIRED]; + + // A description about the new run. + string description = 2 [(google.api.field_behavior) = REQUIRED]; + + // Tags to associate with the new run. + repeated string tags = 3 [(google.api.field_behavior) = OPTIONAL]; + + // The time at which data ingestion begins for this new run. It must be before the `stop_time`, and it must + // be provided if a `stop_time` is provided. + // Important note: `start_time` will be automatically computed during data ingestion and will be set + // based on the timestamp of the data for this run. + google.protobuf.Timestamp start_time = 4 [(google.api.field_behavior) = OPTIONAL]; + + // The time at which data ingestion for this new run concludes. + // + // Important note: `stop_time` will be automatically computed during data ingestion and will be + // set based on the timestamp of the data for this run. + google.protobuf.Timestamp stop_time = 5 [(google.api.field_behavior) = OPTIONAL]; + + // A list of asset names to associate with the new run. If any of the provided asset names are not associated + // with existing assets, then asset names that fall into said category will be used to create new assets. + // Any data that is received for these assets will automatically be associated with this newly created run. This applies + // even if the run has concluded, so long as the new data contains timestamps that are between the `start_time` and `stop_time`. + // Do note that if any of the assets are already associated with an ongoing run whose run period (the period between `start_time` and `end_time`) + // overlaps with the requested run period, an error will be returned. + repeated string asset_names = 6 [(google.api.field_behavior) = OPTIONAL]; + + // An organization ID is only required if the user belongs to multiple organizations. + string organization_id = 7 [(google.api.field_behavior) = OPTIONAL]; +} + +// The response of a call to `RunService_CreateRuns` containing the newly created run. +message CreateRunResponse { + Run run = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The request for a call to `RunService_UpdateRun` to update an existing run. +message UpdateRunRequest { + // The run to update. The run's `run_id` field is used to identify the run to update + // and is required. + Run run = 1 [(google.api.field_behavior) = REQUIRED]; + + // The list of fields to be updated. The fields available to be updated are `description`, + // `start_time`, `stop_time`, `is_pinned`, and `tags`. + // Important Note: When updating the `start_time`, please be aware that if a subsequent data ingestion + // commences for this run, the `start_time` will be automatically overwritten and set to the timestamp + // corresponding to the beginning of the latest run. + google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = REQUIRED]; +} + +// The response of a call to `RunService_UpdateRun` containing the updated run. +message UpdateRunResponse { + Run run = 1 [(google.api.field_behavior) = REQUIRED]; +} diff --git a/protos/sift/tags/v1/tags.proto b/protos/sift/tags/v1/tags.proto new file mode 100644 index 00000000..d1e82665 --- /dev/null +++ b/protos/sift/tags/v1/tags.proto @@ -0,0 +1,18 @@ +syntax = "proto3"; + +package sift.tags.v1; + +import "google/api/field_behavior.proto"; +import "google/protobuf/timestamp.proto"; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/tags/v1;tagsv1pb"; + +message Tag { + string tag_id = 1 [(google.api.field_behavior) = REQUIRED]; + string name = 2 [(google.api.field_behavior) = REQUIRED]; + string organization_id = 3 [(google.api.field_behavior) = REQUIRED]; + string created_by_user_id = 4 [(google.api.field_behavior) = REQUIRED]; + string modified_by_user_id = 5 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp created_date = 6 [(google.api.field_behavior) = REQUIRED]; + google.protobuf.Timestamp modified_date = 7 [(google.api.field_behavior) = REQUIRED]; +} diff --git a/protos/sift/users/v2/users.proto b/protos/sift/users/v2/users.proto new file mode 100644 index 00000000..6d95bbe7 --- /dev/null +++ b/protos/sift/users/v2/users.proto @@ -0,0 +1,43 @@ +syntax = "proto3"; + +package sift.users.v2; + +import "google/api/annotations.proto"; +import "google/api/field_behavior.proto"; +import "protoc-gen-openapiv2/options/annotations.proto"; +import "sift/common/type/v1/user.proto"; + +option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/users/v2;usersv2pb"; +option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { + info: {title: "User Service"} +}; + +service UserService { + rpc UpdateUserOrganizationActive(UpdateUserOrganizationActiveRequest) returns (UpdateUserOrganizationActiveResponse) { + option (google.api.http) = { + post: "/api/v2/users/{user_id}/active" + body: "*" + }; + } + rpc GetUser(GetUserRequest) returns (GetUserResponse) { + option (google.api.http) = {get: "/api/v2/users/{user_id}"}; + } +} + +message UpdateUserOrganizationActiveRequest { + string user_id = 1; + string organization_id = 2; + bool active = 3; +} + +message UpdateUserOrganizationActiveResponse {} + +// The request for a call to retrieve a single existing user by its user_id. +message GetUserRequest { + // The id of the asset to be retrieved. Required. + string user_id = 1 [(google.api.field_behavior) = REQUIRED]; +} + +message GetUserResponse { + sift.common.type.v1.User user = 1; +} diff --git a/sift_gen b/sift_gen new file mode 100755 index 00000000..584ad6d7 --- /dev/null +++ b/sift_gen @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -e + +err_and_exit() { + printf "$2\n" >&2 + exit $1 +} + +if [[ ! -f $(which buf) ]]; then + err_and_exit 2 "Could not find 'buf' executable. Ensure that it is installed in your path." +fi + + +script=$(realpath "$0") +script_path=$(dirname "$SCRIPT") +gen_dir="$script_path/gen" + +printf "Compiling protocol buffers...\n" +rm -rf "$gen_dir" +buf generate "$script_path/protos" --include-imports + +targets="" + +for target in $(ls $gen_dir); do + targets+="- $target\n" +done + +printf "Successfully generated code for the following targets:\n$targets" From ce3c2cc93e2152bfe27ebf73b8213531deaa792d Mon Sep 17 00:00:00 2001 From: solidiquis Date: Fri, 5 Apr 2024 09:38:01 -0700 Subject: [PATCH 2/6] fix yaml --- .github/workflows/buf.yaml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/buf.yaml b/.github/workflows/buf.yaml index fd486350..23151e93 100644 --- a/.github/workflows/buf.yaml +++ b/.github/workflows/buf.yaml @@ -1,10 +1,11 @@ -name: Sift Protos - +name: protos on: pull_request jobs: lint-protos: - - uses: actions/checkout@v2 - - uses: bufbuild/buf-setup-action@v1 - - uses: bufbuild/buf-lint-action@v1 - with: - input: protos + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: bufbuild/buf-setup-action@v1 + - uses: bufbuild/buf-lint-action@v1 + with: + input: proto From 4a2c350ea1c5de6473b89cdfbfec225f90ef6d12 Mon Sep 17 00:00:00 2001 From: solidiquis Date: Fri, 5 Apr 2024 09:38:46 -0700 Subject: [PATCH 3/6] typo --- .github/workflows/buf.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buf.yaml b/.github/workflows/buf.yaml index 23151e93..8cdee662 100644 --- a/.github/workflows/buf.yaml +++ b/.github/workflows/buf.yaml @@ -8,4 +8,4 @@ jobs: - uses: bufbuild/buf-setup-action@v1 - uses: bufbuild/buf-lint-action@v1 with: - input: proto + input: protos From ec8dd01bc7f3c1307975cfde759d0a86bd8c0c04 Mon Sep 17 00:00:00 2001 From: solidiquis Date: Fri, 5 Apr 2024 10:10:23 -0700 Subject: [PATCH 4/6] testing --- .githooks/pre-commit | 3 --- protos/sift/annotations/v1/annotations.proto | 1 - sift_gen | 8 ++------ 3 files changed, 2 insertions(+), 10 deletions(-) mode change 100644 => 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit old mode 100644 new mode 100755 index d662eb52..a46bdbbd --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -5,9 +5,6 @@ if [[ ! -f $(which buf) ]]; then exit 2 fi -# cd back to repo root -cd ../../ - changed_files=($(git diff --cached --name-only --diff-filter=ACM | grep '^protos/' | grep '**.proto$')) if [[ -n "$changed_files" ]]; then diff --git a/protos/sift/annotations/v1/annotations.proto b/protos/sift/annotations/v1/annotations.proto index a39fec88..2318e3b9 100644 --- a/protos/sift/annotations/v1/annotations.proto +++ b/protos/sift/annotations/v1/annotations.proto @@ -65,7 +65,6 @@ message Annotation { } enum AnnotationState { - ANNOTATION_STATE_UNSPECIFIED = 0; ANNOTATION_STATE_OPEN = 1; ANNOTATION_STATE_FLAGGED = 2; ANNOTATION_STATE_RESOLVED = 3; diff --git a/sift_gen b/sift_gen index 584ad6d7..b962b4a3 100755 --- a/sift_gen +++ b/sift_gen @@ -12,17 +12,13 @@ if [[ ! -f $(which buf) ]]; then fi -script=$(realpath "$0") -script_path=$(dirname "$SCRIPT") -gen_dir="$script_path/gen" - printf "Compiling protocol buffers...\n" -rm -rf "$gen_dir" +rm -rf gen buf generate "$script_path/protos" --include-imports targets="" -for target in $(ls $gen_dir); do +for target in $(ls gen); do targets+="- $target\n" done From 2c9add8ab5f5ce6dfc1dfc0ebd50e38b65faaf52 Mon Sep 17 00:00:00 2001 From: solidiquis Date: Fri, 5 Apr 2024 10:11:12 -0700 Subject: [PATCH 5/6] nice --- protos/sift/annotations/v1/annotations.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protos/sift/annotations/v1/annotations.proto b/protos/sift/annotations/v1/annotations.proto index 2318e3b9..bdcc7274 100644 --- a/protos/sift/annotations/v1/annotations.proto +++ b/protos/sift/annotations/v1/annotations.proto @@ -9,7 +9,6 @@ import "google/protobuf/timestamp.proto"; import "protoc-gen-openapiv2/options/annotations.proto"; option go_package = "github.com/sift-stack/protobufs/gen/protos/go/sift/annotations/v1;annotationsv1pb"; - option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { info: {title: "Annotation service"} }; @@ -65,6 +64,7 @@ message Annotation { } enum AnnotationState { + ANNOTATION_STATE_UNSPECIFIED = 0; ANNOTATION_STATE_OPEN = 1; ANNOTATION_STATE_FLAGGED = 2; ANNOTATION_STATE_RESOLVED = 3; From 86c891116774e709728d8e3897669c4ccd284b8a Mon Sep 17 00:00:00 2001 From: solidiquis Date: Sun, 7 Apr 2024 11:22:22 -0700 Subject: [PATCH 6/6] script update --- sift | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sift_gen | 25 ------------------------ 2 files changed, 59 insertions(+), 25 deletions(-) create mode 100755 sift delete mode 100755 sift_gen diff --git a/sift b/sift new file mode 100755 index 00000000..7f3438c7 --- /dev/null +++ b/sift @@ -0,0 +1,59 @@ +#!/usr/bin/env bash + +if [[ ! -f $(which buf) ]]; then + printf "Could not find 'buf' executable. Ensure that it is installed in your path.\n" >&2 + exit 1 +fi + +gen_desc="Compiles protos in the protos directory using plugins found in buf.gen.yaml" +gen() { + printf "Compiling protocol buffers...\n" + rm -rf gen + buf generate protos --include-imports + + targets="" + + for target in $(ls gen); do + targets+="- $target\n" + done + + printf "Successfully generated code for the following targets:\n$targets" +} + +lint_desc="Lints protos found in the protos directory" +lint() { + buf lint protos +} + +read -r -d '' sift_usage << EOT +Script containing Sift protobuf utilities. + +Usage: sift [options] [command] + +Available commands: + gen $gen_desc + lint $lint_desc + +Available options: + -h, --help Show help text. +EOT + +if [[ "${#@}" == "0" ]]; then + printf "$sift_usage\n" + exit 0 +fi + +case "$1" in + -h|--help) printf "$usage\n" + ;; + lint) lint + ;; + gen) gen + ;; + *) + printf "Unrecognized argument '$1'. Please refer to '--help' for a list of valid arguments.\n" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/sift_gen b/sift_gen deleted file mode 100755 index b962b4a3..00000000 --- a/sift_gen +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -set -e - -err_and_exit() { - printf "$2\n" >&2 - exit $1 -} - -if [[ ! -f $(which buf) ]]; then - err_and_exit 2 "Could not find 'buf' executable. Ensure that it is installed in your path." -fi - - -printf "Compiling protocol buffers...\n" -rm -rf gen -buf generate "$script_path/protos" --include-imports - -targets="" - -for target in $(ls gen); do - targets+="- $target\n" -done - -printf "Successfully generated code for the following targets:\n$targets"