Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
db8361f
changed names of handler and added serverside request handler
avatus Aug 29, 2022
ab46825
added separate GetServers grpc for connect
avatus Aug 30, 2022
4bcfdf5
Merge branch 'master' into michaelmyers/connect/add-parameter-search
avatus Aug 30, 2022
7ba931c
addressing reviews
avatus Aug 30, 2022
134c9b4
more changes
avatus Aug 30, 2022
b4e1d19
run make grpc-teleterm
avatus Aug 30, 2022
c6daeaa
Merge branch 'master' into michaelmyers/connect/add-parameter-search
avatus Aug 30, 2022
92c7f8a
moved clients outside of retry
avatus Aug 30, 2022
08c90dd
Merge branch 'michaelmyers/connect/add-parameter-search' of https://g…
avatus Aug 30, 2022
1a37ac7
Merge branch 'master' into michaelmyers/connect/add-parameter-search
avatus Aug 30, 2022
235e650
move authClient into retyable
avatus Aug 31, 2022
82896b1
abstracted sortby out
avatus Aug 31, 2022
7e34859
Merge branch 'master' into michaelmyers/connect/add-parameter-search
avatus Aug 31, 2022
c9b2cd3
Merge branch 'michaelmyers/connect/add-parameter-search' of https://g…
avatus Aug 31, 2022
ee3e584
removed unused import
avatus Aug 31, 2022
371d7f0
moved request into right scope
avatus Aug 31, 2022
f0574bd
used new sortby method in listResources and added tests
avatus Sep 1, 2022
169345c
Merge branch 'master' into michaelmyers/connect/add-parameter-search
avatus Sep 1, 2022
0c30b98
fixed godocs
avatus Sep 2, 2022
08c0cc6
Merge branch 'master' into michaelmyers/connect/add-parameter-search
avatus Sep 2, 2022
d2a2eec
more contextual naming and removing useless comments
avatus Sep 2, 2022
64a8719
Merge branch 'master' into michaelmyers/connect/add-parameter-search
avatus Sep 6, 2022
6f8291d
fix-license
avatus Sep 6, 2022
d8ec5eb
Merge branch 'michaelmyers/connect/add-parameter-search' of https://g…
avatus Sep 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions api/types/sortby.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022 Gravitational, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package types
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is types the best package for this? This is a pretty low-level commonly imported package. Maybe there's a better place for it?

Copy link
Copy Markdown
Contributor Author

@avatus avatus Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was our first best guess at where to put it. I'm open to suggestions, not quite sure which context suites it best.


import (
"strings"
)

// GetSortByFromString expects a string in format `<fieldName>:<asc|desc>` where
// index 0 is fieldName and index 1 is direction.
// If a direction is not set, or is not recognized, it defaults to ASC.
func GetSortByFromString(sortStr string) (sortBy SortBy) {
if sortStr == "" {
return sortBy
}

vals := strings.Split(sortStr, ":")
if vals[0] != "" {
sortBy.Field = vals[0]
if len(vals) > 1 && vals[1] == "desc" {
sortBy.IsDesc = true
}
}

return sortBy
}
63 changes: 63 additions & 0 deletions api/types/sortby_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2022 Gravitational, Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package types

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestGetSortByFromString(t *testing.T) {
t.Parallel()
tests := []struct {
in string
out SortBy
}{
{
"hostname:asc",
SortBy{
Field: "hostname",
IsDesc: false,
},
},
{
"",
SortBy{},
},
{
"name:desc",
SortBy{
Field: "name",
IsDesc: true,
},
},
{
"hostname",
SortBy{
Field: "hostname",
IsDesc: false,
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.in, func(t *testing.T) {

out := GetSortByFromString(tt.in)
require.Equal(t, tt.out, out)
})
}
}
26 changes: 22 additions & 4 deletions lib/teleterm/api/proto/v1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ service TerminalService {
rpc ListDatabases(ListDatabasesRequest) returns (ListDatabasesResponse);
// ListDatabaseUsers lists allowed users for the given database based on the role set.
rpc ListDatabaseUsers(ListDatabaseUsersRequest) returns (ListDatabaseUsersResponse);
// ListServers lists servers
rpc ListServers(ListServersRequest) returns (ListServersResponse);
// GetAllServers returns all servers
rpc GetAllServers(GetAllServersRequest) returns (GetAllServersResponse);
// GetServers returns filtered, sorted, and paginated servers
rpc GetServers(GetServersRequest) returns (GetServersResponse);
// ListKubes list kubes
rpc ListKubes(ListKubesRequest) returns (ListKubesResponse);
// ListApps list apps
Expand Down Expand Up @@ -267,14 +269,30 @@ message SetGatewayLocalPortRequest {
string local_port = 2;
}

message ListServersRequest {
message GetAllServersRequest {
string cluster_uri = 1;
}

message ListServersResponse {
message GetAllServersResponse {
repeated Server servers = 1;
}

message GetServersRequest {
string cluster_uri = 1;
int32 limit = 2;
string start_key = 3;
string search = 4;
string query = 5;
string sort_by = 6;
string search_as_roles = 7;
}

message GetServersResponse {
repeated Server servers = 1;
int32 total_count = 2;
string start_key = 3;
}

message ListKubesResponse {
repeated Kube kubes = 1;
}
Expand Down
Loading