@@ -26,6 +26,11 @@ type v1Assignment struct {
2626 Unsynced bool `json:"unsynced"`
2727}
2828
29+ // v2AssignmentOverrideRequestBody is the JSON input for the V2 assignment override endpoint
30+ type v2AssignmentOverrideRequestBody struct {
31+ Assignments []v1Assignment `json:"assignments"`
32+ }
33+
2934// v1VisitorConfig is the JSON output type for V1 visitor_config endpoints
3035type v1VisitorConfig struct {
3136 Splits map [string ]* splits.Weights `json:"splits"`
@@ -112,6 +117,10 @@ func (s *server) routes() {
112117 "/api/v1/assignment_override" ,
113118 postV1AssignmentOverride ,
114119 )
120+ s .handlePostReturnNoContent (
121+ "/api/v2/visitors/{v}/assignment_overrides" ,
122+ postV2AssignmentOverride ,
123+ )
115124 s .handleGet (
116125 "/api/v1/apps/{a}/versions/{v}/builds/{b}/visitors/{id}/config" ,
117126 getV1AppVisitorConfig ,
@@ -257,6 +266,35 @@ func postV1AssignmentOverride(r *http.Request) error {
257266 return nil
258267}
259268
269+ func postV2AssignmentOverride (r * http.Request ) error {
270+ var assignments []v1Assignment
271+ contentType := r .Header .Get ("content-type" )
272+ switch {
273+ case strings .HasPrefix (contentType , "application/json" ):
274+ requestBytes , err := ioutil .ReadAll (r .Body )
275+ if err != nil {
276+ return err
277+ }
278+ var assignmentBody v2AssignmentOverrideRequestBody
279+ err = json .Unmarshal (requestBytes , & assignmentBody )
280+ if err != nil {
281+ return err
282+ }
283+ assignments = assignmentBody .Assignments
284+ default :
285+ return fmt .Errorf ("got unexpected content type %s" , contentType )
286+ }
287+ storedAssignments , err := fakeassignments .Read ()
288+ for _ , assignment := range assignments {
289+ (* storedAssignments )[assignment .SplitName ] = assignment .Variant
290+ }
291+ err = fakeassignments .Write (storedAssignments )
292+ if err != nil {
293+ return err
294+ }
295+ return nil
296+ }
297+
260298func getV1AppVisitorConfig () (interface {}, error ) {
261299 isplitRegistry , err := getV1SplitRegistry ()
262300 splitRegistry := isplitRegistry .(map [string ]* splits.Weights )
0 commit comments