simply: update to API v2 (#2631)

This commit is contained in:
Ludovic Fernandez 2025-08-28 17:04:43 +02:00 committed by GitHub
commit cb44524070
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 11 deletions

View file

@ -16,7 +16,7 @@ import (
"github.com/go-acme/lego/v4/providers/dns/internal/errutils"
)
const defaultBaseURL = "https://api.simply.com/1/"
const defaultBaseURL = "https://api.simply.com/2/"
// Client is a Simply.com API client.
type Client struct {
@ -111,10 +111,12 @@ func (c *Client) DeleteRecord(ctx context.Context, zoneName string, id int64) er
}
func (c *Client) createEndpoint(zoneName, uri string) *url.URL {
return c.baseURL.JoinPath(c.accountName, c.apiKey, "my", "products", zoneName, "dns", "records", strings.TrimSuffix(uri, "/"))
return c.baseURL.JoinPath("my", "products", zoneName, "dns", "records", strings.TrimSuffix(uri, "/"))
}
func (c *Client) do(req *http.Request, result Response) error {
req.SetBasicAuth(c.accountName, c.apiKey)
resp, err := c.HTTPClient.Do(req)
if err != nil {
return errutils.NewHTTPDoError(req, err)

View file

@ -24,12 +24,13 @@ func mockBuilder() *servermock.Builder[*Client] {
return client, nil
},
servermock.CheckHeader().WithJSONHeaders())
servermock.CheckHeader().WithJSONHeaders().
WithBasicAuth("accountname", "apikey"))
}
func TestClient_GetRecords(t *testing.T) {
client := mockBuilder().
Route("GET /accountname/apikey/my/products/azone01/dns/records",
Route("GET /my/products/azone01/dns/records",
servermock.ResponseFromFixture("get_records.json")).
Build(t)
@ -76,7 +77,7 @@ func TestClient_GetRecords(t *testing.T) {
func TestClient_GetRecords_error(t *testing.T) {
client := mockBuilder().
Route("GET /accountname/apikey/my/products/azone01/dns/records",
Route("GET /my/products/azone01/dns/records",
servermock.ResponseFromFixture("bad_auth_error.json").
WithStatusCode(http.StatusBadRequest)).
Build(t)
@ -89,7 +90,7 @@ func TestClient_GetRecords_error(t *testing.T) {
func TestClient_AddRecord(t *testing.T) {
client := mockBuilder().
Route("POST /accountname/apikey/my/products/azone01/dns/records",
Route("POST /my/products/azone01/dns/records",
servermock.ResponseFromFixture("add_record.json")).
Build(t)
@ -109,7 +110,7 @@ func TestClient_AddRecord(t *testing.T) {
func TestClient_AddRecord_error(t *testing.T) {
client := mockBuilder().
Route("POST /accountname/apikey/my/products/azone01/dns/records",
Route("POST /my/products/azone01/dns/records",
servermock.ResponseFromFixture("bad_zone_error.json").
WithStatusCode(http.StatusNotFound)).
Build(t)
@ -130,7 +131,7 @@ func TestClient_AddRecord_error(t *testing.T) {
func TestClient_EditRecord(t *testing.T) {
client := mockBuilder().
Route("PUT /accountname/apikey/my/products/azone01/dns/records/123456789",
Route("PUT /my/products/azone01/dns/records/123456789",
servermock.ResponseFromFixture("success.json")).
Build(t)
@ -148,7 +149,7 @@ func TestClient_EditRecord(t *testing.T) {
func TestClient_EditRecord_error(t *testing.T) {
client := mockBuilder().
Route("PUT /accountname/apikey/my/products/azone01/dns/records/123456789",
Route("PUT /my/products/azone01/dns/records/123456789",
servermock.ResponseFromFixture("invalid_record_id.json").
WithStatusCode(http.StatusNotFound)).
Build(t)
@ -167,7 +168,7 @@ func TestClient_EditRecord_error(t *testing.T) {
func TestClient_DeleteRecord(t *testing.T) {
client := mockBuilder().
Route("DELETE /accountname/apikey/my/products/azone01/dns/records/123456789",
Route("DELETE /my/products/azone01/dns/records/123456789",
servermock.ResponseFromFixture("success.json")).
Build(t)
@ -177,7 +178,7 @@ func TestClient_DeleteRecord(t *testing.T) {
func TestClient_DeleteRecord_error(t *testing.T) {
client := mockBuilder().
Route("DELETE /accountname/apikey/my/products/azone01/dns/records/123456789",
Route("DELETE /my/products/azone01/dns/records/123456789",
servermock.ResponseFromFixture("invalid_record_id.json").
WithStatusCode(http.StatusNotFound)).
Build(t)

View file

@ -22,3 +22,4 @@ lego --email you@example.com --dns simply -d '*.example.com' -d example.com run
[Links]
API = "https://www.simply.com/en/docs/api/"
Spec = "https://generator.swagger.io/?url=https://api.simply.com/2/openapi.json#/"