mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-20 01:38:41 +02:00
[management] Add Bearer token support (#3534)
This commit is contained in:
parent
919fe94fd5
commit
939419a0ea
@ -68,28 +68,42 @@ type Client struct {
|
||||
Events *EventsAPI
|
||||
}
|
||||
|
||||
// New initialize new Client instance
|
||||
// New initialize new Client instance using PAT token
|
||||
func New(managementURL, token string) *Client {
|
||||
client := &Client{
|
||||
managementURL: managementURL,
|
||||
authHeader: "Token " + token,
|
||||
}
|
||||
client.Accounts = &AccountsAPI{client}
|
||||
client.Users = &UsersAPI{client}
|
||||
client.Tokens = &TokensAPI{client}
|
||||
client.Peers = &PeersAPI{client}
|
||||
client.SetupKeys = &SetupKeysAPI{client}
|
||||
client.Groups = &GroupsAPI{client}
|
||||
client.Policies = &PoliciesAPI{client}
|
||||
client.PostureChecks = &PostureChecksAPI{client}
|
||||
client.Networks = &NetworksAPI{client}
|
||||
client.Routes = &RoutesAPI{client}
|
||||
client.DNS = &DNSAPI{client}
|
||||
client.GeoLocation = &GeoLocationAPI{client}
|
||||
client.Events = &EventsAPI{client}
|
||||
client.initialize()
|
||||
return client
|
||||
}
|
||||
|
||||
// NewWithBearerToken initialize new Client instance using Bearer token type
|
||||
func NewWithBearerToken(managementURL, token string) *Client {
|
||||
client := &Client{
|
||||
managementURL: managementURL,
|
||||
authHeader: "Bearer " + token,
|
||||
}
|
||||
client.initialize()
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *Client) initialize() {
|
||||
c.Accounts = &AccountsAPI{c}
|
||||
c.Users = &UsersAPI{c}
|
||||
c.Tokens = &TokensAPI{c}
|
||||
c.Peers = &PeersAPI{c}
|
||||
c.SetupKeys = &SetupKeysAPI{c}
|
||||
c.Groups = &GroupsAPI{c}
|
||||
c.Policies = &PoliciesAPI{c}
|
||||
c.PostureChecks = &PostureChecksAPI{c}
|
||||
c.Networks = &NetworksAPI{c}
|
||||
c.Routes = &RoutesAPI{c}
|
||||
c.DNS = &DNSAPI{c}
|
||||
c.GeoLocation = &GeoLocationAPI{c}
|
||||
c.Events = &EventsAPI{c}
|
||||
}
|
||||
|
||||
func (c *Client) newRequest(ctx context.Context, method, path string, body io.Reader) (*http.Response, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, method, c.managementURL+path, body)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user