/
checkin.go
33 lines (28 loc) · 1.06 KB
/
checkin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package probeservices
import (
"context"
"github.com/ooni/probe-engine/pkg/checkincache"
"github.com/ooni/probe-engine/pkg/httpapi"
"github.com/ooni/probe-engine/pkg/model"
"github.com/ooni/probe-engine/pkg/ooapi"
)
// CheckIn function is called by probes asking if there are tests to be run
// The config argument contains the mandatory settings.
// This function will additionally update the [checkincache] such that we
// track selected parts of the check-in API response.
// Returns the list of tests to run and the URLs, on success,
// or an explanatory error, in case of failure.
func (c Client) CheckIn(
ctx context.Context, config model.OOAPICheckInConfig) (*model.OOAPICheckInResult, error) {
// prepare endpoint and descriptor for the API call
epnt := c.newHTTPAPIEndpoint()
desc := ooapi.NewDescriptorCheckIn(&config)
// issue the API call and handle failures
resp, err := httpapi.Call(ctx, desc, epnt)
if err != nil {
return nil, err
}
// make sure we track selected parts of the response
_ = checkincache.Store(c.KVStore, resp)
return resp, nil
}