mirror of
https://github.com/NVIDIA/OpenShell.git
synced 2026-10-30 07:33:59 +08:00
* feat(service): add bearer authorization passthrough Signed-off-by: Derek Carr <decarr@redhat.com> * docs(sdk): add service authorization migration guide Signed-off-by: Derek Carr <decarr@redhat.com> * fix(server): remove stale version import Signed-off-by: Derek Carr <decarr@redhat.com> * docs(upgrade): remove service authorization SDK guide Signed-off-by: Derek Carr <decarr@redhat.com> * fix(e2e): relabel provider readiness TLS mount Signed-off-by: Derek Carr <decarr@redhat.com> * test(e2e): stabilize exposed service routing Signed-off-by: Derek Carr <decarr@redhat.com> * test(e2e): support HTTPS service routing Signed-off-by: Derek Carr <decarr@redhat.com> --------- Signed-off-by: Derek Carr <decarr@redhat.com>
105 lines
3.5 KiB
Go
105 lines
3.5 KiB
Go
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package v1
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/NVIDIA/OpenShell/sdk/go/openshell/v1/internal/converter"
|
|
pb "github.com/NVIDIA/OpenShell/sdk/go/proto/openshellv1"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
type serviceClient struct {
|
|
client pb.OpenShellClient
|
|
}
|
|
|
|
func newServiceClient(conn grpc.ClientConnInterface) *serviceClient {
|
|
return &serviceClient{client: pb.NewOpenShellClient(conn)}
|
|
}
|
|
|
|
func (s *serviceClient) Expose(ctx context.Context, workspace, sandboxName, serviceName string, targetPort uint32, domain bool, opts ...ExposeServiceOptions) (*ServiceEndpoint, error) {
|
|
authorizationMode := ServiceAuthorizationModeStrip
|
|
if len(opts) > 0 && opts[0].AuthorizationMode != 0 {
|
|
authorizationMode = opts[0].AuthorizationMode
|
|
}
|
|
resp, err := s.client.ExposeService(ctx, &pb.ExposeServiceRequest{
|
|
Sandbox: sandboxName,
|
|
WorkspaceScope: namedWorkspaceScope(workspace),
|
|
Name: serviceName,
|
|
TargetPort: targetPort,
|
|
Domain: domain,
|
|
AuthorizationMode: pb.ServiceAuthorizationMode(authorizationMode),
|
|
})
|
|
if err != nil {
|
|
return nil, converter.FromGRPCError(err)
|
|
}
|
|
return converter.ServiceEndpointFromProto(resp), nil
|
|
}
|
|
|
|
func (s *serviceClient) Get(ctx context.Context, workspace, sandboxName, serviceName string) (*ServiceEndpoint, error) {
|
|
resp, err := s.client.GetService(ctx, &pb.GetServiceRequest{
|
|
Sandbox: sandboxName,
|
|
WorkspaceScope: namedWorkspaceScope(workspace),
|
|
Name: serviceName,
|
|
})
|
|
if err != nil {
|
|
return nil, converter.FromGRPCError(err)
|
|
}
|
|
return converter.ServiceEndpointFromProto(resp), nil
|
|
}
|
|
|
|
func (s *serviceClient) List(workspace, sandboxName string, opts ...ListOptions) (*Pager[*ServiceEndpoint], error) {
|
|
pageSize, err := listPageSize(opts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var pageToken string
|
|
var allWorkspaces bool
|
|
if len(opts) > 0 {
|
|
pageToken = opts[0].PageToken
|
|
allWorkspaces = opts[0].AllWorkspaces
|
|
}
|
|
workspaceScope := namedWorkspaceScope(workspace)
|
|
if allWorkspaces {
|
|
workspaceScope = allWorkspacesScope()
|
|
}
|
|
return newPager(pageToken, func(ctx context.Context, pageToken string) (*Page[*ServiceEndpoint], error) {
|
|
req := &pb.ListServicesRequest{
|
|
Sandbox: sandboxName, WorkspaceScope: workspaceScope, PageSize: pageSize,
|
|
PageToken: pageToken,
|
|
}
|
|
resp, err := s.client.ListServices(ctx, req)
|
|
if err != nil {
|
|
return nil, converter.FromGRPCError(err)
|
|
}
|
|
endpoints := make([]*ServiceEndpoint, 0, len(resp.GetServices()))
|
|
for _, svc := range resp.GetServices() {
|
|
endpoints = append(endpoints, converter.ServiceEndpointFromProto(svc))
|
|
}
|
|
return &Page[*ServiceEndpoint]{Items: endpoints, NextPageToken: resp.GetNextPageToken()}, nil
|
|
}), nil
|
|
}
|
|
|
|
func (s *serviceClient) ListAll(ctx context.Context, workspace, sandboxName string, opts ...ListOptions) ([]*ServiceEndpoint, error) {
|
|
pager, err := s.List(workspace, sandboxName, opts...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return pager.All(ctx)
|
|
}
|
|
|
|
func (s *serviceClient) Delete(ctx context.Context, workspace, sandboxName, serviceName string, opts ...DeleteOptions) (*DeletionResult, error) {
|
|
resp, err := s.client.DeleteService(ctx, &pb.DeleteServiceRequest{
|
|
AllowMissing: allowMissing(opts),
|
|
Sandbox: sandboxName,
|
|
WorkspaceScope: namedWorkspaceScope(workspace),
|
|
Name: serviceName,
|
|
})
|
|
if err != nil {
|
|
return nil, converter.FromGRPCError(err)
|
|
}
|
|
return &DeletionResult{Outcome: DeletionOutcome(resp.GetOutcome())}, nil
|
|
}
|