Skip to content

Commit

Permalink
Add CMX Update Network outbound behind feature flag (#506)
Browse files Browse the repository at this point in the history
* add feature flag
  • Loading branch information
jdewinne authored Feb 1, 2025
1 parent 6b23806 commit ea83702
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cli/cmd/network_update_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func (r *runners) updateNetworkOutbound(cmd *cobra.Command, args []string) error
network, err := r.kotsAPI.UpdateNetworkOutbound(r.args.updateNetworkID, opts)
if errors.Cause(err) == platformclient.ErrForbidden {
return ErrCompatibilityMatrixTermsNotAccepted
} else if err != nil {
}
if err != nil {
return errors.Wrap(err, "update network outbound")
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/kotsclient/network_update_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package kotsclient

import (
"context"
"encoding/json"
"fmt"
"net/http"

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/pkg/platformclient"
"github.com/replicatedhq/replicated/pkg/types"
)

Expand All @@ -21,6 +24,12 @@ type UpdateNetworkOutboundOpts struct {
Outbound string
}

type UpdateNetworkOutboundErrorResponse struct {
Error struct {
Message string `json:"message"`
}
}

func (c *VendorV3Client) UpdateNetworkOutbound(networkID string, opts UpdateNetworkOutboundOpts) (*types.Network, error) {
req := UpdateNetworkOutboundRequest{
Outbound: opts.Outbound,
Expand All @@ -34,6 +43,17 @@ func (c *VendorV3Client) doUpdateNetworkOutboundRequest(networkID string, req Up
endpoint := fmt.Sprintf("/v3/network/%s/outbound", networkID)
err := c.DoJSON(context.TODO(), "PUT", endpoint, http.StatusOK, req, &resp)
if err != nil {
// if err is APIError and the status code is 400, then we have a validation error
// and we can return the validation error
if apiErr, ok := errors.Cause(err).(platformclient.APIError); ok {
if apiErr.StatusCode == http.StatusBadRequest {
errResp := &UpdateNetworkOutboundErrorResponse{}
if jsonErr := json.Unmarshal(apiErr.Body, errResp); jsonErr != nil {
return nil, fmt.Errorf("unmarshal error response: %w", err)
}
return nil, errors.New(errResp.Error.Message)
}
}
return nil, err
}

Expand Down

0 comments on commit ea83702

Please sign in to comment.