1
// Copyright Istio Authors
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
22
"google.golang.org/grpc"
24
gcapb "istio.io/istio/security/proto/providers/google"
27
// CAService is a simple mocked Google CA Service.
28
type CAService struct {
29
*gcapb.UnimplementedMeshCertificateServiceServer
34
// CreateCertificate is a mocked function for the Google Mesh CA API.
35
func (ca *CAService) CreateCertificate(ctx context.Context, in *gcapb.MeshCertificateRequest) (
36
*gcapb.MeshCertificateResponse, error,
39
return &gcapb.MeshCertificateResponse{CertChain: ca.Certs}, nil
44
// CAServer is the mocked Mesh CA server.
50
// CreateServer creates a mocked local Google CA server and runs it in a separate thread.
52
func CreateServer(addr string, service *CAService) (*CAServer, error) {
53
// create a local grpc server
55
Server: grpc.NewServer(),
58
lis, err := net.Listen("tcp", addr)
60
return nil, fmt.Errorf("failed to listen on the TCP address: %v", err)
62
s.Address = lis.Addr().String()
65
gcapb.RegisterMeshCertificateServiceServer(s.Server, service)
67
if err := s.Server.Serve(lis); err != nil {
79
// Stop stops the Mock Mesh CA server.
80
func (s *CAServer) Stop() {