mattermost-community-enterp.../cmd/mmctl/commands/oauth.go
Claude ec1f89217a Merge: Complete Mattermost Server with Community Enterprise
Full Mattermost server source with integrated Community Enterprise features.
Includes vendor directory for offline/air-gapped builds.

Structure:
- enterprise-impl/: Enterprise feature implementations
- enterprise-community/: Init files that register implementations
- enterprise/: Bridge imports (community_imports.go)
- vendor/: All dependencies for offline builds

Build (online):
  go build ./cmd/mattermost

Build (offline/air-gapped):
  go build -mod=vendor ./cmd/mattermost

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 23:59:07 +09:00

84 lines
1.9 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package commands
import (
"context"
"fmt"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/client"
"github.com/mattermost/mattermost/server/v8/cmd/mmctl/printer"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
var OAuthCmd = &cobra.Command{
Use: "oauth",
Short: "Management of OAuth2 apps",
}
var ListOAuthAppsCmd = &cobra.Command{
Use: "list",
Short: "List OAuth2 apps",
Long: "list all OAuth2 apps",
Example: " oauth list",
RunE: withClient(listOAuthAppsCmdF),
Args: cobra.NoArgs,
}
func listOAuthAppsCmdF(c client.Client, command *cobra.Command, args []string) error {
page, err := command.Flags().GetInt("page")
if err != nil {
return err
}
perPage, err := command.Flags().GetInt("per-page")
if err != nil {
return err
}
apps, _, err := c.GetOAuthApps(context.Background(), page, perPage)
if err != nil {
return errors.Wrap(err, "Failed to fetch oauth2 apps")
}
userIds := make([]string, len(apps))
for i := range apps {
userIds[i] = apps[i].CreatorId
}
users, _, err := c.GetUsersByIds(context.Background(), userIds)
if err != nil {
return errors.Wrap(err, "Failed to fetch users for oauth2 apps")
}
usersByID := map[string]*model.User{}
for _, user := range users {
usersByID[user.Id] = user
}
for _, app := range apps {
ownerName := app.CreatorId
if owner, ok := usersByID[app.CreatorId]; ok {
ownerName = owner.Username
}
printer.PrintT(fmt.Sprintf("{{.Id}}: {{.Name}} (Created by %s)", ownerName), app)
}
return nil
}
func init() {
ListOAuthAppsCmd.Flags().Int("page", 0, "Page number to fetch for the list of OAuth2 apps")
ListOAuthAppsCmd.Flags().Int("per-page", DefaultPageSize, "Number of OAuth2 apps to be fetched")
OAuthCmd.AddCommand(
ListOAuthAppsCmd,
)
RootCmd.AddCommand(OAuthCmd)
}