Skip to content

Commit

Permalink
feat(frontier): supporting preferences for different resource types
Browse files Browse the repository at this point in the history
- allow adding preferences(k/v) for org, project, user, group and platform

Signed-off-by: Kush Sharma <[email protected]>
  • Loading branch information
kushsharma committed Aug 19, 2023
1 parent 19d90af commit 8393dae
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 1 deletion.
35 changes: 35 additions & 0 deletions raystack/frontier/v1beta1/admin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,27 @@ service AdminService {
summary: "Delete platform permission";
};
}

// Preferences
rpc ListPreferences(ListPreferencesRequest) returns (ListPreferencesResponse) {
option (google.api.http) = {get: "/v1beta1/preferences"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "List platform preferences";
description: "Returns a list of all preferences configured on an instance in Frontier. e.g user, project, organization etc";
};
}
rpc CreatePreferences(CreatePreferencesRequest) returns (CreatePreferencesResponse) {
option (google.api.http) = {
post: "/v1beta1/preferences",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "Create platform preferences";
description: "Create new platform preferences. The platform preferences **name** must be unique within the platform and can contain only alphanumeric characters, dashes and underscores.";
};
}
}

message ListAllUsersRequest {
Expand Down Expand Up @@ -419,3 +440,17 @@ message DeletePermissionRequest {
}

message DeletePermissionResponse {}

message ListPreferencesRequest {}

message ListPreferencesResponse {
repeated Preference preferences = 1;
}

message CreatePreferencesRequest {
repeated PreferenceRequestBody preferences = 1;
}

message CreatePreferencesResponse {
repeated Preference preference = 1;
}
169 changes: 169 additions & 0 deletions raystack/frontier/v1beta1/frontier.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,98 @@ service FrontierService {
description: "Get an audit log by ID.";
};
}

// Preferences

// DescribePreferences list down all the supported preferences of entities
rpc DescribePreferences(DescribePreferencesRequest) returns (DescribePreferencesResponse) {
option (google.api.http) = {get: "/v1beta1/preferences/_describe"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "Describe preferences";
description: "Returns a list of all preferences supported by Frontier.";
};
}

rpc CreateOrganizationPreferences(CreateOrganizationPreferencesRequest) returns (CreateOrganizationPreferencesResponse) {
option (google.api.http) = {
post: "/v1beta1/organizations/{id}/preferences",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "Create organization preferences";
description: "Create a new organization preferences. The organization preferences **name** must be unique within the organization and can contain only alphanumeric characters, dashes and underscores.";
};
}
rpc ListOrganizationPreferences(ListOrganizationPreferencesRequest) returns (ListOrganizationPreferencesResponse) {
option (google.api.http) = {get: "/v1beta1/organizations/{id}/preferences"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "List organization preferences";
description: "List an organization preferences by ID.";
};
}

rpc CreateProjectPreferences(CreateProjectPreferencesRequest) returns (CreateProjectPreferencesResponse) {
option (google.api.http) = {
post: "/v1beta1/projects/{id}/preferences",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "Create project preferences";
description: "Create a new project preferences. The project preferences **name** must be unique within the project and can contain only alphanumeric characters, dashes and underscores.";
};
}
rpc ListProjectPreferences(ListProjectPreferencesRequest) returns (ListProjectPreferencesResponse) {
option (google.api.http) = {get: "/v1beta1/projects/{id}/preferences"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "List project preferences";
description: "List a project preferences by ID.";
};
}

rpc CreateGroupPreferences(CreateGroupPreferencesRequest) returns (CreateGroupPreferencesResponse) {
option (google.api.http) = {
post: "/v1beta1/groups/{id}/preferences",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "Create group preferences";
description: "Create a new group preferences. The group preferences **name** must be unique within the group and can contain only alphanumeric characters, dashes and underscores.";
};
}
rpc ListGroupPreferences(ListGroupPreferencesRequest) returns (ListGroupPreferencesResponse) {
option (google.api.http) = {get: "/v1beta1/groups/{id}/preferences"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "List group preferences";
description: "List a group preferences by ID.";
};
}

rpc CreateUserPreferences(CreateUserPreferencesRequest) returns (CreateUserPreferencesResponse) {
option (google.api.http) = {
post: "/v1beta1/users/{id}/preferences",
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "Create user preferences";
description: "Create a new user preferences. The user preferences **name** must be unique within the user and can contain only alphanumeric characters, dashes and underscores.";
};
}
rpc ListUserPreferences(ListUserPreferencesRequest) returns (ListUserPreferencesResponse) {
option (google.api.http) = {get: "/v1beta1/users/{id}/preferences"};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
tags: "Preference";
summary: "List user preferences";
description: "List a user preferences by ID.";
};
}
}

// Authentication
Expand Down Expand Up @@ -1748,6 +1840,7 @@ message CreateOrganizationInvitationRequest {
(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {description: "user_id is email id of user who are invited inside the organization. If user is not registered on the platform, it will be notified"}
];
repeated string group_ids = 3 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {description: "list of group ids to which user needs to be added as a member."}];
repeated string role_ids = 4 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {description: "list of role ids to which user needs to be added as a member. Roles are binded at organization level by default."}];
}

message CreateOrganizationInvitationResponse {
Expand Down Expand Up @@ -2371,3 +2464,79 @@ message GetOrganizationAuditLogRequest {
message GetOrganizationAuditLogResponse {
AuditLog log = 1;
}

// Preferences

message DescribePreferencesRequest {}

message DescribePreferencesResponse {
repeated PreferenceTrait preference_traits = 1;
}

message CreateOrganizationPreferencesRequest {
string id = 1 [(validate.rules).string.min_len = 3];
repeated PreferenceRequestBody bodies = 2 [(validate.rules).repeated.min_items = 1];
}

message CreateOrganizationPreferencesResponse {
repeated Preference preferences = 1;
}

message ListOrganizationPreferencesRequest {
string id = 1 [(validate.rules).string.min_len = 3];
}

message ListOrganizationPreferencesResponse {
repeated Preference preferences = 1;
}

message CreateProjectPreferencesRequest {
string id = 1 [(validate.rules).string.min_len = 3];
repeated PreferenceRequestBody bodies = 2 [(validate.rules).repeated.min_items = 1];
}

message CreateProjectPreferencesResponse {
repeated Preference preferences = 1;
}

message ListProjectPreferencesRequest {
string id = 1 [(validate.rules).string.min_len = 3];
}

message ListProjectPreferencesResponse {
repeated Preference preferences = 1;
}

message CreateGroupPreferencesRequest {
string id = 1 [(validate.rules).string.min_len = 3];
repeated PreferenceRequestBody bodies = 2 [(validate.rules).repeated.min_items = 1];
}

message CreateGroupPreferencesResponse {
repeated Preference preferences = 1;
}

message ListGroupPreferencesRequest {
string id = 1 [(validate.rules).string.min_len = 3];
}

message ListGroupPreferencesResponse {
repeated Preference preferences = 1;
}

message CreateUserPreferencesRequest {
string id = 1 [(validate.rules).string.min_len = 3];
repeated PreferenceRequestBody bodies = 2 [(validate.rules).repeated.min_items = 1];
}

message CreateUserPreferencesResponse {
repeated Preference preferences = 1;
}

message ListUserPreferencesRequest {
string id = 1 [(validate.rules).string.min_len = 3];
}

message ListUserPreferencesResponse {
repeated Preference preferences = 1;
}
36 changes: 35 additions & 1 deletion raystack/frontier/v1beta1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ message Invitation {
description: "The time when the invitation expires.",
example: "\"2023-06-07T05:39:56.961Z\""
}];
repeated string role_ids = 8 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
description: "The list of role ids to which the user is invited in an organization.",
example: "\"d9c4f4e2-9b9a-4c1a-8f1a-2b9b9b9b9b9b\""
}];
}

message ServiceUserKey {
Expand Down Expand Up @@ -456,7 +460,29 @@ message AuditLog {
}];
}

// model crud body
// PreferenceTrait is a trait that can be used to add preferences to a resource
// it explains what preferences are available for a resource
message PreferenceTrait {
string name = 1;
string title = 2;
string description = 3;
string resource_type = 4;
}

message Preference {
string id = 1;
string name = 2;
string value = 3;
string resource_id = 4;
string resource_type = 5;

google.protobuf.Timestamp created_at = 10 [(grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
description: "The time when the preference was created.",
example: "\"2023-06-07T05:39:56.961Z\""
}];
}

// Model crud body

message RoleRequestBody {
reserved 1, 4;
Expand All @@ -469,3 +495,11 @@ message RoleRequestBody {
google.protobuf.Struct metadata = 5;
string title = 6;
}

message PreferenceRequestBody {
string name = 2 [(validate.rules).string = {
min_len: 2,
pattern: "^[A-Za-z0-9-_]+$"
}];
string value = 3;
}

0 comments on commit 8393dae

Please sign in to comment.