Skip to content

Commit 5bb14e4

Browse files
authored
feat(controlplane): show role information in API (#554)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 1b6c0aa commit 5bb14e4

21 files changed

+405
-211
lines changed

app/cli/cmd/organization_describe.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ func contextTableOutput(config *action.ConfigContextItem) error {
4646
gt.SetTitle("Current Context")
4747
gt.AppendRow(table.Row{"Logged in as", config.CurrentUser.Email})
4848
gt.AppendSeparator()
49-
gt.AppendRow(table.Row{"Organization", fmt.Sprintf("%s (%s)", config.CurrentOrg.Name, config.CurrentOrg.ID)})
49+
50+
if m := config.CurrentMembership; m != nil {
51+
gt.AppendRow(table.Row{"Organization", fmt.Sprintf("%s (role=%s)", m.Org.Name, m.Role)})
52+
}
53+
5054
backend := config.CurrentCASBackend
5155
if backend != nil {
5256
gt.AppendSeparator()

app/cli/cmd/organization_list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -49,10 +49,10 @@ func orgMembershipTableOutput(items []*action.MembershipItem) error {
4949
}
5050

5151
t := newTableWriter()
52-
t.AppendHeader(table.Row{"Org ID", "Org Name", "Current", "Joined At"})
52+
t.AppendHeader(table.Row{"Org ID", "Org Name", "Current", "Role", "Joined At"})
5353

5454
for _, i := range items {
55-
t.AppendRow(table.Row{i.Org.ID, i.Org.Name, i.Current, i.CreatedAt.Format(time.RFC822)})
55+
t.AppendRow(table.Row{i.Org.ID, i.Org.Name, i.Current, i.Role, i.CreatedAt.Format(time.RFC822)})
5656
t.AppendSeparator()
5757
}
5858

app/cli/internal/action/config_current_context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewConfigCurrentContext(cfg *ActionsOpts) *ConfigCurrentContext {
3232

3333
type ConfigContextItem struct {
3434
CurrentUser *UserItem
35-
CurrentOrg *OrgItem
35+
CurrentMembership *MembershipItem
3636
CurrentCASBackend *CASBackendItem
3737
}
3838

@@ -52,7 +52,7 @@ func (action *ConfigCurrentContext) Run() (*ConfigContextItem, error) {
5252

5353
return &ConfigContextItem{
5454
CurrentUser: pbUserItemToAction(res.GetCurrentUser()),
55-
CurrentOrg: pbOrgItemToAction(res.GetCurrentOrg()),
55+
CurrentMembership: pbMembershipItemToAction(res.GetCurrentMembership()),
5656
CurrentCASBackend: pbCASBackendItemToAction(res.GetCurrentCasBackend()),
5757
}, nil
5858
}

app/cli/internal/action/membership_list.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ type MembershipItem struct {
3737
CreatedAt *time.Time `json:"joinedAt"`
3838
UpdatedAt *time.Time `json:"updatedAt"`
3939
Org *OrgItem
40+
Role string `json:"role"`
4041
}
4142

4243
func NewMembershipList(cfg *ActionsOpts) *MembershipList {
@@ -71,11 +72,22 @@ func pbMembershipItemToAction(in *pb.OrgMembershipItem) *MembershipItem {
7172
return nil
7273
}
7374

75+
var role string
76+
switch in.Role {
77+
case pb.MembershipRole_MEMBERSHIP_ROLE_ORG_ADMIN:
78+
role = "admin"
79+
case pb.MembershipRole_MEMBERSHIP_ROLE_ORG_VIEWER:
80+
role = "viewer"
81+
case pb.MembershipRole_MEMBERSHIP_ROLE_ORG_OWNER:
82+
role = "owner"
83+
}
84+
7485
return &MembershipItem{
7586
ID: in.GetId(),
7687
CreatedAt: toTimePtr(in.GetCreatedAt().AsTime()),
7788
UpdatedAt: toTimePtr(in.GetCreatedAt().AsTime()),
7889
Org: pbOrgItemToAction(in.Org),
7990
Current: in.Current,
91+
Role: role,
8092
}
8193
}

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

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

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

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

app/controlplane/api/controlplane/v1/context.proto

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -16,23 +16,24 @@
1616
syntax = "proto3";
1717

1818
package controlplane.v1;
19-
option go_package = "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1;v1";
2019

2120
import "controlplane/v1/response_messages.proto";
2221

22+
option go_package = "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1;v1";
23+
2324
service ContextService {
2425
// Get information about the current logged in context
25-
rpc Current (ContextServiceCurrentRequest) returns (ContextServiceCurrentResponse);
26+
rpc Current(ContextServiceCurrentRequest) returns (ContextServiceCurrentResponse);
2627
}
2728

2829
message ContextServiceCurrentRequest {}
2930

3031
message ContextServiceCurrentResponse {
3132
Result result = 1;
32-
33+
3334
message Result {
3435
User current_user = 1;
35-
OrgItem current_org = 2;
36+
OrgMembershipItem current_membership = 2;
3637
CASBackendItem current_cas_backend = 3;
3738
}
3839
}

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

Lines changed: 1 addition & 1 deletion
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.go

Lines changed: 1 addition & 1 deletion
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: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -16,20 +16,21 @@
1616
syntax = "proto3";
1717

1818
package controlplane.v1;
19-
option go_package = "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1;v1";
2019

2120
import "controlplane/v1/response_messages.proto";
2221
import "validate/validate.proto";
2322

23+
option go_package = "github.com/chainloop-dev/chainloop/app/controlplane/api/controlplane/v1;v1";
24+
2425
service OrganizationService {
2526
// Mermbership management
2627
// List the organizations this user has access to
27-
rpc ListMemberships (OrganizationServiceListMembershipsRequest) returns (OrganizationServiceListMembershipsResponse);
28-
rpc DeleteMembership (DeleteMembershipRequest) returns (DeleteMembershipResponse);
29-
rpc SetCurrentMembership (SetCurrentMembershipRequest) returns (SetCurrentMembershipResponse);
28+
rpc ListMemberships(OrganizationServiceListMembershipsRequest) returns (OrganizationServiceListMembershipsResponse);
29+
rpc DeleteMembership(DeleteMembershipRequest) returns (DeleteMembershipResponse);
30+
rpc SetCurrentMembership(SetCurrentMembershipRequest) returns (SetCurrentMembershipResponse);
3031
// Organization management
31-
rpc Create (OrganizationServiceCreateRequest) returns (OrganizationServiceCreateResponse);
32-
rpc Update (OrganizationServiceUpdateRequest) returns (OrganizationServiceUpdateResponse);
32+
rpc Create(OrganizationServiceCreateRequest) returns (OrganizationServiceCreateResponse);
33+
rpc Update(OrganizationServiceUpdateRequest) returns (OrganizationServiceUpdateResponse);
3334
}
3435

3536
message OrganizationServiceListMembershipsRequest {}

0 commit comments

Comments
 (0)