55bdebe8b2
* internal/engine/ooapi: auto-generated API client * feat: introduce the callers abstraction * feat: implement API caching on disk * feat: implement cloneWithToken when we require login * feat: implement login * fix: do not cache all APIs * feat: start making space for more tests * feat: implement caching policy * feat: write tests for caching layer * feat: add integration tests and fix some minor issues * feat: write much more unit tests * feat: add some more easy unit tests * feat: add tests that use a local server While there, make sure many fields we care about are OK. * doc: write basic documentation * fix: tweak sentence * doc: improve ooapi documentation * doc(ooapi): other documentation improvements * fix(ooapi): remove caching for most APIs We discussed this topic yesterday with @FedericoCeratto. The only place where we want LRU caching is MeasurementMeta. * feat(ooapi): improve handling of errors during login This was also discussed yesterday with @FedericoCeratto * fix(swaggerdiff_test.go): temporarily disable Before I work on this, I need to tend onto other tasks. * fix(ootest): add one more test case We're going towards 100% coverage of this package, as it ought to be. * feat(ooapi): test cases for when the probe clock is off * fix(ooapi): change test to have 100% unittest coverage * feat: sync server and client APIs definition Companion PR: https://github.com/ooni/api/pull/218 * fix(ooapi): start testing again against API * fix(ooapi): only generate each file once * chore: set version to 3.7.0-alpha While there, make sure we don't always skip a currently failing riseupvpn test, and slightly clarify the readme. * fix(kvstore): less scoped error message
277 lines
6.6 KiB
Go
277 lines
6.6 KiB
Go
// Code generated by go generate; DO NOT EDIT.
|
|
// 2021-02-26 15:45:53.567815989 +0100 CET m=+0.000158731
|
|
|
|
package ooapi
|
|
|
|
//go:generate go run ./internal/generator -file responses.go
|
|
|
|
import (
|
|
"io"
|
|
"io/ioutil"
|
|
"net/http"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/ooapi/apimodel"
|
|
)
|
|
|
|
func (api *CheckReportIDAPI) newResponse(resp *http.Response, err error) (*apimodel.CheckReportIDResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.CheckReportIDResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *CheckInAPI) newResponse(resp *http.Response, err error) (*apimodel.CheckInResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.CheckInResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *LoginAPI) newResponse(resp *http.Response, err error) (*apimodel.LoginResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.LoginResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *MeasurementMetaAPI) newResponse(resp *http.Response, err error) (*apimodel.MeasurementMetaResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.MeasurementMetaResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *RegisterAPI) newResponse(resp *http.Response, err error) (*apimodel.RegisterResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.RegisterResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *TestHelpersAPI) newResponse(resp *http.Response, err error) (apimodel.TestHelpersResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := apimodel.TestHelpersResponse{}
|
|
if err := api.jsonCodec().Decode(data, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if out == nil {
|
|
return nil, ErrJSONLiteralNull
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *PsiphonConfigAPI) newResponse(resp *http.Response, err error) (apimodel.PsiphonConfigResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := apimodel.PsiphonConfigResponse{}
|
|
if err := api.jsonCodec().Decode(data, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if out == nil {
|
|
return nil, ErrJSONLiteralNull
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *TorTargetsAPI) newResponse(resp *http.Response, err error) (apimodel.TorTargetsResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := apimodel.TorTargetsResponse{}
|
|
if err := api.jsonCodec().Decode(data, &out); err != nil {
|
|
return nil, err
|
|
}
|
|
if out == nil {
|
|
return nil, ErrJSONLiteralNull
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *URLsAPI) newResponse(resp *http.Response, err error) (*apimodel.URLsResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.URLsResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *OpenReportAPI) newResponse(resp *http.Response, err error) (*apimodel.OpenReportResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.OpenReportResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func (api *SubmitMeasurementAPI) newResponse(resp *http.Response, err error) (*apimodel.SubmitMeasurementResponse, error) {
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.StatusCode == 401 {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
if resp.StatusCode != 200 {
|
|
return nil, newHTTPFailure(resp.StatusCode)
|
|
}
|
|
defer resp.Body.Close()
|
|
reader := io.LimitReader(resp.Body, 4<<20)
|
|
data, err := ioutil.ReadAll(reader)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out := &apimodel.SubmitMeasurementResponse{}
|
|
if err := api.jsonCodec().Decode(data, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|