mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-20 07:21:27 +02:00
Add the wrappers needed to drive the bring-your-own-proxy + private-
service flows from external tooling (CI, IaC, dashboards built against
the REST client). The existing Service / ProxyCluster types already
carry Private / AccessGroups / direct_upstream via the openapi-generated
shapes, so the new code is the API surface itself — not field-level
plumbing.
- ReverseProxyClustersAPI.Delete(clusterAddress): DELETE
/api/reverse-proxies/clusters/{clusterAddress}. Removes every
self-hosted (BYOP) proxy registration the calling account owns under
that address. Shared clusters operated by NetBird are 404 here.
- ReverseProxyTokensAPI (new file): List / Create / Delete against
/api/reverse-proxies/proxy-tokens. Tokens are account-scoped and
used by `netbird proxy` to register against management. Create
returns api.ProxyTokenCreated, whose PlainToken is the one-shot
secret; List and Delete operate on metadata only.
Tests cover the success + error paths for each new operation and pin
the cluster List response to round-trip the `private` capability flag.
Existing reverse_proxy_services_test.go was failing to build on the
parent commit because the regenerated api types switched Service.Auth
to *ServiceAuthConfig and Service.Targets to *[]ServiceTarget; fixed
the literals (`&api.ServiceAuthConfig{}`, `&[]api.ServiceTarget{...}`,
`(*req.Targets)[0]`) so the integration tag builds again — necessary
to even run the new tests.
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package rest
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"github.com/netbirdio/netbird/shared/management/http/api"
|
|
)
|
|
|
|
// ReverseProxyClustersAPI APIs for Reverse Proxy Clusters, do not use directly
|
|
type ReverseProxyClustersAPI struct {
|
|
c *Client
|
|
}
|
|
|
|
// List lists all available proxy clusters. Each cluster is enriched with the
|
|
// capability flags reported by its connected proxies (supports_custom_ports,
|
|
// supports_crowdsec, private, etc.), so callers can render UX gates without
|
|
// a follow-up round-trip.
|
|
func (a *ReverseProxyClustersAPI) List(ctx context.Context) ([]api.ProxyCluster, error) {
|
|
resp, err := a.c.NewRequest(ctx, "GET", "/api/reverse-proxies/clusters", nil, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.Body != nil {
|
|
defer resp.Body.Close()
|
|
}
|
|
ret, err := parseResponse[[]api.ProxyCluster](resp)
|
|
return ret, err
|
|
}
|
|
|
|
// Delete removes every self-hosted (BYOP) proxy registration for the given
|
|
// cluster address owned by the calling account. Shared clusters operated by
|
|
// NetBird cannot be deleted via this endpoint; the server returns 404 / 400
|
|
// for cluster addresses the account does not own.
|
|
func (a *ReverseProxyClustersAPI) Delete(ctx context.Context, clusterAddress string) error {
|
|
resp, err := a.c.NewRequest(ctx, "DELETE", "/api/reverse-proxies/clusters/"+url.PathEscape(clusterAddress), nil, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if resp.Body != nil {
|
|
defer resp.Body.Close()
|
|
}
|
|
return nil
|
|
}
|