Skip to content
Open
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
2 changes: 1 addition & 1 deletion internal/api-key/command_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *command) describe(cmd *cobra.Command, args []string) error {
resourceIdToUserIdMap := mapResourceIdToUserId(allUsers)
usersMap := getUsersMap(allUsers)

serviceAccounts, err := c.V2Client.ListIamServiceAccounts()
serviceAccounts, err := c.V2Client.ListIamServiceAccounts(nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/api-key/command_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *command) list(cmd *cobra.Command, _ []string) error {
serviceAccount = c.Context.GetCurrentServiceAccount()
}

serviceAccounts, err := c.V2Client.ListIamServiceAccounts()
serviceAccounts, err := c.V2Client.ListIamServiceAccounts(nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/flink/command_statement_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *command) addPrincipalFlag(cmd *cobra.Command) {
return nil
}

serviceAccounts, err := c.V2Client.ListIamServiceAccounts()
serviceAccounts, err := c.V2Client.ListIamServiceAccounts(nil)
if err != nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/iam/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func autocompleteResourceOwners(client *ccloudv2.Client) []string {
if err != nil {
return nil
}
serviceAccounts, err := client.ListIamServiceAccounts()
serviceAccounts, err := client.ListIamServiceAccounts(nil)
if err != nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/iam/command_rbac_role_binding_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (c *roleBindingCommand) getPrincipalToUserMap() (map[string]*iamv2.IamV2Use
}

func (c *roleBindingCommand) getServiceAccountIdToNameMap() (map[string]string, error) {
serviceAccounts, err := c.V2Client.ListIamServiceAccounts()
serviceAccounts, err := c.V2Client.ListIamServiceAccounts(nil)
if err != nil {
return nil, err
}
Expand Down
8 changes: 7 additions & 1 deletion internal/iam/command_service_account_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ func (c *serviceAccountCommand) newListCommand() *cobra.Command {
RunE: c.list,
}

cmd.Flags().StringSlice("display-name", nil, "A comma-separated list of service account display names.")
pcmd.AddContextFlag(cmd, c.CLICommand)
pcmd.AddOutputFlag(cmd)

return cmd
}

func (c *serviceAccountCommand) list(cmd *cobra.Command, _ []string) error {
serviceAccounts, err := c.V2Client.ListIamServiceAccounts()
displayNames, err := cmd.Flags().GetStringSlice("display-name")
if err != nil {
return err
}

serviceAccounts, err := c.V2Client.ListIamServiceAccounts(displayNames)
Comment on lines +27 to +31
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new --display-name filtering behavior isn’t covered by the existing CLI integration tests. There are already golden tests for iam service-account list, so please add a new test case exercising iam service-account list --display-name ... and update the test server handler for /iam/v2/service-accounts to honor the display_name query param so the test can actually validate filtering (not just ignore the param).

Copilot uses AI. Check for mistakes.
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ksql/command_cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *ksqlCommand) addCredentialIdentityFlag(cmd *cobra.Command) {
return nil
}

serviceAccounts, err := c.V2Client.ListIamServiceAccounts()
serviceAccounts, err := c.V2Client.ListIamServiceAccounts(nil)
if err != nil {
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/ccloudv2/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func (c *Client) UpdateIamServiceAccount(id string, update iamv2.IamV2ServiceAcc
return c.IamClient.ServiceAccountsIamV2Api.UpdateIamV2ServiceAccount(c.iamApiContext(), id).IamV2ServiceAccount(update).Execute()
}

func (c *Client) ListIamServiceAccounts() ([]iamv2.IamV2ServiceAccount, error) {
func (c *Client) ListIamServiceAccounts(displayName []string) ([]iamv2.IamV2ServiceAccount, error) {
var list []iamv2.IamV2ServiceAccount

done := false
pageToken := ""
for !done {
page, httpResp, err := c.executeListServiceAccounts(pageToken)
page, httpResp, err := c.executeListServiceAccounts(pageToken, displayName)
if err != nil {
return nil, errors.CatchCCloudV2Error(err, httpResp)
}
Expand All @@ -64,8 +64,11 @@ func (c *Client) ListIamServiceAccounts() ([]iamv2.IamV2ServiceAccount, error) {
return list, nil
}

func (c *Client) executeListServiceAccounts(pageToken string) (iamv2.IamV2ServiceAccountList, *http.Response, error) {
func (c *Client) executeListServiceAccounts(pageToken string, displayName []string) (iamv2.IamV2ServiceAccountList, *http.Response, error) {
req := c.IamClient.ServiceAccountsIamV2Api.ListIamV2ServiceAccounts(c.iamApiContext()).PageSize(ccloudV2ListPageSize)
if len(displayName) > 0 {
req = req.DisplayName(displayName)
}
if pageToken != "" {
req = req.PageToken(pageToken)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func AddServiceAccountFlag(cmd *cobra.Command, command *AuthenticatedCLICommand)
}

func AutocompleteServiceAccounts(client *ccloudv2.Client) []string {
serviceAccounts, err := client.ListIamServiceAccounts()
serviceAccounts, err := client.ListIamServiceAccounts(nil)
if err != nil {
return nil
}
Expand Down