Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/cli/cmd/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func newOrganizationCmd() *cobra.Command {

cmd.AddCommand(
newOrganizationList(),
newOrganizationCreateCmd(),
newOrganizationUpdateCmd(),
newOrganizationSet(),
newOrganizationDescribeCmd(),
Expand Down
47 changes: 47 additions & 0 deletions app/cli/cmd/organization_create.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion app/cli/cmd/organization_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
40 changes: 40 additions & 0 deletions app/cli/internal/action/org_create.go
Original file line number Diff line number Diff line change
@@ -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
}
316 changes: 228 additions & 88 deletions app/controlplane/api/controlplane/v1/organization.pb.go

Large diffs are not rendered by default.

250 changes: 250 additions & 0 deletions app/controlplane/api/controlplane/v1/organization.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions app/controlplane/api/controlplane/v1/organization.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down
Loading