add endpoint in devices API to query for api features (#6152)

Related to #6063, this adds a new device API to get an object with boolean values that we can use as feature flags to manage backwards compatibility in Fleet Desktop.
This commit is contained in:
Roberto Dip 2022-06-09 10:17:55 -03:00 committed by GitHub
parent 9965da174c
commit a6cf9b3d8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 0 deletions

View file

@ -435,3 +435,8 @@ type KafkaRESTConfig struct {
ResultTopic string `json:"result_topic"`
ProxyHost string `json:"proxyhost"`
}
// DeviceAPIFeatures specifies a list of features supported
// by the current API version. Each field in the struct is
// meant to be a boolean value.
type DeviceAPIFeatures struct{}

View file

@ -214,3 +214,26 @@ func (svc *Service) ListDevicePolicies(ctx context.Context, host *fleet.Host) ([
return nil, fleet.ErrMissingLicense
}
////////////////////////////////////////////////////////////////////////////////
// Device API features
////////////////////////////////////////////////////////////////////////////////
type deviceAPIFeaturesRequest struct {
Token string `url:"token"`
}
func (r *deviceAPIFeaturesRequest) deviceAuthToken() string {
return r.Token
}
type deviceAPIFeaturesResponse struct {
Err error `json:"error,omitempty"`
Features fleet.DeviceAPIFeatures
}
func (r deviceAPIFeaturesResponse) error() error { return r.Err }
func deviceAPIFeaturesEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (interface{}, error) {
return deviceAPIFeaturesResponse{Features: fleet.DeviceAPIFeatures{}}, nil
}

View file

@ -396,6 +396,7 @@ func attachFleetAPIRoutes(r *mux.Router, svc fleet.Service, config config.FleetC
de.GET("/api/_version_/fleet/device/{token}/device_mapping", listDeviceHostDeviceMappingEndpoint, listDeviceHostDeviceMappingRequest{})
de.GET("/api/_version_/fleet/device/{token}/macadmins", getDeviceMacadminsDataEndpoint, getDeviceMacadminsDataRequest{})
de.GET("/api/_version_/fleet/device/{token}/policies", listDevicePoliciesEndpoint, listDevicePoliciesRequest{})
de.GET("/api/_version_/fleet/device/{token}/api_features", deviceAPIFeaturesEndpoint, deviceAPIFeaturesRequest{})
// host-authenticated endpoints
he := newHostAuthenticatedEndpointer(svc, logger, opts, r, apiVersions...)

View file

@ -4624,6 +4624,14 @@ func (s *integrationTestSuite) TestDeviceAuthenticatedEndpoints() {
json.NewDecoder(res.Body).Decode(&getHostResp)
res.Body.Close()
require.Nil(t, listPoliciesResp.Policies)
// get list of api features
apiFeaturesResp := deviceAPIFeaturesResponse{}
res = s.DoRawNoAuth("GET", "/api/latest/fleet/device/"+token+"/api_features", nil, http.StatusOK)
json.NewDecoder(res.Body).Decode(&apiFeaturesResp)
res.Body.Close()
require.Nil(t, apiFeaturesResp.Err)
require.NotNil(t, apiFeaturesResp.Features)
}
func (s *integrationTestSuite) TestModifyUser() {