diff --git a/app/cli/cmd/organization.go b/app/cli/cmd/organization.go index 5ec04e51c..c13f2b580 100644 --- a/app/cli/cmd/organization.go +++ b/app/cli/cmd/organization.go @@ -28,6 +28,7 @@ func newOrganizationCmd() *cobra.Command { cmd.AddCommand( newOrganizationList(), + newOrganizationCreateCmd(), newOrganizationUpdateCmd(), newOrganizationSet(), newOrganizationDescribeCmd(), diff --git a/app/cli/cmd/organization_create.go b/app/cli/cmd/organization_create.go new file mode 100644 index 000000000..eb97b0849 --- /dev/null +++ b/app/cli/cmd/organization_create.go @@ -0,0 +1,47 @@ +// +// Copyright 2023 The Chainloop Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "context" + + "github.com/chainloop-dev/chainloop/app/cli/internal/action" + "github.com/spf13/cobra" +) + +func newOrganizationCreateCmd() *cobra.Command { + var name string + + cmd := &cobra.Command{ + Use: "create", + Short: "Create an organization", + RunE: func(cmd *cobra.Command, args []string) error { + org, err := action.NewOrgCreate(actionOpts).Run(context.Background(), name) + if err != nil { + return err + } + + logger.Info().Msgf("Organization %q created!", org.Name) + return nil + }, + } + + cmd.Flags().StringVar(&name, "name", "", "organization name") + err := cmd.MarkFlagRequired("name") + cobra.CheckErr(err) + + return cmd +} diff --git a/app/cli/cmd/organization_update.go b/app/cli/cmd/organization_update.go index b40b7c1c7..c3e92c33f 100644 --- a/app/cli/cmd/organization_update.go +++ b/app/cli/cmd/organization_update.go @@ -48,6 +48,6 @@ func newOrganizationUpdateCmd() *cobra.Command { err := cmd.MarkFlagRequired("id") cobra.CheckErr(err) - cmd.Flags().StringVar(&name, "name", "", "workflow name") + cmd.Flags().StringVar(&name, "name", "", "organization name") return cmd } diff --git a/app/cli/internal/action/org_create.go b/app/cli/internal/action/org_create.go new file mode 100644 index 000000000..95574479b --- /dev/null +++ b/app/cli/internal/action/org_create.go @@ -0,0 +1,40 @@ +// +// Copyright 2023 The Chainloop Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package action + +import ( + "context" + + pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1" +) + +type OrgCreate struct { + cfg *ActionsOpts +} + +func NewOrgCreate(cfg *ActionsOpts) *OrgCreate { + return &OrgCreate{cfg} +} + +func (action *OrgCreate) Run(ctx context.Context, name string) (*OrgItem, error) { + client := pb.NewOrganizationServiceClient(action.cfg.CPConnection) + resp, err := client.Create(ctx, &pb.OrganizationServiceCreateRequest{Name: name}) + if err != nil { + return nil, err + } + + return pbOrgItemToAction(resp.Result), nil +} diff --git a/app/controlplane/api/controlplane/v1/organization.pb.go b/app/controlplane/api/controlplane/v1/organization.pb.go index 0aeabd7ad..8379194fb 100644 --- a/app/controlplane/api/controlplane/v1/organization.pb.go +++ b/app/controlplane/api/controlplane/v1/organization.pb.go @@ -121,6 +121,100 @@ func (x *OrganizationServiceListMembershipsResponse) GetResult() []*OrgMembershi return nil } +type OrganizationServiceCreateRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *OrganizationServiceCreateRequest) Reset() { + *x = OrganizationServiceCreateRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_controlplane_v1_organization_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrganizationServiceCreateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrganizationServiceCreateRequest) ProtoMessage() {} + +func (x *OrganizationServiceCreateRequest) ProtoReflect() protoreflect.Message { + mi := &file_controlplane_v1_organization_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrganizationServiceCreateRequest.ProtoReflect.Descriptor instead. +func (*OrganizationServiceCreateRequest) Descriptor() ([]byte, []int) { + return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{2} +} + +func (x *OrganizationServiceCreateRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type OrganizationServiceCreateResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Result *OrgItem `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` +} + +func (x *OrganizationServiceCreateResponse) Reset() { + *x = OrganizationServiceCreateResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_controlplane_v1_organization_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrganizationServiceCreateResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrganizationServiceCreateResponse) ProtoMessage() {} + +func (x *OrganizationServiceCreateResponse) ProtoReflect() protoreflect.Message { + mi := &file_controlplane_v1_organization_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OrganizationServiceCreateResponse.ProtoReflect.Descriptor instead. +func (*OrganizationServiceCreateResponse) Descriptor() ([]byte, []int) { + return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{3} +} + +func (x *OrganizationServiceCreateResponse) GetResult() *OrgItem { + if x != nil { + return x.Result + } + return nil +} + type OrganizationServiceUpdateRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -135,7 +229,7 @@ type OrganizationServiceUpdateRequest struct { func (x *OrganizationServiceUpdateRequest) Reset() { *x = OrganizationServiceUpdateRequest{} if protoimpl.UnsafeEnabled { - mi := &file_controlplane_v1_organization_proto_msgTypes[2] + mi := &file_controlplane_v1_organization_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -148,7 +242,7 @@ func (x *OrganizationServiceUpdateRequest) String() string { func (*OrganizationServiceUpdateRequest) ProtoMessage() {} func (x *OrganizationServiceUpdateRequest) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_organization_proto_msgTypes[2] + mi := &file_controlplane_v1_organization_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -161,7 +255,7 @@ func (x *OrganizationServiceUpdateRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use OrganizationServiceUpdateRequest.ProtoReflect.Descriptor instead. func (*OrganizationServiceUpdateRequest) Descriptor() ([]byte, []int) { - return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{2} + return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{4} } func (x *OrganizationServiceUpdateRequest) GetId() string { @@ -189,7 +283,7 @@ type OrganizationServiceUpdateResponse struct { func (x *OrganizationServiceUpdateResponse) Reset() { *x = OrganizationServiceUpdateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_controlplane_v1_organization_proto_msgTypes[3] + mi := &file_controlplane_v1_organization_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -202,7 +296,7 @@ func (x *OrganizationServiceUpdateResponse) String() string { func (*OrganizationServiceUpdateResponse) ProtoMessage() {} func (x *OrganizationServiceUpdateResponse) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_organization_proto_msgTypes[3] + mi := &file_controlplane_v1_organization_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -215,7 +309,7 @@ func (x *OrganizationServiceUpdateResponse) ProtoReflect() protoreflect.Message // Deprecated: Use OrganizationServiceUpdateResponse.ProtoReflect.Descriptor instead. func (*OrganizationServiceUpdateResponse) Descriptor() ([]byte, []int) { - return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{3} + return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{5} } func (x *OrganizationServiceUpdateResponse) GetResult() *OrgItem { @@ -236,7 +330,7 @@ type SetCurrentMembershipRequest struct { func (x *SetCurrentMembershipRequest) Reset() { *x = SetCurrentMembershipRequest{} if protoimpl.UnsafeEnabled { - mi := &file_controlplane_v1_organization_proto_msgTypes[4] + mi := &file_controlplane_v1_organization_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -249,7 +343,7 @@ func (x *SetCurrentMembershipRequest) String() string { func (*SetCurrentMembershipRequest) ProtoMessage() {} func (x *SetCurrentMembershipRequest) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_organization_proto_msgTypes[4] + mi := &file_controlplane_v1_organization_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -262,7 +356,7 @@ func (x *SetCurrentMembershipRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use SetCurrentMembershipRequest.ProtoReflect.Descriptor instead. func (*SetCurrentMembershipRequest) Descriptor() ([]byte, []int) { - return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{4} + return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{6} } func (x *SetCurrentMembershipRequest) GetMembershipId() string { @@ -283,7 +377,7 @@ type SetCurrentMembershipResponse struct { func (x *SetCurrentMembershipResponse) Reset() { *x = SetCurrentMembershipResponse{} if protoimpl.UnsafeEnabled { - mi := &file_controlplane_v1_organization_proto_msgTypes[5] + mi := &file_controlplane_v1_organization_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -296,7 +390,7 @@ func (x *SetCurrentMembershipResponse) String() string { func (*SetCurrentMembershipResponse) ProtoMessage() {} func (x *SetCurrentMembershipResponse) ProtoReflect() protoreflect.Message { - mi := &file_controlplane_v1_organization_proto_msgTypes[5] + mi := &file_controlplane_v1_organization_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -309,7 +403,7 @@ func (x *SetCurrentMembershipResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use SetCurrentMembershipResponse.ProtoReflect.Descriptor instead. func (*SetCurrentMembershipResponse) Descriptor() ([]byte, []int) { - return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{5} + return file_controlplane_v1_organization_proto_rawDescGZIP(), []int{7} } func (x *SetCurrentMembershipResponse) GetResult() *OrgMembershipItem { @@ -338,59 +432,76 @@ var file_controlplane_v1_organization_proto_rawDesc = []byte{ 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, - 0x69, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x5e, + 0x69, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x3f, 0x0a, 0x20, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x18, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x08, - 0xfa, 0x42, 0x05, 0x72, 0x03, 0xb0, 0x01, 0x01, 0x52, 0x02, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x88, 0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x55, - 0x0a, 0x21, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, - 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x06, 0x72, - 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x4c, 0x0a, 0x1b, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, - 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x2d, 0x0a, 0x0d, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, - 0x69, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x08, 0xfa, 0x42, 0x05, - 0x72, 0x03, 0xb0, 0x01, 0x01, 0x52, 0x0c, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, - 0x70, 0x49, 0x64, 0x22, 0x5a, 0x0a, 0x1c, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, - 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, - 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, - 0x68, 0x69, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, - 0x88, 0x03, 0x0a, 0x13, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x8a, 0x01, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, - 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x73, 0x12, 0x3a, 0x2e, 0x63, 0x6f, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x42, 0x07, 0xfa, 0x42, 0x04, 0x72, 0x02, 0x10, 0x01, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, + 0x55, 0x0a, 0x21, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, + 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x06, + 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x5e, 0x0a, 0x20, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, + 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x02, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x72, 0x03, 0xb0, 0x01, 0x01, + 0x52, 0x02, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x88, 0x01, 0x01, 0x42, 0x07, 0x0a, + 0x05, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x55, 0x0a, 0x21, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, + 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x30, 0x0a, 0x06, 0x72, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, + 0x67, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x4c, 0x0a, + 0x1b, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, + 0x72, 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2d, 0x0a, 0x0d, + 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x72, 0x03, 0xb0, 0x01, 0x01, 0x52, 0x0c, 0x6d, + 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x49, 0x64, 0x22, 0x5a, 0x0a, 0x1c, 0x53, + 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, + 0x68, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x06, 0x72, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x22, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, - 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x3b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, + 0x67, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x49, 0x74, 0x65, 0x6d, 0x52, + 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0xf9, 0x03, 0x0a, 0x13, 0x4f, 0x72, 0x67, 0x61, + 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x8a, 0x01, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, + 0x69, 0x70, 0x73, 0x12, 0x3a, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, + 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x65, 0x6d, + 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x3b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, + 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x4c, 0x69, 0x73, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, + 0x68, 0x69, 0x70, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6f, 0x0a, 0x06, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x12, 0x31, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x32, 0x2e, 0x63, 0x6f, 0x6e, 0x74, + 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x61, + 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6f, 0x0a, + 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x31, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, - 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x4c, 0x69, 0x73, - 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x73, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6f, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x31, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, - 0x2e, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, - 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x32, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, - 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x73, 0x0a, 0x14, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, - 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x12, 0x2c, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, - 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, - 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, - 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, - 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x4c, 0x5a, 0x4a, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, 0x6f, - 0x6f, 0x70, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, 0x6f, 0x6f, 0x70, - 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, - 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, - 0x6e, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x32, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x72, 0x67, + 0x61, 0x6e, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x73, + 0x0a, 0x14, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x6d, 0x62, + 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x12, 0x2c, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, + 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, + 0x61, 0x6e, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, + 0x74, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x42, 0x4c, 0x5a, 0x4a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, 0x6f, 0x6f, 0x70, 0x2d, 0x64, 0x65, 0x76, 0x2f, + 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, 0x6f, 0x6f, 0x70, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, 0x65, 0x2f, 0x76, 0x31, 0x3b, 0x76, + 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -405,32 +516,37 @@ func file_controlplane_v1_organization_proto_rawDescGZIP() []byte { return file_controlplane_v1_organization_proto_rawDescData } -var file_controlplane_v1_organization_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_controlplane_v1_organization_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_controlplane_v1_organization_proto_goTypes = []interface{}{ (*OrganizationServiceListMembershipsRequest)(nil), // 0: controlplane.v1.OrganizationServiceListMembershipsRequest (*OrganizationServiceListMembershipsResponse)(nil), // 1: controlplane.v1.OrganizationServiceListMembershipsResponse - (*OrganizationServiceUpdateRequest)(nil), // 2: controlplane.v1.OrganizationServiceUpdateRequest - (*OrganizationServiceUpdateResponse)(nil), // 3: controlplane.v1.OrganizationServiceUpdateResponse - (*SetCurrentMembershipRequest)(nil), // 4: controlplane.v1.SetCurrentMembershipRequest - (*SetCurrentMembershipResponse)(nil), // 5: controlplane.v1.SetCurrentMembershipResponse - (*OrgMembershipItem)(nil), // 6: controlplane.v1.OrgMembershipItem - (*OrgItem)(nil), // 7: controlplane.v1.OrgItem + (*OrganizationServiceCreateRequest)(nil), // 2: controlplane.v1.OrganizationServiceCreateRequest + (*OrganizationServiceCreateResponse)(nil), // 3: controlplane.v1.OrganizationServiceCreateResponse + (*OrganizationServiceUpdateRequest)(nil), // 4: controlplane.v1.OrganizationServiceUpdateRequest + (*OrganizationServiceUpdateResponse)(nil), // 5: controlplane.v1.OrganizationServiceUpdateResponse + (*SetCurrentMembershipRequest)(nil), // 6: controlplane.v1.SetCurrentMembershipRequest + (*SetCurrentMembershipResponse)(nil), // 7: controlplane.v1.SetCurrentMembershipResponse + (*OrgMembershipItem)(nil), // 8: controlplane.v1.OrgMembershipItem + (*OrgItem)(nil), // 9: controlplane.v1.OrgItem } var file_controlplane_v1_organization_proto_depIdxs = []int32{ - 6, // 0: controlplane.v1.OrganizationServiceListMembershipsResponse.result:type_name -> controlplane.v1.OrgMembershipItem - 7, // 1: controlplane.v1.OrganizationServiceUpdateResponse.result:type_name -> controlplane.v1.OrgItem - 6, // 2: controlplane.v1.SetCurrentMembershipResponse.result:type_name -> controlplane.v1.OrgMembershipItem - 0, // 3: controlplane.v1.OrganizationService.ListMemberships:input_type -> controlplane.v1.OrganizationServiceListMembershipsRequest - 2, // 4: controlplane.v1.OrganizationService.Update:input_type -> controlplane.v1.OrganizationServiceUpdateRequest - 4, // 5: controlplane.v1.OrganizationService.SetCurrentMembership:input_type -> controlplane.v1.SetCurrentMembershipRequest - 1, // 6: controlplane.v1.OrganizationService.ListMemberships:output_type -> controlplane.v1.OrganizationServiceListMembershipsResponse - 3, // 7: controlplane.v1.OrganizationService.Update:output_type -> controlplane.v1.OrganizationServiceUpdateResponse - 5, // 8: controlplane.v1.OrganizationService.SetCurrentMembership:output_type -> controlplane.v1.SetCurrentMembershipResponse - 6, // [6:9] is the sub-list for method output_type - 3, // [3:6] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 8, // 0: controlplane.v1.OrganizationServiceListMembershipsResponse.result:type_name -> controlplane.v1.OrgMembershipItem + 9, // 1: controlplane.v1.OrganizationServiceCreateResponse.result:type_name -> controlplane.v1.OrgItem + 9, // 2: controlplane.v1.OrganizationServiceUpdateResponse.result:type_name -> controlplane.v1.OrgItem + 8, // 3: controlplane.v1.SetCurrentMembershipResponse.result:type_name -> controlplane.v1.OrgMembershipItem + 0, // 4: controlplane.v1.OrganizationService.ListMemberships:input_type -> controlplane.v1.OrganizationServiceListMembershipsRequest + 2, // 5: controlplane.v1.OrganizationService.Create:input_type -> controlplane.v1.OrganizationServiceCreateRequest + 4, // 6: controlplane.v1.OrganizationService.Update:input_type -> controlplane.v1.OrganizationServiceUpdateRequest + 6, // 7: controlplane.v1.OrganizationService.SetCurrentMembership:input_type -> controlplane.v1.SetCurrentMembershipRequest + 1, // 8: controlplane.v1.OrganizationService.ListMemberships:output_type -> controlplane.v1.OrganizationServiceListMembershipsResponse + 3, // 9: controlplane.v1.OrganizationService.Create:output_type -> controlplane.v1.OrganizationServiceCreateResponse + 5, // 10: controlplane.v1.OrganizationService.Update:output_type -> controlplane.v1.OrganizationServiceUpdateResponse + 7, // 11: controlplane.v1.OrganizationService.SetCurrentMembership:output_type -> controlplane.v1.SetCurrentMembershipResponse + 8, // [8:12] is the sub-list for method output_type + 4, // [4:8] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_controlplane_v1_organization_proto_init() } @@ -465,7 +581,7 @@ func file_controlplane_v1_organization_proto_init() { } } file_controlplane_v1_organization_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*OrganizationServiceUpdateRequest); i { + switch v := v.(*OrganizationServiceCreateRequest); i { case 0: return &v.state case 1: @@ -477,7 +593,7 @@ func file_controlplane_v1_organization_proto_init() { } } file_controlplane_v1_organization_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*OrganizationServiceUpdateResponse); i { + switch v := v.(*OrganizationServiceCreateResponse); i { case 0: return &v.state case 1: @@ -489,7 +605,7 @@ func file_controlplane_v1_organization_proto_init() { } } file_controlplane_v1_organization_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SetCurrentMembershipRequest); i { + switch v := v.(*OrganizationServiceUpdateRequest); i { case 0: return &v.state case 1: @@ -501,6 +617,30 @@ func file_controlplane_v1_organization_proto_init() { } } file_controlplane_v1_organization_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OrganizationServiceUpdateResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_controlplane_v1_organization_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SetCurrentMembershipRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_controlplane_v1_organization_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SetCurrentMembershipResponse); i { case 0: return &v.state @@ -513,14 +653,14 @@ func file_controlplane_v1_organization_proto_init() { } } } - file_controlplane_v1_organization_proto_msgTypes[2].OneofWrappers = []interface{}{} + file_controlplane_v1_organization_proto_msgTypes[4].OneofWrappers = []interface{}{} type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_controlplane_v1_organization_proto_rawDesc, NumEnums: 0, - NumMessages: 6, + NumMessages: 8, NumExtensions: 0, NumServices: 1, }, diff --git a/app/controlplane/api/controlplane/v1/organization.pb.validate.go b/app/controlplane/api/controlplane/v1/organization.pb.validate.go index c95d38169..c7f75a215 100644 --- a/app/controlplane/api/controlplane/v1/organization.pb.validate.go +++ b/app/controlplane/api/controlplane/v1/organization.pb.validate.go @@ -284,6 +284,256 @@ var _ interface { ErrorName() string } = OrganizationServiceListMembershipsResponseValidationError{} +// Validate checks the field values on OrganizationServiceCreateRequest with +// the rules defined in the proto definition for this message. If any rules +// are violated, the first error encountered is returned, or nil if there are +// no violations. +func (m *OrganizationServiceCreateRequest) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on OrganizationServiceCreateRequest with +// the rules defined in the proto definition for this message. If any rules +// are violated, the result is a list of violation errors wrapped in +// OrganizationServiceCreateRequestMultiError, or nil if none found. +func (m *OrganizationServiceCreateRequest) ValidateAll() error { + return m.validate(true) +} + +func (m *OrganizationServiceCreateRequest) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if utf8.RuneCountInString(m.GetName()) < 1 { + err := OrganizationServiceCreateRequestValidationError{ + field: "Name", + reason: "value length must be at least 1 runes", + } + if !all { + return err + } + errors = append(errors, err) + } + + if len(errors) > 0 { + return OrganizationServiceCreateRequestMultiError(errors) + } + + return nil +} + +// OrganizationServiceCreateRequestMultiError is an error wrapping multiple +// validation errors returned by +// OrganizationServiceCreateRequest.ValidateAll() if the designated +// constraints aren't met. +type OrganizationServiceCreateRequestMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m OrganizationServiceCreateRequestMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m OrganizationServiceCreateRequestMultiError) AllErrors() []error { return m } + +// OrganizationServiceCreateRequestValidationError is the validation error +// returned by OrganizationServiceCreateRequest.Validate if the designated +// constraints aren't met. +type OrganizationServiceCreateRequestValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e OrganizationServiceCreateRequestValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e OrganizationServiceCreateRequestValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e OrganizationServiceCreateRequestValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e OrganizationServiceCreateRequestValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e OrganizationServiceCreateRequestValidationError) ErrorName() string { + return "OrganizationServiceCreateRequestValidationError" +} + +// Error satisfies the builtin error interface +func (e OrganizationServiceCreateRequestValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sOrganizationServiceCreateRequest.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = OrganizationServiceCreateRequestValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = OrganizationServiceCreateRequestValidationError{} + +// Validate checks the field values on OrganizationServiceCreateResponse with +// the rules defined in the proto definition for this message. If any rules +// are violated, the first error encountered is returned, or nil if there are +// no violations. +func (m *OrganizationServiceCreateResponse) Validate() error { + return m.validate(false) +} + +// ValidateAll checks the field values on OrganizationServiceCreateResponse +// with the rules defined in the proto definition for this message. If any +// rules are violated, the result is a list of violation errors wrapped in +// OrganizationServiceCreateResponseMultiError, or nil if none found. +func (m *OrganizationServiceCreateResponse) ValidateAll() error { + return m.validate(true) +} + +func (m *OrganizationServiceCreateResponse) validate(all bool) error { + if m == nil { + return nil + } + + var errors []error + + if all { + switch v := interface{}(m.GetResult()).(type) { + case interface{ ValidateAll() error }: + if err := v.ValidateAll(); err != nil { + errors = append(errors, OrganizationServiceCreateResponseValidationError{ + field: "Result", + reason: "embedded message failed validation", + cause: err, + }) + } + case interface{ Validate() error }: + if err := v.Validate(); err != nil { + errors = append(errors, OrganizationServiceCreateResponseValidationError{ + field: "Result", + reason: "embedded message failed validation", + cause: err, + }) + } + } + } else if v, ok := interface{}(m.GetResult()).(interface{ Validate() error }); ok { + if err := v.Validate(); err != nil { + return OrganizationServiceCreateResponseValidationError{ + field: "Result", + reason: "embedded message failed validation", + cause: err, + } + } + } + + if len(errors) > 0 { + return OrganizationServiceCreateResponseMultiError(errors) + } + + return nil +} + +// OrganizationServiceCreateResponseMultiError is an error wrapping multiple +// validation errors returned by +// OrganizationServiceCreateResponse.ValidateAll() if the designated +// constraints aren't met. +type OrganizationServiceCreateResponseMultiError []error + +// Error returns a concatenation of all the error messages it wraps. +func (m OrganizationServiceCreateResponseMultiError) Error() string { + var msgs []string + for _, err := range m { + msgs = append(msgs, err.Error()) + } + return strings.Join(msgs, "; ") +} + +// AllErrors returns a list of validation violation errors. +func (m OrganizationServiceCreateResponseMultiError) AllErrors() []error { return m } + +// OrganizationServiceCreateResponseValidationError is the validation error +// returned by OrganizationServiceCreateResponse.Validate if the designated +// constraints aren't met. +type OrganizationServiceCreateResponseValidationError struct { + field string + reason string + cause error + key bool +} + +// Field function returns field value. +func (e OrganizationServiceCreateResponseValidationError) Field() string { return e.field } + +// Reason function returns reason value. +func (e OrganizationServiceCreateResponseValidationError) Reason() string { return e.reason } + +// Cause function returns cause value. +func (e OrganizationServiceCreateResponseValidationError) Cause() error { return e.cause } + +// Key function returns key value. +func (e OrganizationServiceCreateResponseValidationError) Key() bool { return e.key } + +// ErrorName returns error name. +func (e OrganizationServiceCreateResponseValidationError) ErrorName() string { + return "OrganizationServiceCreateResponseValidationError" +} + +// Error satisfies the builtin error interface +func (e OrganizationServiceCreateResponseValidationError) Error() string { + cause := "" + if e.cause != nil { + cause = fmt.Sprintf(" | caused by: %v", e.cause) + } + + key := "" + if e.key { + key = "key for " + } + + return fmt.Sprintf( + "invalid %sOrganizationServiceCreateResponse.%s: %s%s", + key, + e.field, + e.reason, + cause) +} + +var _ error = OrganizationServiceCreateResponseValidationError{} + +var _ interface { + Field() string + Reason() string + Key() bool + Cause() error + ErrorName() string +} = OrganizationServiceCreateResponseValidationError{} + // Validate checks the field values on OrganizationServiceUpdateRequest with // the rules defined in the proto definition for this message. If any rules // are violated, the first error encountered is returned, or nil if there are diff --git a/app/controlplane/api/controlplane/v1/organization.proto b/app/controlplane/api/controlplane/v1/organization.proto index c9f445682..2a8f15d6a 100644 --- a/app/controlplane/api/controlplane/v1/organization.proto +++ b/app/controlplane/api/controlplane/v1/organization.proto @@ -24,6 +24,7 @@ import "validate/validate.proto"; service OrganizationService { // List the organizations this user has access to rpc ListMemberships (OrganizationServiceListMembershipsRequest) returns (OrganizationServiceListMembershipsResponse); + rpc Create (OrganizationServiceCreateRequest) returns (OrganizationServiceCreateResponse); rpc Update (OrganizationServiceUpdateRequest) returns (OrganizationServiceUpdateResponse); rpc SetCurrentMembership (SetCurrentMembershipRequest) returns (SetCurrentMembershipResponse); } @@ -34,6 +35,14 @@ message OrganizationServiceListMembershipsResponse { repeated OrgMembershipItem result = 1; } +message OrganizationServiceCreateRequest { + string name = 1 [(validate.rules).string.min_len = 1]; +} + +message OrganizationServiceCreateResponse { + OrgItem result = 1; +} + message OrganizationServiceUpdateRequest { string id = 1 [(validate.rules).string.uuid = true]; // "optional" allow us to detect if the value is explicitly set diff --git a/app/controlplane/api/controlplane/v1/organization_grpc.pb.go b/app/controlplane/api/controlplane/v1/organization_grpc.pb.go index 36e3b28b8..b9bc43219 100644 --- a/app/controlplane/api/controlplane/v1/organization_grpc.pb.go +++ b/app/controlplane/api/controlplane/v1/organization_grpc.pb.go @@ -35,6 +35,7 @@ const _ = grpc.SupportPackageIsVersion7 const ( OrganizationService_ListMemberships_FullMethodName = "/controlplane.v1.OrganizationService/ListMemberships" + OrganizationService_Create_FullMethodName = "/controlplane.v1.OrganizationService/Create" OrganizationService_Update_FullMethodName = "/controlplane.v1.OrganizationService/Update" OrganizationService_SetCurrentMembership_FullMethodName = "/controlplane.v1.OrganizationService/SetCurrentMembership" ) @@ -45,6 +46,7 @@ const ( type OrganizationServiceClient interface { // List the organizations this user has access to ListMemberships(ctx context.Context, in *OrganizationServiceListMembershipsRequest, opts ...grpc.CallOption) (*OrganizationServiceListMembershipsResponse, error) + Create(ctx context.Context, in *OrganizationServiceCreateRequest, opts ...grpc.CallOption) (*OrganizationServiceCreateResponse, error) Update(ctx context.Context, in *OrganizationServiceUpdateRequest, opts ...grpc.CallOption) (*OrganizationServiceUpdateResponse, error) SetCurrentMembership(ctx context.Context, in *SetCurrentMembershipRequest, opts ...grpc.CallOption) (*SetCurrentMembershipResponse, error) } @@ -66,6 +68,15 @@ func (c *organizationServiceClient) ListMemberships(ctx context.Context, in *Org return out, nil } +func (c *organizationServiceClient) Create(ctx context.Context, in *OrganizationServiceCreateRequest, opts ...grpc.CallOption) (*OrganizationServiceCreateResponse, error) { + out := new(OrganizationServiceCreateResponse) + err := c.cc.Invoke(ctx, OrganizationService_Create_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *organizationServiceClient) Update(ctx context.Context, in *OrganizationServiceUpdateRequest, opts ...grpc.CallOption) (*OrganizationServiceUpdateResponse, error) { out := new(OrganizationServiceUpdateResponse) err := c.cc.Invoke(ctx, OrganizationService_Update_FullMethodName, in, out, opts...) @@ -90,6 +101,7 @@ func (c *organizationServiceClient) SetCurrentMembership(ctx context.Context, in type OrganizationServiceServer interface { // List the organizations this user has access to ListMemberships(context.Context, *OrganizationServiceListMembershipsRequest) (*OrganizationServiceListMembershipsResponse, error) + Create(context.Context, *OrganizationServiceCreateRequest) (*OrganizationServiceCreateResponse, error) Update(context.Context, *OrganizationServiceUpdateRequest) (*OrganizationServiceUpdateResponse, error) SetCurrentMembership(context.Context, *SetCurrentMembershipRequest) (*SetCurrentMembershipResponse, error) mustEmbedUnimplementedOrganizationServiceServer() @@ -102,6 +114,9 @@ type UnimplementedOrganizationServiceServer struct { func (UnimplementedOrganizationServiceServer) ListMemberships(context.Context, *OrganizationServiceListMembershipsRequest) (*OrganizationServiceListMembershipsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListMemberships not implemented") } +func (UnimplementedOrganizationServiceServer) Create(context.Context, *OrganizationServiceCreateRequest) (*OrganizationServiceCreateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Create not implemented") +} func (UnimplementedOrganizationServiceServer) Update(context.Context, *OrganizationServiceUpdateRequest) (*OrganizationServiceUpdateResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Update not implemented") } @@ -139,6 +154,24 @@ func _OrganizationService_ListMemberships_Handler(srv interface{}, ctx context.C return interceptor(ctx, in, info, handler) } +func _OrganizationService_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(OrganizationServiceCreateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrganizationServiceServer).Create(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: OrganizationService_Create_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrganizationServiceServer).Create(ctx, req.(*OrganizationServiceCreateRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _OrganizationService_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(OrganizationServiceUpdateRequest) if err := dec(in); err != nil { @@ -186,6 +219,10 @@ var OrganizationService_ServiceDesc = grpc.ServiceDesc{ MethodName: "ListMemberships", Handler: _OrganizationService_ListMemberships_Handler, }, + { + MethodName: "Create", + Handler: _OrganizationService_Create_Handler, + }, { MethodName: "Update", Handler: _OrganizationService_Update_Handler, diff --git a/app/controlplane/api/gen/frontend/controlplane/v1/organization.ts b/app/controlplane/api/gen/frontend/controlplane/v1/organization.ts index 3dc5991d4..cba23a877 100644 --- a/app/controlplane/api/gen/frontend/controlplane/v1/organization.ts +++ b/app/controlplane/api/gen/frontend/controlplane/v1/organization.ts @@ -13,6 +13,14 @@ export interface OrganizationServiceListMembershipsResponse { result: OrgMembershipItem[]; } +export interface OrganizationServiceCreateRequest { + name: string; +} + +export interface OrganizationServiceCreateResponse { + result?: OrgItem; +} + export interface OrganizationServiceUpdateRequest { id: string; /** @@ -148,6 +156,128 @@ export const OrganizationServiceListMembershipsResponse = { }, }; +function createBaseOrganizationServiceCreateRequest(): OrganizationServiceCreateRequest { + return { name: "" }; +} + +export const OrganizationServiceCreateRequest = { + encode(message: OrganizationServiceCreateRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.name !== "") { + writer.uint32(10).string(message.name); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): OrganizationServiceCreateRequest { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseOrganizationServiceCreateRequest(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.name = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): OrganizationServiceCreateRequest { + return { name: isSet(object.name) ? String(object.name) : "" }; + }, + + toJSON(message: OrganizationServiceCreateRequest): unknown { + const obj: any = {}; + message.name !== undefined && (obj.name = message.name); + return obj; + }, + + create, I>>( + base?: I, + ): OrganizationServiceCreateRequest { + return OrganizationServiceCreateRequest.fromPartial(base ?? {}); + }, + + fromPartial, I>>( + object: I, + ): OrganizationServiceCreateRequest { + const message = createBaseOrganizationServiceCreateRequest(); + message.name = object.name ?? ""; + return message; + }, +}; + +function createBaseOrganizationServiceCreateResponse(): OrganizationServiceCreateResponse { + return { result: undefined }; +} + +export const OrganizationServiceCreateResponse = { + encode(message: OrganizationServiceCreateResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.result !== undefined) { + OrgItem.encode(message.result, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + + decode(input: _m0.Reader | Uint8Array, length?: number): OrganizationServiceCreateResponse { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseOrganizationServiceCreateResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + + message.result = OrgItem.decode(reader, reader.uint32()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + + fromJSON(object: any): OrganizationServiceCreateResponse { + return { result: isSet(object.result) ? OrgItem.fromJSON(object.result) : undefined }; + }, + + toJSON(message: OrganizationServiceCreateResponse): unknown { + const obj: any = {}; + message.result !== undefined && (obj.result = message.result ? OrgItem.toJSON(message.result) : undefined); + return obj; + }, + + create, I>>( + base?: I, + ): OrganizationServiceCreateResponse { + return OrganizationServiceCreateResponse.fromPartial(base ?? {}); + }, + + fromPartial, I>>( + object: I, + ): OrganizationServiceCreateResponse { + const message = createBaseOrganizationServiceCreateResponse(); + message.result = (object.result !== undefined && object.result !== null) + ? OrgItem.fromPartial(object.result) + : undefined; + return message; + }, +}; + function createBaseOrganizationServiceUpdateRequest(): OrganizationServiceUpdateRequest { return { id: "", name: undefined }; } @@ -406,6 +536,10 @@ export interface OrganizationService { request: DeepPartial, metadata?: grpc.Metadata, ): Promise; + Create( + request: DeepPartial, + metadata?: grpc.Metadata, + ): Promise; Update( request: DeepPartial, metadata?: grpc.Metadata, @@ -422,6 +556,7 @@ export class OrganizationServiceClientImpl implements OrganizationService { constructor(rpc: Rpc) { this.rpc = rpc; this.ListMemberships = this.ListMemberships.bind(this); + this.Create = this.Create.bind(this); this.Update = this.Update.bind(this); this.SetCurrentMembership = this.SetCurrentMembership.bind(this); } @@ -437,6 +572,17 @@ export class OrganizationServiceClientImpl implements OrganizationService { ); } + Create( + request: DeepPartial, + metadata?: grpc.Metadata, + ): Promise { + return this.rpc.unary( + OrganizationServiceCreateDesc, + OrganizationServiceCreateRequest.fromPartial(request), + metadata, + ); + } + Update( request: DeepPartial, metadata?: grpc.Metadata, @@ -485,6 +631,29 @@ export const OrganizationServiceListMembershipsDesc: UnaryMethodDefinitionish = } as any, }; +export const OrganizationServiceCreateDesc: UnaryMethodDefinitionish = { + methodName: "Create", + service: OrganizationServiceDesc, + requestStream: false, + responseStream: false, + requestType: { + serializeBinary() { + return OrganizationServiceCreateRequest.encode(this).finish(); + }, + } as any, + responseType: { + deserializeBinary(data: Uint8Array) { + const value = OrganizationServiceCreateResponse.decode(data); + return { + ...value, + toObject() { + return value; + }, + }; + }, + } as any, +}; + export const OrganizationServiceUpdateDesc: UnaryMethodDefinitionish = { methodName: "Update", service: OrganizationServiceDesc, diff --git a/app/controlplane/internal/service/organization.go b/app/controlplane/internal/service/organization.go index 473cbc1ff..ea30a0dc2 100644 --- a/app/controlplane/internal/service/organization.go +++ b/app/controlplane/internal/service/organization.go @@ -63,6 +63,25 @@ func (s *OrganizationService) ListMemberships(ctx context.Context, _ *pb.Organiz return &pb.OrganizationServiceListMembershipsResponse{Result: result}, nil } +// Create persists an organization with a given name and associate it to the current user. +func (s *OrganizationService) Create(ctx context.Context, req *pb.OrganizationServiceCreateRequest) (*pb.OrganizationServiceCreateResponse, error) { + currentUser, _, err := loadCurrentUserAndOrg(ctx) + if err != nil { + return nil, err + } + + org, err := s.orgUC.Create(ctx, req.Name) + if err != nil { + return nil, handleUseCaseErr("organization", err, s.log) + } + + if _, err := s.membershipUC.Create(ctx, org.ID, currentUser.ID, false); err != nil { + return nil, handleUseCaseErr("organization", err, s.log) + } + + return &pb.OrganizationServiceCreateResponse{Result: bizOrgToPb(org)}, nil +} + func (s *OrganizationService) Update(ctx context.Context, req *pb.OrganizationServiceUpdateRequest) (*pb.OrganizationServiceUpdateResponse, error) { currentUser, _, err := loadCurrentUserAndOrg(ctx) if err != nil {