Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate kindAppOrSAMLIdPServiceProvider, AppServerOrSAMLIdPServiceProvider and use types.SAMLIdPServiceProvider #38709

Merged
merged 14 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3554,7 +3554,10 @@ func (c *Client) ListResources(ctx context.Context, req proto.ListResourcesReque
case types.KindUserGroup:
resources[i] = respResource.GetUserGroup()
case types.KindAppOrSAMLIdPServiceProvider:
//nolint:staticcheck // SA1019. TODO(sshah) DELETE IN 17.0
resources[i] = respResource.GetAppServerOrSAMLIdPServiceProvider()
case types.KindSAMLIdPServiceProvider:
resources[i] = respResource.GetSAMLIdPServiceProvider()
flyinghermit marked this conversation as resolved.
Show resolved Hide resolved
default:
return nil, trace.NotImplemented("resource type %s does not support pagination", req.ResourceType)
}
Expand Down Expand Up @@ -3632,7 +3635,7 @@ func getResourceFromProtoPage(resource *proto.PaginatedResource) (types.Resource
} else if r := resource.GetDatabaseService(); r != nil {
out = r
return out, nil
} else if r := resource.GetAppServerOrSAMLIdPServiceProvider(); r != nil {
} else if r := resource.GetAppServerOrSAMLIdPServiceProvider(); r != nil { //nolint:staticcheck // SA1019. TODO(sshah) DELETE IN 17.0
out = r
return out, nil
} else if r := resource.GetWindowsDesktop(); r != nil {
Expand All @@ -3653,6 +3656,9 @@ func getResourceFromProtoPage(resource *proto.PaginatedResource) (types.Resource
} else if r := resource.GetAppServer(); r != nil {
out = r
return out, nil
} else if r := resource.GetSAMLIdPServiceProvider(); r != nil {
out = r
return out, nil
} else {
return nil, trace.BadParameter("received unsupported resource %T", resource.Resource)
}
Expand Down Expand Up @@ -3748,7 +3754,10 @@ func GetResourcePage[T types.ResourceWithLabels](ctx context.Context, clt GetRes
case types.KindUserGroup:
resource = respResource.GetUserGroup()
case types.KindAppOrSAMLIdPServiceProvider:
//nolint:staticcheck // SA1019. TODO(sshah) DELETE IN 17.0
resource = respResource.GetAppServerOrSAMLIdPServiceProvider()
case types.KindSAMLIdPServiceProvider:
resource = respResource.GetSAMLIdPServiceProvider()
default:
out.Resources = nil
return out, trace.NotImplemented("resource type %s does not support pagination", req.ResourceType)
Expand Down
53 changes: 47 additions & 6 deletions api/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,21 @@ type listResourcesService struct {
}

func (s *listResourcesService) ListResources(ctx context.Context, req *proto.ListResourcesRequest) (*proto.ListResourcesResponse, error) {
resources, err := testResources[types.ResourceWithLabels](req.ResourceType, req.Namespace)
expectedResources, err := testResources[types.ResourceWithLabels](req.ResourceType, req.Namespace)
if err != nil {
return nil, trail.ToGRPC(err)
}

resp := &proto.ListResourcesResponse{
Resources: make([]*proto.PaginatedResource, 0, len(resources)),
TotalCount: int32(len(resources)),
Resources: make([]*proto.PaginatedResource, 0, len(expectedResources)),
TotalCount: int32(len(expectedResources)),
}

var (
takeResources = req.StartKey == ""
lastResourceName string
)
for _, resource := range resources {
for _, resource := range expectedResources {
if resource.GetName() == req.StartKey {
takeResources = true
continue
Expand Down Expand Up @@ -262,12 +262,20 @@ func (s *listResourcesService) ListResources(ctx context.Context, req *proto.Lis

protoResource = &proto.PaginatedResource{Resource: &proto.PaginatedResource_WindowsDesktop{WindowsDesktop: desktop}}
case types.KindAppOrSAMLIdPServiceProvider:
//nolint:staticcheck // SA1019. TODO(sshah) DELETE IN 17.0
appServerOrSP, ok := resource.(*types.AppServerOrSAMLIdPServiceProviderV1)
if !ok {
return nil, trace.Errorf("AppServerOrSAMLIdPServiceProvider has invalid type %T", resource)
}

protoResource = &proto.PaginatedResource{Resource: &proto.PaginatedResource_AppServerOrSAMLIdPServiceProvider{AppServerOrSAMLIdPServiceProvider: appServerOrSP}}
case types.KindSAMLIdPServiceProvider:
samlSP, ok := resource.(*types.SAMLIdPServiceProviderV1)
if !ok {
return nil, trace.Errorf("SAML IdP service provider has invalid type %T", resource)
}

protoResource = &proto.PaginatedResource{Resource: &proto.PaginatedResource_SAMLIdPServiceProvider{SAMLIdPServiceProvider: samlSP}}
}
resp.Resources = append(resp.Resources, protoResource)
lastResourceName = resource.GetName()
Expand All @@ -276,7 +284,7 @@ func (s *listResourcesService) ListResources(ctx context.Context, req *proto.Lis
}
}

if len(resp.Resources) != len(resources) {
if len(resp.Resources) != len(expectedResources) {
resp.NextKey = lastResourceName
}

Expand Down Expand Up @@ -440,6 +448,7 @@ func testResources[T types.ResourceWithLabels](resourceType, namespace string) (
return nil, trace.Wrap(err)
}

//nolint:staticcheck // SA1019. TODO(sshah) DELETE IN 17.0
resource := &types.AppServerOrSAMLIdPServiceProviderV1{
Resource: &types.AppServerOrSAMLIdPServiceProviderV1_AppServer{
AppServer: appServer,
Expand All @@ -451,7 +460,7 @@ func testResources[T types.ResourceWithLabels](resourceType, namespace string) (
sp := &types.SAMLIdPServiceProviderV1{ResourceHeader: types.ResourceHeader{Metadata: types.Metadata{Name: fmt.Sprintf("saml-app-%d", i), Labels: map[string]string{
"label": string(make([]byte, labelSize)),
}}}}

//nolint:staticcheck // SA1019. TODO(sshah) DELETE IN 17.0
resource := &types.AppServerOrSAMLIdPServiceProviderV1{
Resource: &types.AppServerOrSAMLIdPServiceProviderV1_SAMLIdPServiceProvider{
SAMLIdPServiceProvider: sp,
Expand All @@ -460,6 +469,26 @@ func testResources[T types.ResourceWithLabels](resourceType, namespace string) (
resources = append(resources, any(resource).(T))
}
}
case types.KindSAMLIdPServiceProvider:
for i := 0; i < size; i++ {
name := fmt.Sprintf("saml-app-%d", i)
spResource, err := types.NewSAMLIdPServiceProvider(
types.Metadata{
Name: name, Labels: map[string]string{
"label": string(make([]byte, labelSize)),
},
},
types.SAMLIdPServiceProviderSpecV1{
EntityID: name,
ACSURL: name,
},
)
if err != nil {
return nil, trace.Wrap(err)
}

resources = append(resources, any(spResource).(T))
}
default:
return nil, trace.Errorf("unsupported resource type %s", resourceType)
}
Expand Down Expand Up @@ -496,6 +525,10 @@ func TestListResources(t *testing.T) {
resourceType: types.KindWindowsDesktop,
resourceStruct: &types.WindowsDesktopV3{},
},
"SAMLIdPServiceProvider": {
resourceType: types.KindSAMLIdPServiceProvider,
resourceStruct: &types.SAMLIdPServiceProviderV1{},
},
}

// Create client
Expand Down Expand Up @@ -607,6 +640,11 @@ func TestGetResources(t *testing.T) {
t.Parallel()
testGetResources[types.AppServerOrSAMLIdPServiceProvider](t, clt, types.KindAppOrSAMLIdPServiceProvider)
})

t.Run("SAMLIdPServiceProvider", func(t *testing.T) {
t.Parallel()
testGetResources[types.SAMLIdPServiceProvider](t, clt, types.KindSAMLIdPServiceProvider)
})
}

func TestGetResourcesWithFilters(t *testing.T) {
Expand Down Expand Up @@ -639,6 +677,9 @@ func TestGetResourcesWithFilters(t *testing.T) {
"AppAndIdPServiceProvider": {
resourceType: types.KindAppOrSAMLIdPServiceProvider,
},
"SAMLIdPServiceProvider": {
resourceType: types.KindSAMLIdPServiceProvider,
},
}

for name, test := range testCases {
Expand Down
Loading
Loading