apiclient

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

README

PoC OONI client API

This repository contains a PoC where we automatically generate Go clients for using the OONI API.

Most code is generated from annotated data structures and from definitions of all the supported APIs.

We generate a Swagger 2.0 definition of the API recognized by the client. Tests check whether the client's definition of the API is in sync with the server's own definition.

This code will eventually be merged into ooni/probe-cli.

Documentation

Overview

Package apiclient contains a client for the OONI API.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrHTTPFailure     = errors.New("apiclient: http request failed")
	ErrJSONLiteralNull = errors.New("apiclient: server returned us a literal null")
	ErrEmptyField      = errors.New("apiclient: empty field")
)

The following errors may be returned by this implementation in addition to the errors returned by APIs we call.

Functions

This section is empty.

Types

type CheckInRequest

type CheckInRequest struct {
	Charging        bool                           `json:"charging"`
	OnWiFi          bool                           `json:"on_wifi"`
	Platform        string                         `json:"platform"`
	ProbeASN        string                         `json:"probe_asn"`
	ProbeCC         string                         `json:"probe_cc"`
	RunType         string                         `json:"run_type"`
	SoftwareName    string                         `json:"software_name"`
	SoftwareVersion string                         `json:"software_version"`
	WebConnectivity *CheckInRequestWebConnectivity `json:"web_connectivity"`
}

CheckInRequest is the check-in API request

type CheckInRequestWebConnectivity

type CheckInRequestWebConnectivity struct {
	CategoryCodes []string `json:"category_codes"`
}

CheckInRequestWebConnectivity contains WebConnectivity specific parameters to include into CheckInRequest

type CheckInResponse

type CheckInResponse struct {
	WebConnectivity *CheckInResponseWebConnectivity `json:"web_connectivity"`
}

CheckInResponse is the check-in API response

type CheckInResponseURLInfo

type CheckInResponseURLInfo struct {
	CategoryCode string `json:"category_code"`
	CountryCode  string `json:"country_code"`
	URL          string `json:"url"`
}

CheckInResponseURLInfo contains information about an URL.

type CheckInResponseWebConnectivity

type CheckInResponseWebConnectivity struct {
	ReportID string                   `json:"report_id"`
	URLs     []CheckInResponseURLInfo `json:"urls"`
}

CheckInResponseWebConnectivity contains WebConnectivity specific information of a CheckInResponse

type CheckReportIDRequest

type CheckReportIDRequest struct {
	ReportID string `query:"report_id" required:"true"`
}

CheckReportIDRequest is the CheckReportID request.

type CheckReportIDResponse

type CheckReportIDResponse struct {
	Found bool `json:"found"`
}

CheckReportIDResponse is the CheckReportID response.

type Client

type Client struct {
	Accept        string
	Authorization string
	BaseURL       string
	HTTPClient    *http.Client
	UserAgent     string
}

Client is a client for the OONI API.

func (Client) GETCheckReportID

func (c Client) GETCheckReportID(ctx context.Context, in *CheckReportIDRequest) (*CheckReportIDResponse, error)

GETCheckReportID implements the GET /api/_/check_report_id API

func (Client) GETMeasurementMeta

func (c Client) GETMeasurementMeta(ctx context.Context, in *MeasurementMetaRequest) (*MeasurementMetaResponse, error)

GETMeasurementMeta implements the GET /api/v1/measurement_meta API

func (Client) GETPsiphonConfig

func (c Client) GETPsiphonConfig(ctx context.Context, in *PsiphonConfigRequest) (PsiphonConfigResponse, error)

GETPsiphonConfig implements the GET /api/v1/test-list/psiphon-config API

func (Client) GETTestHelpers

func (c Client) GETTestHelpers(ctx context.Context, in *TestHelpersRequest) (TestHelpersResponse, error)

GETTestHelpers implements the GET /api/v1/test-helpers API

func (Client) GETTorTargets

func (c Client) GETTorTargets(ctx context.Context, in *TorTargetsRequest) (TorTargetsResponse, error)

GETTorTargets implements the GET /api/v1/test-list/tor-targets API

func (Client) GETURLS

func (c Client) GETURLS(ctx context.Context, in *URLSRequest) (*URLSResponse, error)

GETURLS implements the GET /api/v1/test-list/urls API

func (Client) POSTCheckIn

func (c Client) POSTCheckIn(ctx context.Context, in *CheckInRequest) (*CheckInResponse, error)

POSTCheckIn implements the POST /api/v1/check-in API

func (Client) POSTLogin

func (c Client) POSTLogin(ctx context.Context, in *LoginRequest) (*LoginResponse, error)

POSTLogin implements the POST /api/v1/login API

func (Client) POSTOpenReport

func (c Client) POSTOpenReport(ctx context.Context, in *OpenReportRequest) (*OpenReportResponse, error)

POSTOpenReport implements the POST /report API

func (Client) POSTRegister

func (c Client) POSTRegister(ctx context.Context, in *RegisterRequest) (*RegisterResponse, error)

POSTRegister implements the POST /api/v1/register API

func (Client) POSTSubmitMeasurement

func (c Client) POSTSubmitMeasurement(ctx context.Context, in *SubmitMeasurementRequest) (*SubmitMeasurementResponse, error)

POSTSubmitMeasurement implements the POST /report/{{ .ReportID }} API

type LoginRequest

type LoginRequest struct {
	ClientID string `json:"username"`
	Password string `json:"password"`
}

LoginRequest is the login API request

type LoginResponse

type LoginResponse struct {
	Expire string `json:"expire"`
	Token  string `json:"token"`
}

LoginResponse is the login API response

type MeasurementMetaRequest

type MeasurementMetaRequest struct {
	ReportID string `query:"report_id" required:"true"`
	Full     bool   `query:"full"`
	Input    string `query:"input"`
}

MeasurementMetaRequest is the MeasurementMeta Request.

type MeasurementMetaResponse

type MeasurementMetaResponse struct {
	Anomaly              bool   `json:"anomaly"`
	CategoryCode         string `json:"category_code"`
	Confirmed            bool   `json:"confirmed"`
	Failure              bool   `json:"failure"`
	Input                string `json:"input"`
	MeasurementStartTime string `json:"measurement_start_time"`
	ProbeASN             int64  `json:"probe_asn"`
	ProbeCC              string `json:"probe_cc"`
	RawMeasurement       string `json:"raw_measurement"`
	ReportID             string `json:"report_id"`
	Scores               string `json:"scores"`
	TestName             string `json:"test_name"`
	TestStartTime        string `json:"test_start_time"`
}

MeasurementMetaResponse is the MeasurementMeta Response.

type OpenReportRequest

type OpenReportRequest struct {
	DataFormatVersion string `json:"data_format_version"`
	Format            string `json:"format"`
	ProbeASN          string `json:"probe_asn"`
	ProbeCC           string `json:"probe_cc"`
	SoftwareName      string `json:"software_name"`
	SoftwareVersion   string `json:"software_version"`
	TestName          string `json:"test_name"`
	TestStartTime     string `json:"test_start_time"`
	TestVersion       string `json:"test_version"`
}

OpenReportRequest is the OpenReport request.

type OpenReportResponse

type OpenReportResponse struct {
	ReportID         string   `json:"report_id"`
	SupportedFormats []string `json:"supported_formats"`
}

OpenReportResponse is the OpenReport response.

type PsiphonConfigRequest

type PsiphonConfigRequest struct{}

PsiphonConfigRequest is the request for the PsiphonConfig API

type PsiphonConfigResponse

type PsiphonConfigResponse map[string]interface{}

PsiphonConfigResponse is the response from the PsiphonConfig API

type RegisterRequest

type RegisterRequest struct {
	AvailableBandwidth string   `json:"available_bandwidth,omitempty"`
	DeviceToken        string   `json:"device_token,omitempty"`
	Language           string   `json:"language,omitempty"`
	NetworkType        string   `json:"network_type,omitempty"`
	Platform           string   `json:"platform"`
	ProbeASN           string   `json:"probe_asn"`
	ProbeCC            string   `json:"probe_cc"`
	ProbeFamily        string   `json:"probe_family,omitempty"`
	ProbeTimezone      string   `json:"probe_timezone,omitempty"`
	SoftwareName       string   `json:"software_name"`
	SoftwareVersion    string   `json:"software_version"`
	SupportedTests     []string `json:"supported_tests"`
}

RegisterRequest is the request for the Register API.

type RegisterResponse

type RegisterResponse struct {
	ClientID string `json:"client_id"`
}

RegisterResponse is the response from the Register API.

type SubmitMeasurementRequest

type SubmitMeasurementRequest struct {
	ReportID string      `path:"report_id"`
	Format   string      `json:"format"`
	Content  interface{} `json:"content"`
}

SubmitMeasurementRequest is the SubmitMeasurement request.

type SubmitMeasurementResponse

type SubmitMeasurementResponse struct{}

SubmitMeasurementResponse is the SubmitMeasurement response.

type TestHelpersHelperInfo

type TestHelpersHelperInfo struct {
	Address string `json:"address"`
	Type    string `json:"type"`
	Front   string `json:"front,omitempty"`
}

TestHelpersHelperInfo is a single helper within the response returned by the TestHelpers API.

type TestHelpersRequest

type TestHelpersRequest struct{}

TestHelpersRequest is the TestHelpers request.

type TestHelpersResponse

type TestHelpersResponse map[string][]TestHelpersHelperInfo

TestHelpersResponse is the TestHelpers response.

type TorTargetsRequest

type TorTargetsRequest struct{}

TorTargetsRequest is a request for the TorTargets API.

type TorTargetsResponse

type TorTargetsResponse map[string]TorTargetsTarget

TorTargetsResponse is the response from the TorTargets API.

type TorTargetsTarget

type TorTargetsTarget struct {
	Address  string              `json:"address"`
	Name     string              `json:"name"`
	Params   map[string][]string `json:"params"`
	Protocol string              `json:"protocol"`
	Source   string              `json:"source"`
}

TorTargetsTarget is a target for the tor experiment.

type URLSRequest

type URLSRequest struct {
	CategoryCodes string `query:"category_codes"`
	CountryCode   string `query:"country_code"`
	Limit         int64  `query:"limit"`
}

URLSRequest is the URLS request.

type URLSResponse

type URLSResponse struct {
	Results []URLSResponseURL `json:"results"`
}

URLSResponse is the URLS response.

type URLSResponseURL

type URLSResponseURL struct {
	CategoryCode string `json:"category_code"`
	CountryCode  string `json:"country_code"`
	URL          string `json:"url"`
}

URLSResponseURL is a single URL in the URLS response.

Directories

Path Synopsis
internal
apimodel
Package apimodel describes all the implemented APIs.
Package apimodel describes all the implemented APIs.
datamodel
Package datamodel describes the data types used by OONI's API.
Package datamodel describes the data types used by OONI's API.
diffmodel command
Command diffmodel compares our model and the server model.
Command diffmodel compares our model and the server model.
fatalx
Package fatalx simplifies checking for errors.
Package fatalx simplifies checking for errors.
fmtx
Package fmtx extends the fmt package
Package fmtx extends the fmt package
genapi command
This script generates api.go
This script generates api.go
gendatamodel command
This script generates datamodel.go
This script generates datamodel.go
gennewrequest command
This script generates newrequest.go
This script generates newrequest.go
gennewresponse command
This script generates newresponse.go.
This script generates newresponse.go.
genswagger command
This script generates swagger.json
This script generates swagger.json
openapi
Package openapi contains the swagger 2.0 data model
Package openapi contains the swagger 2.0 data model
osx
Package osx extends the os package.
Package osx extends the os package.
reflectx
Package reflectx extends the reflect package.
Package reflectx extends the reflect package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL