2023-01-27 13:37:20 -08:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2022-04-29 21:03:00 -07:00
|
|
|
|
2022-08-02 11:34:03 -07:00
|
|
|
//go:build go1.19
|
2022-04-29 21:03:00 -07:00
|
|
|
|
|
|
|
package tailscale
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2023-01-26 19:35:26 -08:00
|
|
|
|
|
|
|
"tailscale.com/util/httpm"
|
2022-04-29 21:03:00 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
// TailnetDeleteRequest handles sending a DELETE request for a tailnet to control.
|
|
|
|
func (c *Client) TailnetDeleteRequest(ctx context.Context, tailnetID string) (err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("tailscale.DeleteTailnet: %w", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2025-02-12 10:34:28 -06:00
|
|
|
path := c.BuildTailnetURL("tailnet")
|
2023-01-26 19:35:26 -08:00
|
|
|
req, err := http.NewRequestWithContext(ctx, httpm.DELETE, path, nil)
|
2022-04-29 21:03:00 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-30 21:45:51 -07:00
|
|
|
c.setAuth(req)
|
2022-04-29 21:03:00 -07:00
|
|
|
b, resp, err := c.sendRequest(req)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
2025-02-12 10:34:28 -06:00
|
|
|
return HandleErrorResponse(b, resp)
|
2022-04-29 21:03:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|