-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
165 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package spaceship | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/qdm12/ddns-updater/internal/provider/errors" | ||
"github.com/qdm12/ddns-updater/internal/provider/utils" | ||
) | ||
|
||
func (p *Provider) deleteRecord(ctx context.Context, client *http.Client, record Record) error { | ||
u := url.URL{ | ||
Scheme: "https", | ||
Host: "spaceship.dev", | ||
Path: fmt.Sprintf("/api/v1/dns/records/%s", p.domain), | ||
} | ||
|
||
deleteData := []Record{record} | ||
|
||
var requestBody bytes.Buffer | ||
if err := json.NewEncoder(&requestBody).Encode(deleteData); err != nil { | ||
return fmt.Errorf("encoding request body: %w", err) | ||
} | ||
|
||
request, err := http.NewRequestWithContext(ctx, http.MethodDelete, u.String(), &requestBody) | ||
if err != nil { | ||
return fmt.Errorf("creating request: %w", err) | ||
} | ||
p.setHeaders(request) | ||
|
||
response, err := client.Do(request) | ||
if err != nil { | ||
return err | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusNoContent { | ||
return fmt.Errorf("%w: %d: %s", | ||
errors.ErrHTTPStatusNotValid, response.StatusCode, | ||
utils.BodyToSingleLine(response.Body)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package spaceship | ||
|
||
// APIError represents the Spaceship API error response | ||
type APIError struct { | ||
Detail string `json:"detail"` | ||
Data []struct { | ||
Field string `json:"field"` | ||
Details string `json:"details"` | ||
} `json:"data"` | ||
} | ||
|
||
// Record represents a DNS record | ||
type Record struct { | ||
Type string `json:"type"` | ||
Name string `json:"name"` | ||
Address string `json:"address"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters