Skip to content

Commit cd122f9

Browse files
authored
feat(controlplane): create organization (#450)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 4a6e458 commit cd122f9

File tree

10 files changed

+801
-89
lines changed

10 files changed

+801
-89
lines changed

app/cli/cmd/organization.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func newOrganizationCmd() *cobra.Command {
2828

2929
cmd.AddCommand(
3030
newOrganizationList(),
31+
newOrganizationCreateCmd(),
3132
newOrganizationUpdateCmd(),
3233
newOrganizationSet(),
3334
newOrganizationDescribeCmd(),

app/cli/cmd/organization_create.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Copyright 2023 The Chainloop Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package cmd
17+
18+
import (
19+
"context"
20+
21+
"github.com/chainloop-dev/chainloop/app/cli/internal/action"
22+
"github.com/spf13/cobra"
23+
)
24+
25+
func newOrganizationCreateCmd() *cobra.Command {
26+
var name string
27+
28+
cmd := &cobra.Command{
29+
Use: "create",
30+
Short: "Create an organization",
31+
RunE: func(cmd *cobra.Command, args []string) error {
32+
org, err := action.NewOrgCreate(actionOpts).Run(context.Background(), name)
33+
if err != nil {
34+
return err
35+
}
36+
37+
logger.Info().Msgf("Organization %q created!", org.Name)
38+
return nil
39+
},
40+
}
41+
42+
cmd.Flags().StringVar(&name, "name", "", "organization name")
43+
err := cmd.MarkFlagRequired("name")
44+
cobra.CheckErr(err)
45+
46+
return cmd
47+
}

app/cli/cmd/organization_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ func newOrganizationUpdateCmd() *cobra.Command {
4848
err := cmd.MarkFlagRequired("id")
4949
cobra.CheckErr(err)
5050

51-
cmd.Flags().StringVar(&name, "name", "", "workflow name")
51+
cmd.Flags().StringVar(&name, "name", "", "organization name")
5252
return cmd
5353
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Copyright 2023 The Chainloop Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package action
17+
18+
import (
19+
"context"
20+
21+
pb "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1"
22+
)
23+
24+
type OrgCreate struct {
25+
cfg *ActionsOpts
26+
}
27+
28+
func NewOrgCreate(cfg *ActionsOpts) *OrgCreate {
29+
return &OrgCreate{cfg}
30+
}
31+
32+
func (action *OrgCreate) Run(ctx context.Context, name string) (*OrgItem, error) {
33+
client := pb.NewOrganizationServiceClient(action.cfg.CPConnection)
34+
resp, err := client.Create(ctx, &pb.OrganizationServiceCreateRequest{Name: name})
35+
if err != nil {
36+
return nil, err
37+
}
38+
39+
return pbOrgItemToAction(resp.Result), nil
40+
}

app/controlplane/api/controlplane/v1/organization.pb.go

Lines changed: 228 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/organization.pb.validate.go

Lines changed: 250 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/controlplane/api/controlplane/v1/organization.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import "validate/validate.proto";
2424
service OrganizationService {
2525
// List the organizations this user has access to
2626
rpc ListMemberships (OrganizationServiceListMembershipsRequest) returns (OrganizationServiceListMembershipsResponse);
27+
rpc Create (OrganizationServiceCreateRequest) returns (OrganizationServiceCreateResponse);
2728
rpc Update (OrganizationServiceUpdateRequest) returns (OrganizationServiceUpdateResponse);
2829
rpc SetCurrentMembership (SetCurrentMembershipRequest) returns (SetCurrentMembershipResponse);
2930
}
@@ -34,6 +35,14 @@ message OrganizationServiceListMembershipsResponse {
3435
repeated OrgMembershipItem result = 1;
3536
}
3637

38+
message OrganizationServiceCreateRequest {
39+
string name = 1 [(validate.rules).string.min_len = 1];
40+
}
41+
42+
message OrganizationServiceCreateResponse {
43+
OrgItem result = 1;
44+
}
45+
3746
message OrganizationServiceUpdateRequest {
3847
string id = 1 [(validate.rules).string.uuid = true];
3948
// "optional" allow us to detect if the value is explicitly set

0 commit comments

Comments
 (0)