From 4e13468a9665733b8b57ea5cfe738599ed786969 Mon Sep 17 00:00:00 2001 From: Andrew Stucki Date: Tue, 3 Dec 2024 16:37:15 -0500 Subject: [PATCH] Scope clients to new hosts --- rpadmin/admin.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rpadmin/admin.go b/rpadmin/admin.go index 88850f2..092d958 100644 --- a/rpadmin/admin.go +++ b/rpadmin/admin.go @@ -220,6 +220,22 @@ func (a *AdminAPI) SetAuth(auth Auth) { a.auth = auth } +// ForBroker returns a new admin client with the same configuration as the initial +// client, but that talks to a single broker with the given id. +func (a *AdminAPI) ForBroker(ctx context.Context, id int) (*AdminAPI, error) { + url, err := a.BrokerIDToURL(ctx, id) + if err != nil { + return nil, err + } + return a.newAdminForSingleHost(url) +} + +// ForHost returns a new admin client with the same configuration as the initial +// client, but that talks to a single broker at the given url. +func (a *AdminAPI) ForHost(url string) (*AdminAPI, error) { + return a.newAdminForSingleHost(url) +} + func (a *AdminAPI) newAdminForSingleHost(host string) (*AdminAPI, error) { return newAdminAPI([]string{host}, a.auth, a.tlsConfig, nil, a.forCloud) }