Skip to content

Commit

Permalink
Merge branch 'v3' into key-via-file-path
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-breen committed Jan 20, 2025
2 parents 371c72b + 0f0c0e2 commit cd74bd4
Show file tree
Hide file tree
Showing 32 changed files with 3,335 additions and 606 deletions.
743 changes: 477 additions & 266 deletions api/grpc/mpi/v1/command.pb.go

Large diffs are not rendered by default.

462 changes: 462 additions & 0 deletions api/grpc/mpi/v1/command.pb.validate.go

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions api/grpc/mpi/v1/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,11 @@ message APIActionRequest {
message NGINXPlusAction {
// types of actions possible with NGINX Plus API
oneof action {
UpdateHTTPUpstreamServers update_http_upstream_servers = 2;
GetHTTPUpstreamServers get_http_upstream_servers = 3;
UpdateHTTPUpstreamServers update_http_upstream_servers = 1;
GetHTTPUpstreamServers get_http_upstream_servers = 2;
UpdateStreamServers update_stream_servers = 3;
GetUpstreams get_upstreams = 4;
GetStreamUpstreams get_stream_upstreams = 5;
}
}

Expand All @@ -223,6 +226,22 @@ message GetHTTPUpstreamServers {
string http_upstream_name = 1;
}

// Update Upstream Stream Servers for an instance
message UpdateStreamServers {
// the name of the upstream stream
string upstream_stream_name = 1;
// a list of upstream stream servers
repeated google.protobuf.Struct servers = 2;
}

// Get Upstreams for an instance
message GetUpstreams {
}

// Get Stream Upstream Servers for an instance
message GetStreamUpstreams {
}

// Request an update on a particular command
message CommandStatusRequest {}

Expand Down
366 changes: 188 additions & 178 deletions api/grpc/mpi/v1/files.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/grpc/mpi/v1/files.pb.validate.go

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

4 changes: 3 additions & 1 deletion api/grpc/mpi/v1/files.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ message File {
}
// Optional action
optional FileAction action = 2;
// Unmanaged files will not be modified
bool unmanaged = 3;
}

// Represents the get file request
Expand Down Expand Up @@ -290,4 +292,4 @@ message AttributeTypeAndValue {

// The value associated with the attribute.
string value = 2 [(buf.validate.field).string.min_len = 1];
}
}
47 changes: 47 additions & 0 deletions api/grpc/mpi/v1/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) F5, Inc.
//
// This source code is licensed under the Apache License, Version 2.0 license found in the
// LICENSE file in the root directory of this source tree.

package v1

import (
"google.golang.org/protobuf/types/known/structpb"
)

// ConvertToStructs converts a map[string]any into a slice of *structpb.Struct.
// Each key-value pair in the input map is converted into a *structpb.Struct,
// where the key is used as the field name, and the value is added to the Struct.
//
// Parameters:
// - input: A map[string]any containing key-value pairs to be converted.
//
// Returns:
// - []*structpb.Struct: A slice of *structpb.Struct, where each map entry is converted into a struct.
// - error: An error if any value in the input map cannot be converted into a *structpb.Struct.
//
// Example:
//
// input := map[string]any{
// "key1": "value1",
// "key2": 123,
// "key3": true,
// }
// structs, err := ConvertToStructs(input)
// // structs will contain a slice of *structpb.Struct
// // err will be nil if all conversions succeed.
func ConvertToStructs(input map[string]any) ([]*structpb.Struct, error) {
structs := []*structpb.Struct{}
for key, value := range input {
// Convert each value in the map to *structpb.Struct
structValue, err := structpb.NewStruct(map[string]any{
key: value,
})
if err != nil {
return structs, err
}
structs = append(structs, structValue)
}

return structs, nil
}
72 changes: 72 additions & 0 deletions api/grpc/mpi/v1/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) F5, Inc.
//
// This source code is licensed under the Apache License, Version 2.0 license found in the
// LICENSE file in the root directory of this source tree.

package v1

import (
"testing"

"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/types/known/structpb"
)

func TestConvertToStructs(t *testing.T) {
tests := []struct {
name string
input map[string]any
expected []*structpb.Struct
wantErr bool
}{
{
name: "Test 1: Valid input with simple key-value pairs",
input: map[string]any{
"key1": "value1",
"key2": 123,
"key3": true,
},
expected: []*structpb.Struct{
{
Fields: map[string]*structpb.Value{
"key1": structpb.NewStringValue("value1"),
},
},
{
Fields: map[string]*structpb.Value{
"key2": structpb.NewNumberValue(123),
},
},
{
Fields: map[string]*structpb.Value{
"key3": structpb.NewBoolValue(true),
},
},
},
wantErr: false,
},
{
name: "Test 2: Empty input map",
input: make(map[string]any),
expected: []*structpb.Struct{},
wantErr: false,
},
{
name: "Test 3: Invalid input type",
input: map[string]any{
"key1": func() {}, // Unsupported type
},
expected: []*structpb.Struct{},
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ConvertToStructs(tt.input)

assert.Equal(t, tt.expected, got)
assert.Equal(t, tt.wantErr, err != nil)
})
}
}
43 changes: 43 additions & 0 deletions docs/proto/protos.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
- [DataPlaneResponse](#mpi-v1-DataPlaneResponse)
- [FileServer](#mpi-v1-FileServer)
- [GetHTTPUpstreamServers](#mpi-v1-GetHTTPUpstreamServers)
- [GetStreamUpstreams](#mpi-v1-GetStreamUpstreams)
- [GetUpstreams](#mpi-v1-GetUpstreams)
- [HealthRequest](#mpi-v1-HealthRequest)
- [HostInfo](#mpi-v1-HostInfo)
- [Instance](#mpi-v1-Instance)
Expand All @@ -74,6 +76,7 @@
- [UpdateDataPlaneStatusRequest](#mpi-v1-UpdateDataPlaneStatusRequest)
- [UpdateDataPlaneStatusResponse](#mpi-v1-UpdateDataPlaneStatusResponse)
- [UpdateHTTPUpstreamServers](#mpi-v1-UpdateHTTPUpstreamServers)
- [UpdateStreamServers](#mpi-v1-UpdateStreamServers)

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



Expand Down Expand Up @@ -797,6 +801,26 @@ Get HTTP Upstream Servers for an instance



<a name="mpi-v1-GetStreamUpstreams"></a>

### GetStreamUpstreams
Get Stream Upstream Servers for an instance






<a name="mpi-v1-GetUpstreams"></a>

### GetUpstreams
Get Upstreams for an instance






<a name="mpi-v1-HealthRequest"></a>

### HealthRequest
Expand Down Expand Up @@ -977,6 +1001,9 @@ Perform an action using the NGINX Plus API on an instance
| ----- | ---- | ----- | ----------- |
| update_http_upstream_servers | [UpdateHTTPUpstreamServers](#mpi-v1-UpdateHTTPUpstreamServers) | | |
| get_http_upstream_servers | [GetHTTPUpstreamServers](#mpi-v1-GetHTTPUpstreamServers) | | |
| update_stream_servers | [UpdateStreamServers](#mpi-v1-UpdateStreamServers) | | |
| get_upstreams | [GetUpstreams](#mpi-v1-GetUpstreams) | | |
| get_stream_upstreams | [GetStreamUpstreams](#mpi-v1-GetStreamUpstreams) | | |



Expand Down Expand Up @@ -1136,6 +1163,22 @@ Update HTTP Upstream Servers for an instance




<a name="mpi-v1-UpdateStreamServers"></a>

### UpdateStreamServers
Update Upstream Stream Servers for an instance


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| upstream_stream_name | [string](#string) | | the name of the upstream stream |
| servers | [google.protobuf.Struct](#google-protobuf-Struct) | repeated | a list of upstream stream servers |








Expand Down
Loading

0 comments on commit cd74bd4

Please sign in to comment.