package migrationAPI import ( "context" "encoding/json" "fmt" "io" "net/http" "github.com/pkg/errors" ) // PostFinalizeResp type is the custom response received from // the post_finalize migration api call. type PostFinalizeResp struct { Data PostFinalizeData `json:"data"` Error *string `json:"error"` } // PostFinalizeData is the data response payload type PostFinalizeData struct { Changes []string `json:"changes"` Errors []string `json:"errors"` } // PostFinalize call will run additional port prep actions after the initial // DCX finalize has been completed func (c *Client) PostFinalize(moveGroup, device string) (PostFinalizeResp, error) { var resp PostFinalizeResp uri := fmt.Sprintf("/post_finalize/%s/device/%s", moveGroup, device) req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, c.URL+uri, nil) if err != nil { return resp, err } req.Header.Set("X-Auth-Token", c.Token) res, err := http.DefaultClient.Do(req) if res != nil { defer func() { if defErr := res.Body.Close(); defErr != nil { err = errors.Wrap(err, defErr.Error()) } }() } if err != nil { return resp, err } if res.StatusCode > http.StatusNoContent { return resp, err } if err := json.NewDecoder(res.Body).Decode(&resp); err != nil { if !errors.Is(err, io.EOF) { return resp, err } } if resp.Error != nil { return resp, errors.New(*resp.Error) } return resp, nil }