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 7 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
14 changes: 7 additions & 7 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3337,8 +3337,8 @@ func (c *Client) ListResources(ctx context.Context, req proto.ListResourcesReque
resources[i] = respResource.GetKubernetesServer()
case types.KindUserGroup:
resources[i] = respResource.GetUserGroup()
case types.KindAppOrSAMLIdPServiceProvider:
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 @@ -3416,9 +3416,6 @@ 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 {
out = r
return out, nil
} else if r := resource.GetWindowsDesktop(); r != nil {
out = r
return out, nil
Expand All @@ -3437,6 +3434,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 @@ -3531,8 +3531,8 @@ func GetResourcePage[T types.ResourceWithLabels](ctx context.Context, clt GetRes
resource = respResource.GetKubernetesServer()
case types.KindUserGroup:
resource = respResource.GetUserGroup()
case types.KindAppOrSAMLIdPServiceProvider:
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
86 changes: 32 additions & 54 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 @@ -261,13 +261,13 @@ func (s *listResourcesService) ListResources(ctx context.Context, req *proto.Lis
}

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

protoResource = &proto.PaginatedResource{Resource: &proto.PaginatedResource_AppServerOrSAMLIdPServiceProvider{AppServerOrSAMLIdPServiceProvider: appServerOrSP}}
protoResource = &proto.PaginatedResource{Resource: &proto.PaginatedResource_SAMLIdPServiceProvider{SAMLIdPServiceProvider: samlSP}}
}
resp.Resources = append(resp.Resources, protoResource)
lastResourceName = resource.GetName()
Expand All @@ -276,7 +276,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 @@ -414,51 +414,25 @@ func testResources[T types.ResourceWithLabels](resourceType, namespace string) (

resources = append(resources, any(resource).(T))
}
case types.KindAppOrSAMLIdPServiceProvider:
case types.KindSAMLIdPServiceProvider:
for i := 0; i < size; i++ {
// Alternate between adding Apps and SAMLIdPServiceProviders. If `i` is even, add an app.
if i%2 == 0 {
app, err := types.NewAppV3(types.Metadata{
Name: fmt.Sprintf("app-%d", i),
}, types.AppSpecV3{
URI: "localhost",
})
if err != nil {
return nil, trace.Wrap(err)
}

appServer, err := types.NewAppServerV3(types.Metadata{
Name: fmt.Sprintf("app-%d", i),
Labels: map[string]string{
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.AppServerSpecV3{
HostID: fmt.Sprintf("host-%d", i),
App: app,
})
if err != nil {
return nil, trace.Wrap(err)
}

resource := &types.AppServerOrSAMLIdPServiceProviderV1{
Resource: &types.AppServerOrSAMLIdPServiceProviderV1_AppServer{
AppServer: appServer,
},
}

resources = append(resources, any(resource).(T))
} else {
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)),
}}}}

resource := &types.AppServerOrSAMLIdPServiceProviderV1{
Resource: &types.AppServerOrSAMLIdPServiceProviderV1_SAMLIdPServiceProvider{
SAMLIdPServiceProvider: sp,
},
}
resources = append(resources, any(resource).(T))
},
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 +470,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 @@ -603,9 +581,9 @@ func TestGetResources(t *testing.T) {
testGetResources[types.WindowsDesktop](t, clt, types.KindWindowsDesktop)
})

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

Expand Down Expand Up @@ -636,8 +614,8 @@ func TestGetResourcesWithFilters(t *testing.T) {
"WindowsDesktop": {
resourceType: types.KindWindowsDesktop,
},
"AppAndIdPServiceProvider": {
resourceType: types.KindAppOrSAMLIdPServiceProvider,
"SAMLIdPServiceProvider": {
resourceType: types.KindSAMLIdPServiceProvider,
},
}

Expand Down
Loading
Loading