dba861d262
1. we want optionally to log the body (we don't want to log the body when we're fetching psiphon secrets or tor targets) 2. we want body logging to _also_ happen on error since this is quite useful to debug possible errors when accessing the API This diff adds the above functionality, which were previously described in https://github.com/ooni/probe/issues/1951. This diff also adds comprehensive testing.
30 lines
719 B
Go
30 lines
719 B
Go
package probeservices
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/httpx"
|
|
)
|
|
|
|
type checkReportIDResponse struct {
|
|
Found bool `json:"found"`
|
|
}
|
|
|
|
// CheckReportID checks whether the given ReportID exists.
|
|
func (c Client) CheckReportID(ctx context.Context, reportID string) (bool, error) {
|
|
query := url.Values{}
|
|
query.Add("report_id", reportID)
|
|
var response checkReportIDResponse
|
|
err := (&httpx.APIClientTemplate{
|
|
BaseURL: c.BaseURL,
|
|
HTTPClient: c.HTTPClient,
|
|
Logger: c.Logger,
|
|
UserAgent: c.UserAgent,
|
|
}).WithBodyLogging().Build().GetJSONWithQuery(ctx, "/api/_/check_report_id", query, &response)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return response.Found, nil
|
|
}
|