From b26d7d34b00a25d8ca627ef0c7825a8f6b4c096a Mon Sep 17 00:00:00 2001 From: Mark Pashmfouroush Date: Mon, 4 Mar 2024 18:58:49 +0000 Subject: [PATCH] warp: add Remove device function Signed-off-by: Mark Pashmfouroush --- warp/account.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/warp/account.go b/warp/account.go index e65254895..e02b55872 100644 --- a/warp/account.go +++ b/warp/account.go @@ -633,3 +633,36 @@ func CheckProfileExists(license string) bool { } return isOk } + +func RemoveDevice(account AccountData) error { + + headers := map[string]string{ + "Content-Type": "application/json", + "User-Agent": "okhttp/3.12.1", + "CF-Client-Version": "a-6.30-3596", + "Authorization": "Bearer " + account.AccessToken, + } + + req, err := http.NewRequest("DELETE", "https://api.cloudflareclient.com/v0a3596/reg/"+account.AccountID, nil) + if err != nil { + return err + } + + // Set headers + for k, v := range MergeMaps(defaultHeaders, headers) { + req.Header.Set(k, v) + } + + // Create HTTP client and execute request + response, err := client.Do(req) + if err != nil { + fmt.Println("sending request to remote server", err) + return err + } + + if response.StatusCode != 204 { + return fmt.Errorf("error in deleting account %d %s", response.StatusCode, response.Status) + } + + return nil +}