Skip to content

Commit

Permalink
fix: change permissions proto package so it doesn't clash with message (
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-kugler authored Aug 18, 2023
1 parent ce843d6 commit 6c8ae5b
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 11 deletions.
4 changes: 2 additions & 2 deletions javascript-web/generate_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ mkdir $out
# So we do a terrible hack to comment out the package declaration before generating the JS types,
# but add them back before generating the GRPC web bindings

proto_file_list=" permissions.proto extensions.proto cacheclient.proto controlclient.proto auth.proto cacheping.proto cachepubsub.proto vectorindex.proto token.proto "
proto_file_list=" permissionmessages.proto extensions.proto cacheclient.proto controlclient.proto auth.proto cacheping.proto cachepubsub.proto vectorindex.proto token.proto "

echo "Backing up protos dir"
cp -r ../proto ../proto.bak
Expand All @@ -74,7 +74,7 @@ echo "Commenting out package declarations"
for f in $proto_file_list
do
$sed_command 's/^\s*package \(.*\)/\/\/package \1/g' ../proto/${f}
$sed_command 's/permissions.Permissions/Permissions/g' ../proto/${f}
$sed_command 's/permission_messages.Permissions/Permissions/g' ../proto/${f}
done

protoc -I=../proto -I=/usr/local/include \
Expand Down
2 changes: 1 addition & 1 deletion javascript/generate_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set -e
set -x

PATH=node_modules/protoc-gen-ts/bin/:$PATH protoc -I=../proto -I=/usr/local/include --ts_out=src permissions.proto cacheclient.proto controlclient.proto cachepubsub.proto auth.proto cacheping.proto vectorindex.proto token.proto
PATH=node_modules/protoc-gen-ts/bin/:$PATH protoc -I=../proto -I=/usr/local/include --ts_out=src permissionmessages.proto cacheclient.proto controlclient.proto cachepubsub.proto auth.proto cacheping.proto vectorindex.proto token.proto
Binary file not shown.
4 changes: 2 additions & 2 deletions proto/auth.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

import "permissions.proto";
import "permissionmessages.proto";

option go_package = "github.com/momentohq/client-sdk-go;client_sdk_go";
option java_multiple_files = true;
Expand Down Expand Up @@ -73,7 +73,7 @@ message _GenerateApiTokenRequest {

string auth_token = 3;

permissions.Permissions permissions = 4;
permission_messages.Permissions permissions = 4;
}

message _GenerateApiTokenResponse {
Expand Down
97 changes: 97 additions & 0 deletions proto/permissionmessages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
syntax = "proto3";

option go_package = "github.com/momentohq/client-sdk-go;client_sdk_go";
option java_multiple_files = true;
option java_package = "grpc.permission_messages";

package permission_messages;

// Aliases for categories of functionality.
enum CacheRole {
CachePermitNone = 0;
// Restricts access to apis that read and write data from caches: No higher level resource description or modification.
CacheReadWrite = 1;
// Restricts access to apis that read from caches: No higher level resource description or modification.
CacheReadOnly = 2;
// Restricts access to apis that write from caches: No higher level resource description or modification.
// Doesn't allow conditional write APIs (SetIfNotExists, IncreaseTTL etc)
CacheWriteOnly = 3;
}

// Aliases for categories of functionality.
enum TopicRole {
TopicPermitNone = 0;
// Restricts access to apis that read and write data from topics: No higher level resource description or modification.
TopicReadWrite = 1;
// Restricts access to apis that read from topics: No higher level resource description or modification.
TopicReadOnly = 2;
// Restricts access to apis that write from topics: No higher level resource description or modification.
TopicWriteOnly = 3;
}

enum SuperUserPermissions {
SuperUser = 0;
}

message Permissions {
oneof kind {
SuperUserPermissions super_user = 1;
ExplicitPermissions explicit = 2;
}
}

message ExplicitPermissions {
repeated PermissionsType permissions = 1;
}

message PermissionsType {
oneof kind {
CachePermissions cache_permissions = 1;
TopicPermissions topic_permissions = 2;
}

message All {}

message CacheSelector {
oneof kind {
string cache_name = 1;
}
}

message CacheItemSelector {
oneof kind {
bytes key = 1;
bytes key_prefix = 2;
}
}

message CachePermissions {
CacheRole role = 1;
oneof cache {
All all_caches = 2;
CacheSelector cache_selector = 3;
}
oneof cache_item {
All all_items = 4;
CacheItemSelector item_selector = 5;
}
}

message TopicSelector {
oneof kind {
string topic_name = 1;
}
}

message TopicPermissions {
TopicRole role = 1;
oneof cache {
All all_caches = 2;
CacheSelector cache_selector = 3;
}
oneof topic {
All all_topics = 4;
TopicSelector topic_selector = 5;
}
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions proto/token.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

import "permissions.proto";
import "permissionmessages.proto";

option go_package = "github.com/momentohq/client-sdk-go;client_sdk_go";
option java_multiple_files = true;
Expand All @@ -23,7 +23,7 @@ message _GenerateAuthAcornRequest {

string auth_token = 2;

permissions.Permissions permissions = 3;
permission_messages.Permissions permissions = 3;
}

message _GenerateAuthAcornResponse {
Expand Down
2 changes: 1 addition & 1 deletion python/run-protoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ do
if [[ $python_protobuf_version == "protobuf>4" ]]; then
pyi_out="--pyi_out=$src_path"
fi
poetry run python -m grpc_tools.protoc -I../proto --python_out=$src_path $pyi_out --grpc_python_out=$src_path permissions.proto extensions.proto cacheclient.proto controlclient.proto auth.proto cachepubsub.proto vectorindex.proto token.proto
poetry run python -m grpc_tools.protoc -I../proto --python_out=$src_path $pyi_out --grpc_python_out=$src_path permissionmessages.proto extensions.proto cacheclient.proto controlclient.proto auth.proto cachepubsub.proto vectorindex.proto token.proto

# A shortcoming of the generated code is in the grpc generated code,
# the protobuf imports are absolute instead of relative.
Expand Down
4 changes: 2 additions & 2 deletions rust/momento-protos/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod permissions {
include!("permissions.rs");
pub mod permission_messages {
include!("permission_messages.rs");
}

pub mod auth {
Expand Down
2 changes: 1 addition & 1 deletion rust/proto_generator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {
.out_dir(out_dir)
.compile(
&[
format!("{proto_dir}/permissions.proto"),
format!("{proto_dir}/permissionmessages.proto"),
format!("{proto_dir}/auth.proto"),
format!("{proto_dir}/token.proto"),
format!("{proto_dir}/cacheclient.proto"),
Expand Down

0 comments on commit 6c8ae5b

Please sign in to comment.