Skip to content

Commit 520671e

Browse files
authored
Add support for projects in nexus endpoint commands (#98)
1 parent b5a7bd2 commit 520671e

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎temporalcloudcli/commands.gen.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4625,6 +4625,7 @@ type CloudNexusEndpointCreateCommand struct {
46254625
ClientOptions
46264626
AsyncOperationOptions
46274627
Name string
4628+
ProjectId string
46284629
TargetNamespace string
46294630
TargetTaskQueue string
46304631
AllowNamespace []string
@@ -4646,6 +4647,7 @@ func NewCloudNexusEndpointCreateCommand(cctx *CommandContext, parent *CloudNexus
46464647
s.Command.Args = cobra.NoArgs
46474648
s.Command.Flags().StringVar(&s.Name, "name", "", "The name of the Nexus Endpoint to create. Required.")
46484649
_ = cobra.MarkFlagRequired(s.Command.Flags(), "name")
4650+
s.Command.Flags().StringVar(&s.ProjectId, "project-id", "", "The ID of the project to create the Nexus Endpoint in.")
46494651
s.Command.Flags().StringVar(&s.TargetNamespace, "target-namespace", "", "The namespace in which a handler worker will be polling for Nexus tasks. Required.")
46504652
_ = cobra.MarkFlagRequired(s.Command.Flags(), "target-namespace")
46514653
s.Command.Flags().StringVar(&s.TargetTaskQueue, "target-task-queue", "", "The task queue on which a handler worker will be polling for Nexus tasks. Required.")
@@ -4733,6 +4735,7 @@ type CloudNexusEndpointListCommand struct {
47334735
Parent *CloudNexusEndpointCommand
47344736
Command cobra.Command
47354737
ClientOptions
4738+
ProjectId string
47364739
PageSize int
47374740
PageToken string
47384741
}
@@ -4745,6 +4748,7 @@ func NewCloudNexusEndpointListCommand(cctx *CommandContext, parent *CloudNexusEn
47454748
s.Command.Short = "List Nexus Endpoints"
47464749
s.Command.Long = "List Nexus Endpoint configurations on the Cloud Account."
47474750
s.Command.Args = cobra.NoArgs
4751+
s.Command.Flags().StringVar(&s.ProjectId, "project-id", "", "Filter Nexus Endpoints by project ID.")
47484752
s.Command.Flags().IntVar(&s.PageSize, "page-size", 0, "Number of endpoints to return per page. If no page size is provided, it will default to 100. A maximum of 1000 endpoints can be fetched at a time.")
47494753
s.Command.Flags().StringVar(&s.PageToken, "page-token", "", "Token for retrieving the next page of results. Initial value is empty string.")
47504754
s.ClientOptions.BuildFlags(s.Command.Flags())

‎temporalcloudcli/commands.nexus.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (c *CloudNexusEndpointListCommand) run(cctx *CommandContext, _ []string) er
5252
res, err := client.GetNexusEndpoints(cctx, &cloudservice.GetNexusEndpointsRequest{
5353
PageSize: int32(c.PageSize),
5454
PageToken: c.PageToken,
55+
ProjectId: c.ProjectId,
5556
})
5657
if err != nil {
5758
return err
@@ -66,7 +67,7 @@ func (c *CloudNexusEndpointListCommand) run(cctx *CommandContext, _ []string) er
6667
NextPageToken: res.NextPageToken,
6768
},
6869
printer.PrintResourceOptions{
69-
Fields: []string{"Id", "State"},
70+
Fields: []string{"Id", "ProjectId", "State"},
7071
SpecFields: []string{"Name", "Description"},
7172
},
7273
printer.TableOptions{},
@@ -132,6 +133,7 @@ func (c *CloudNexusEndpointCreateCommand) run(cctx *CommandContext, _ []string)
132133
PolicySpecs: policySpecs,
133134
},
134135
AsyncOperationId: c.AsyncOperationId,
136+
ProjectId: c.ProjectId,
135137
})
136138
return cctx.GetPoller(client, c.AsyncOperationOptions).HandleCreateAsyncOperationResponse(cctx, resp, err)
137139
}

‎temporalcloudcli/commands.nexus_test.go‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,27 @@ func TestListNexusEndpoints(t *testing.T) {
180180
NextPageToken: "tok-def",
181181
},
182182
},
183+
{
184+
name: "WithProjectID",
185+
cmd: temporalcloudcli.CloudNexusEndpointListCommand{
186+
ProjectId: "project-123",
187+
},
188+
cloudClientExpectations: func(c *cloudmock.MockCloudServiceClient) {
189+
c.EXPECT().
190+
GetNexusEndpoints(mock.Anything, &cloudservice.GetNexusEndpointsRequest{
191+
ProjectId: "project-123",
192+
}, mock.Anything).
193+
Return(&cloudservice.GetNexusEndpointsResponse{
194+
Endpoints: []*nexusv1.Endpoint{testEndpoint},
195+
}, nil)
196+
},
197+
expectedJsonOutput: struct {
198+
Endpoints []*nexusv1.Endpoint
199+
NextPageToken string
200+
}{
201+
Endpoints: []*nexusv1.Endpoint{testEndpoint},
202+
},
203+
},
183204
{
184205
name: "APIError",
185206
cmd: temporalcloudcli.CloudNexusEndpointListCommand{},
@@ -219,6 +240,7 @@ func TestCreateNexusEndpoint(t *testing.T) {
219240
name: "Success",
220241
cmd: temporalcloudcli.CloudNexusEndpointCreateCommand{
221242
Name: "my-endpoint",
243+
ProjectId: "project-123",
222244
TargetNamespace: "ns-123",
223245
TargetTaskQueue: "my-tq",
224246
AllowNamespace: []string{"caller-ns"},
@@ -230,7 +252,8 @@ func TestCreateNexusEndpoint(t *testing.T) {
230252
req.Spec.TargetSpec.GetWorkerTargetSpec().NamespaceId == "ns-123" &&
231253
req.Spec.TargetSpec.GetWorkerTargetSpec().TaskQueue == "my-tq" &&
232254
len(req.Spec.PolicySpecs) == 1 &&
233-
req.Spec.PolicySpecs[0].GetAllowedCloudNamespacePolicySpec().NamespaceId == "caller-ns"
255+
req.Spec.PolicySpecs[0].GetAllowedCloudNamespacePolicySpec().NamespaceId == "caller-ns" &&
256+
req.ProjectId == "project-123"
234257
}), mock.Anything).
235258
Return(&cloudservice.CreateNexusEndpointResponse{
236259
EndpointId: "ep-new",
@@ -500,7 +523,6 @@ func TestUpdateNexusEndpoint(t *testing.T) {
500523
Endpoints: []*nexusv1.Endpoint{existingEndpoint},
501524
}, nil)
502525
}
503-
504526
tests := []struct {
505527
name string
506528
setupCmd func(*temporalcloudcli.CloudNexusEndpointUpdateCommand)

‎temporalcloudcli/commands.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,10 @@ commands:
18681868
option-sets:
18691869
- client
18701870
options:
1871+
- name: project-id
1872+
type: string
1873+
description: |
1874+
Filter Nexus Endpoints by project ID.
18711875
- name: page-size
18721876
type: int
18731877
description: |
@@ -1918,6 +1922,10 @@ commands:
19181922
required: true
19191923
description: |
19201924
The name of the Nexus Endpoint to create.
1925+
- name: project-id
1926+
type: string
1927+
description: |
1928+
The ID of the project to create the Nexus Endpoint in.
19211929
- name: target-namespace
19221930
type: string
19231931
required: true

0 commit comments

Comments
 (0)