Skip to content

Commit cd74bd4

Browse files
committed
Merge branch 'v3' into key-via-file-path
2 parents 371c72b + 0f0c0e2 commit cd74bd4

32 files changed

+3335
-606
lines changed

api/grpc/mpi/v1/command.pb.go

Lines changed: 477 additions & 266 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/command.pb.validate.go

Lines changed: 462 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/command.proto

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,11 @@ message APIActionRequest {
204204
message NGINXPlusAction {
205205
// types of actions possible with NGINX Plus API
206206
oneof action {
207-
UpdateHTTPUpstreamServers update_http_upstream_servers = 2;
208-
GetHTTPUpstreamServers get_http_upstream_servers = 3;
207+
UpdateHTTPUpstreamServers update_http_upstream_servers = 1;
208+
GetHTTPUpstreamServers get_http_upstream_servers = 2;
209+
UpdateStreamServers update_stream_servers = 3;
210+
GetUpstreams get_upstreams = 4;
211+
GetStreamUpstreams get_stream_upstreams = 5;
209212
}
210213
}
211214

@@ -223,6 +226,22 @@ message GetHTTPUpstreamServers {
223226
string http_upstream_name = 1;
224227
}
225228

229+
// Update Upstream Stream Servers for an instance
230+
message UpdateStreamServers {
231+
// the name of the upstream stream
232+
string upstream_stream_name = 1;
233+
// a list of upstream stream servers
234+
repeated google.protobuf.Struct servers = 2;
235+
}
236+
237+
// Get Upstreams for an instance
238+
message GetUpstreams {
239+
}
240+
241+
// Get Stream Upstream Servers for an instance
242+
message GetStreamUpstreams {
243+
}
244+
226245
// Request an update on a particular command
227246
message CommandStatusRequest {}
228247

api/grpc/mpi/v1/files.pb.go

Lines changed: 188 additions & 178 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/files.pb.validate.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/files.proto

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ message File {
9292
}
9393
// Optional action
9494
optional FileAction action = 2;
95+
// Unmanaged files will not be modified
96+
bool unmanaged = 3;
9597
}
9698

9799
// Represents the get file request
@@ -290,4 +292,4 @@ message AttributeTypeAndValue {
290292

291293
// The value associated with the attribute.
292294
string value = 2 [(buf.validate.field).string.min_len = 1];
293-
}
295+
}

api/grpc/mpi/v1/helpers.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) F5, Inc.
2+
//
3+
// This source code is licensed under the Apache License, Version 2.0 license found in the
4+
// LICENSE file in the root directory of this source tree.
5+
6+
package v1
7+
8+
import (
9+
"google.golang.org/protobuf/types/known/structpb"
10+
)
11+
12+
// ConvertToStructs converts a map[string]any into a slice of *structpb.Struct.
13+
// Each key-value pair in the input map is converted into a *structpb.Struct,
14+
// where the key is used as the field name, and the value is added to the Struct.
15+
//
16+
// Parameters:
17+
// - input: A map[string]any containing key-value pairs to be converted.
18+
//
19+
// Returns:
20+
// - []*structpb.Struct: A slice of *structpb.Struct, where each map entry is converted into a struct.
21+
// - error: An error if any value in the input map cannot be converted into a *structpb.Struct.
22+
//
23+
// Example:
24+
//
25+
// input := map[string]any{
26+
// "key1": "value1",
27+
// "key2": 123,
28+
// "key3": true,
29+
// }
30+
// structs, err := ConvertToStructs(input)
31+
// // structs will contain a slice of *structpb.Struct
32+
// // err will be nil if all conversions succeed.
33+
func ConvertToStructs(input map[string]any) ([]*structpb.Struct, error) {
34+
structs := []*structpb.Struct{}
35+
for key, value := range input {
36+
// Convert each value in the map to *structpb.Struct
37+
structValue, err := structpb.NewStruct(map[string]any{
38+
key: value,
39+
})
40+
if err != nil {
41+
return structs, err
42+
}
43+
structs = append(structs, structValue)
44+
}
45+
46+
return structs, nil
47+
}

api/grpc/mpi/v1/helpers_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright (c) F5, Inc.
2+
//
3+
// This source code is licensed under the Apache License, Version 2.0 license found in the
4+
// LICENSE file in the root directory of this source tree.
5+
6+
package v1
7+
8+
import (
9+
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
"google.golang.org/protobuf/types/known/structpb"
13+
)
14+
15+
func TestConvertToStructs(t *testing.T) {
16+
tests := []struct {
17+
name string
18+
input map[string]any
19+
expected []*structpb.Struct
20+
wantErr bool
21+
}{
22+
{
23+
name: "Test 1: Valid input with simple key-value pairs",
24+
input: map[string]any{
25+
"key1": "value1",
26+
"key2": 123,
27+
"key3": true,
28+
},
29+
expected: []*structpb.Struct{
30+
{
31+
Fields: map[string]*structpb.Value{
32+
"key1": structpb.NewStringValue("value1"),
33+
},
34+
},
35+
{
36+
Fields: map[string]*structpb.Value{
37+
"key2": structpb.NewNumberValue(123),
38+
},
39+
},
40+
{
41+
Fields: map[string]*structpb.Value{
42+
"key3": structpb.NewBoolValue(true),
43+
},
44+
},
45+
},
46+
wantErr: false,
47+
},
48+
{
49+
name: "Test 2: Empty input map",
50+
input: make(map[string]any),
51+
expected: []*structpb.Struct{},
52+
wantErr: false,
53+
},
54+
{
55+
name: "Test 3: Invalid input type",
56+
input: map[string]any{
57+
"key1": func() {}, // Unsupported type
58+
},
59+
expected: []*structpb.Struct{},
60+
wantErr: true,
61+
},
62+
}
63+
64+
for _, tt := range tests {
65+
t.Run(tt.name, func(t *testing.T) {
66+
got, err := ConvertToStructs(tt.input)
67+
68+
assert.Equal(t, tt.expected, got)
69+
assert.Equal(t, tt.wantErr, err != nil)
70+
})
71+
}
72+
}

docs/proto/protos.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
- [DataPlaneResponse](#mpi-v1-DataPlaneResponse)
5353
- [FileServer](#mpi-v1-FileServer)
5454
- [GetHTTPUpstreamServers](#mpi-v1-GetHTTPUpstreamServers)
55+
- [GetStreamUpstreams](#mpi-v1-GetStreamUpstreams)
56+
- [GetUpstreams](#mpi-v1-GetUpstreams)
5557
- [HealthRequest](#mpi-v1-HealthRequest)
5658
- [HostInfo](#mpi-v1-HostInfo)
5759
- [Instance](#mpi-v1-Instance)
@@ -74,6 +76,7 @@
7476
- [UpdateDataPlaneStatusRequest](#mpi-v1-UpdateDataPlaneStatusRequest)
7577
- [UpdateDataPlaneStatusResponse](#mpi-v1-UpdateDataPlaneStatusResponse)
7678
- [UpdateHTTPUpstreamServers](#mpi-v1-UpdateHTTPUpstreamServers)
79+
- [UpdateStreamServers](#mpi-v1-UpdateStreamServers)
7780

7881
- [InstanceHealth.InstanceHealthStatus](#mpi-v1-InstanceHealth-InstanceHealthStatus)
7982
- [InstanceMeta.InstanceType](#mpi-v1-InstanceMeta-InstanceType)
@@ -298,6 +301,7 @@ Represents meta data about a file
298301
| ----- | ---- | ----- | ----------- |
299302
| file_meta | [FileMeta](#mpi-v1-FileMeta) | | Meta information about the file, the name (including path) and hash |
300303
| action | [File.FileAction](#mpi-v1-File-FileAction) | optional | Optional action |
304+
| unmanaged | [bool](#bool) | | Unmanaged files will not be modified |
301305

302306

303307

@@ -797,6 +801,26 @@ Get HTTP Upstream Servers for an instance
797801

798802

799803

804+
<a name="mpi-v1-GetStreamUpstreams"></a>
805+
806+
### GetStreamUpstreams
807+
Get Stream Upstream Servers for an instance
808+
809+
810+
811+
812+
813+
814+
<a name="mpi-v1-GetUpstreams"></a>
815+
816+
### GetUpstreams
817+
Get Upstreams for an instance
818+
819+
820+
821+
822+
823+
800824
<a name="mpi-v1-HealthRequest"></a>
801825

802826
### HealthRequest
@@ -977,6 +1001,9 @@ Perform an action using the NGINX Plus API on an instance
9771001
| ----- | ---- | ----- | ----------- |
9781002
| update_http_upstream_servers | [UpdateHTTPUpstreamServers](#mpi-v1-UpdateHTTPUpstreamServers) | | |
9791003
| get_http_upstream_servers | [GetHTTPUpstreamServers](#mpi-v1-GetHTTPUpstreamServers) | | |
1004+
| update_stream_servers | [UpdateStreamServers](#mpi-v1-UpdateStreamServers) | | |
1005+
| get_upstreams | [GetUpstreams](#mpi-v1-GetUpstreams) | | |
1006+
| get_stream_upstreams | [GetStreamUpstreams](#mpi-v1-GetStreamUpstreams) | | |
9801007

9811008

9821009

@@ -1136,6 +1163,22 @@ Update HTTP Upstream Servers for an instance
11361163

11371164

11381165

1166+
1167+
<a name="mpi-v1-UpdateStreamServers"></a>
1168+
1169+
### UpdateStreamServers
1170+
Update Upstream Stream Servers for an instance
1171+
1172+
1173+
| Field | Type | Label | Description |
1174+
| ----- | ---- | ----- | ----------- |
1175+
| upstream_stream_name | [string](#string) | | the name of the upstream stream |
1176+
| servers | [google.protobuf.Struct](#google-protobuf-Struct) | repeated | a list of upstream stream servers |
1177+
1178+
1179+
1180+
1181+
11391182

11401183

11411184

0 commit comments

Comments
 (0)