|
| 1 | +/* |
| 2 | +Copyright 2021 The Kubernetes-CSI-Addons Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | + Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package service |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + |
| 22 | + "github.com/csi-addons/spec/lib/go/identity" |
| 23 | + "google.golang.org/grpc" |
| 24 | +) |
| 25 | + |
| 26 | +// IdentityServer struct of sidecar with supported methods of CSI |
| 27 | +// identity server spec and also containing client to csi driver. |
| 28 | +type IdentityServer struct { |
| 29 | + *identity.UnimplementedIdentityServer |
| 30 | + identityClient identity.IdentityClient |
| 31 | +} |
| 32 | + |
| 33 | +// NewIdentityServer creates a new IdentityServer which handles the Identity |
| 34 | +// Service requests from the CSI-Addons specification. |
| 35 | +func NewIdentityServer(client *grpc.ClientConn) *IdentityServer { |
| 36 | + return &IdentityServer{ |
| 37 | + identityClient: identity.NewIdentityClient(client), |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +func (is *IdentityServer) RegisterService(server grpc.ServiceRegistrar) { |
| 42 | + identity.RegisterIdentityServer(server, is) |
| 43 | +} |
| 44 | + |
| 45 | +// GetIdentity returns available capabilities from the driver. |
| 46 | +func (is *IdentityServer) GetIdentity( |
| 47 | + ctx context.Context, |
| 48 | + req *identity.GetIdentityRequest) (*identity.GetIdentityResponse, error) { |
| 49 | + return is.identityClient.GetIdentity(ctx, req) |
| 50 | +} |
| 51 | + |
| 52 | +// GetCapabilities returns available capabilities from the driver. |
| 53 | +func (is *IdentityServer) GetCapabilities( |
| 54 | + ctx context.Context, |
| 55 | + req *identity.GetCapabilitiesRequest) (*identity.GetCapabilitiesResponse, error) { |
| 56 | + return is.identityClient.GetCapabilities(ctx, req) |
| 57 | +} |
| 58 | + |
| 59 | +// Probe is called by the CO plugin to validate that the CSI-Addons Node is |
| 60 | +// still healthy. |
| 61 | +func (is *IdentityServer) Probe( |
| 62 | + ctx context.Context, |
| 63 | + req *identity.ProbeRequest) (*identity.ProbeResponse, error) { |
| 64 | + return is.identityClient.Probe(ctx, req) |
| 65 | +} |
0 commit comments