package central

import (
	"context"

	"github.com/tidbcloud/clusterproxy/pkg/k8s/tidb"
	"github.com/tidbcloud/clusterproxy/resolve"
	"github.com/tidbcloud/clusterproxy/route"
)

func checkClusterAccess(ctx context.Context, c *route.Context, cl resolve.Cluster, user string, password string) error {
	db, err := tidb.Connect(c, cl, user, password)
	if err != nil {
		return err
	}
	defer db.Close()
	if err = db.PingContext(ctx); err != nil {
		return err
	}
	return nil
}
