Skip to content

Commit

Permalink
Add Update to Gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Gealer committed Oct 15, 2022
1 parent 46baa33 commit dcc5494
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 2 deletions.
18 changes: 18 additions & 0 deletions ignite.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ func (c ClientCategoryIgniteGateways) Delete(ctx context.Context, id string, opt
}, opts)
}

// Update is used to update a gateway by its ID.
func (c ClientCategoryIgniteGateways) Update(
ctx context.Context, id string, updateOpts types.IgniteGatewayUpdateOpts, opts ...ClientOption,
) (*types.Gateway, error) {
var gw types.Gateway
err := c.c.do(ctx, clientArgs{
method: "PATCH",
path: "/ignite/gateways/" + url.PathEscape(id),
resultKey: "gateway",
body: updateOpts,
result: &gw,
}, opts)
if err != nil {
return nil, err
}
return &gw, nil
}

// Create is used to create a deployment.
func (c ClientCategoryIgniteDeployments) Create(
ctx context.Context, deployment *types.DeploymentConfig, opts ...ClientOption,
Expand Down
17 changes: 17 additions & 0 deletions ignite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ func TestClient_Ignite_Gateways_Delete(t *testing.T) {
nil)
}

func TestClient_Ignite_Gateways_Update(t *testing.T) {
c := &mockClientDoer{
t: t,
wantMethod: "PATCH",
wantPath: "/ignite/gateways/test%20test",
wantResultKey: "gateway",
wantIgnore404: false,
wantBody: types.IgniteGatewayUpdateOpts{Name: "new name"},
tokenType: "pat",
}
testApiSingleton(c,
&ClientCategoryIgniteGateways{c: c},
"Update",
[]any{"test test", types.IgniteGatewayUpdateOpts{Name: "new name"}},
&types.Gateway{ID: "hello"})
}

func TestClient_Ignite_Deployments_Create(t *testing.T) {
deploymentConfig := &types.DeploymentConfig{
DeploymentConfigPartial: types.DeploymentConfigPartial{
Expand Down
2 changes: 1 addition & 1 deletion types/generate_stringer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions types/ignite.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,15 @@ const (
// RolloutStateFailed is used to define a rollout that has failed.
RolloutStateFailed RolloutState = "failed"
)

// IgniteGatewayUpdateOpts is used to define the options for updating a gateway.
type IgniteGatewayUpdateOpts struct {
// Name is the name of the gateway. If this is not blank, it will be updated.
Name string `json:"name,omitempty"`

// TargetPort is the port to listen on. If this is not 0, it will be updated.
TargetPort int `json:"target_port,omitempty"`

// Protocol is the protocol to use for the gateway. If this is not blank, it will be updated.
Protocol GatewayProtocol `json:"protocol,omitempty"`
}
5 changes: 5 additions & 0 deletions types/stringer_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions types/testdata/types.IgniteGatewayUpdateOpts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "abc",
"target_port": 1,
"protocol": "def"
}
1 change: 1 addition & 0 deletions types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var types = []reflect.Type{
reflect.TypeOf(BuildMetadata{}),
reflect.TypeOf(BuildMethod("")),
reflect.TypeOf(BuildState("")),
reflect.TypeOf(IgniteGatewayUpdateOpts{}),

// pipe.go
reflect.TypeOf(IngestProtocol("")),
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hop

// Version is used to define a tagged version. This will be updated when a new version is released.
const Version = "1.6.0"
const Version = "1.7.0"

0 comments on commit dcc5494

Please sign in to comment.