[MM-56078] mmctl: assume local mode when no credentials found (#26215)
* assume local mode when no credentials found * Use variable --------- Co-authored-by: Mattermost Build <build@mattermost.com> Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
@@ -218,7 +218,7 @@ func validateArgsWithClient(fn validateArgsFn) func(cmd *cobra.Command, args []s
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), shellCompleteTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), shellCompleteTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c, _, _, err := getClient(ctx)
|
c, _, _, err := getClient(ctx, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cobra.ShellCompDirectiveError
|
return nil, cobra.ShellCompDirectiveError
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,8 +68,22 @@ func CheckVersionMatch(version, serverVersion string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getClient(ctx context.Context) (*model.Client4, string, bool, error) {
|
func getClient(ctx context.Context, cmd *cobra.Command) (*model.Client4, string, bool, error) {
|
||||||
if viper.GetBool("local") {
|
useLocal := viper.GetBool("local")
|
||||||
|
|
||||||
|
if !useLocal {
|
||||||
|
// Assume local mode if no server address is provided
|
||||||
|
credentials, err := GetCurrentCredentials()
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Warning: Unable to retrieve credentials, assuming --local mode")
|
||||||
|
useLocal = true
|
||||||
|
} else if credentials == nil {
|
||||||
|
cmd.PrintErrln("Warning: No credentials found, assuming --local mode")
|
||||||
|
useLocal = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if useLocal {
|
||||||
c, err := InitUnixClient(viper.GetString("local-socket-path"))
|
c, err := InitUnixClient(viper.GetString("local-socket-path"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", true, err
|
return nil, "", true, err
|
||||||
@@ -90,7 +104,7 @@ func getClient(ctx context.Context) (*model.Client4, string, bool, error) {
|
|||||||
func withClient(fn func(c client.Client, cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error {
|
func withClient(fn func(c client.Client, cmd *cobra.Command, args []string) error) func(cmd *cobra.Command, args []string) error {
|
||||||
return func(cmd *cobra.Command, args []string) error {
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
c, serverVersion, local, err := getClient(ctx)
|
c, serverVersion, local, err := getClient(ctx, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create client: %w", err)
|
return fmt.Errorf("failed to create client: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user