From 8393daecaf0f6521b82a2e29c185deb3484cf04c Mon Sep 17 00:00:00 2001 From: Kush Sharma Date: Sat, 19 Aug 2023 13:43:50 +0530 Subject: [PATCH] feat(frontier): supporting preferences for different resource types - allow adding preferences(k/v) for org, project, user, group and platform Signed-off-by: Kush Sharma --- raystack/frontier/v1beta1/admin.proto | 35 +++++ raystack/frontier/v1beta1/frontier.proto | 169 +++++++++++++++++++++++ raystack/frontier/v1beta1/models.proto | 36 ++++- 3 files changed, 239 insertions(+), 1 deletion(-) diff --git a/raystack/frontier/v1beta1/admin.proto b/raystack/frontier/v1beta1/admin.proto index 171f03a2..76ed03ef 100644 --- a/raystack/frontier/v1beta1/admin.proto +++ b/raystack/frontier/v1beta1/admin.proto @@ -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 { @@ -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; +} \ No newline at end of file diff --git a/raystack/frontier/v1beta1/frontier.proto b/raystack/frontier/v1beta1/frontier.proto index 7a5c0028..7b962947 100644 --- a/raystack/frontier/v1beta1/frontier.proto +++ b/raystack/frontier/v1beta1/frontier.proto @@ -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 @@ -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 { @@ -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; +} \ No newline at end of file diff --git a/raystack/frontier/v1beta1/models.proto b/raystack/frontier/v1beta1/models.proto index 25147e7b..d44cce9d 100644 --- a/raystack/frontier/v1beta1/models.proto +++ b/raystack/frontier/v1beta1/models.proto @@ -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 { @@ -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; @@ -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; +} \ No newline at end of file