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

Create interface for GRPC server which encompasses the GRPC HealthServer #1334

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 18 additions & 13 deletions pkg/server/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"errors"
"fmt"

health "google.golang.org/grpc/health/grpc_health_v1"

ctclient "github.com/google/certificate-transparency-go/client"
certauth "github.com/sigstore/fulcio/pkg/ca"
"github.com/sigstore/fulcio/pkg/challenges"
Expand All @@ -32,21 +34,17 @@ import (
"github.com/sigstore/fulcio/pkg/log"
"github.com/sigstore/sigstore/pkg/cryptoutils"
"google.golang.org/grpc/codes"
health "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
)

type GRPCCAServer struct {
fulciogrpc.UnimplementedCAServer
type GRPCCAServer interface {
fulciogrpc.CAServer
health.HealthServer
ct *ctclient.LogClient
ca certauth.CertificateAuthority
identity.IssuerPool
}

func NewGRPCCAServer(ct *ctclient.LogClient, ca certauth.CertificateAuthority, ip identity.IssuerPool) *GRPCCAServer {
return &GRPCCAServer{
func NewGRPCCAServer(ct *ctclient.LogClient, ca certauth.CertificateAuthority, ip identity.IssuerPool) GRPCCAServer {
return &grpcaCAServer{
ct: ct,
ca: ca,
IssuerPool: ip,
Expand All @@ -57,7 +55,14 @@ const (
MetadataOIDCTokenKey = "oidcidentitytoken"
)

func (g *GRPCCAServer) CreateSigningCertificate(ctx context.Context, request *fulciogrpc.CreateSigningCertificateRequest) (*fulciogrpc.SigningCertificate, error) {
type grpcaCAServer struct {
fulciogrpc.UnimplementedCAServer
ct *ctclient.LogClient
ca certauth.CertificateAuthority
identity.IssuerPool
}

func (g *grpcaCAServer) CreateSigningCertificate(ctx context.Context, request *fulciogrpc.CreateSigningCertificateRequest) (*fulciogrpc.SigningCertificate, error) {
logger := log.ContextLogger(ctx)

// OIDC token either is passed in gRPC field or was extracted from HTTP headers
Expand Down Expand Up @@ -231,7 +236,7 @@ func (g *GRPCCAServer) CreateSigningCertificate(ctx context.Context, request *fu
return result, nil
}

func (g *GRPCCAServer) GetTrustBundle(ctx context.Context, _ *fulciogrpc.GetTrustBundleRequest) (*fulciogrpc.TrustBundle, error) {
func (g *grpcaCAServer) GetTrustBundle(ctx context.Context, _ *fulciogrpc.GetTrustBundleRequest) (*fulciogrpc.TrustBundle, error) {
trustBundle, err := g.ca.TrustBundle(ctx)
if err != nil {
return nil, handleFulcioGRPCError(ctx, codes.Internal, err, retrieveTrustBundleCAError)
Expand All @@ -255,7 +260,7 @@ func (g *GRPCCAServer) GetTrustBundle(ctx context.Context, _ *fulciogrpc.GetTrus
return resp, nil
}

func (g *GRPCCAServer) GetConfiguration(ctx context.Context, _ *fulciogrpc.GetConfigurationRequest) (*fulciogrpc.Configuration, error) {
func (g *grpcaCAServer) GetConfiguration(ctx context.Context, _ *fulciogrpc.GetConfigurationRequest) (*fulciogrpc.Configuration, error) {
cfg := config.FromContext(ctx)
if cfg == nil {
err := errors.New("configuration not loaded")
Expand All @@ -267,10 +272,10 @@ func (g *GRPCCAServer) GetConfiguration(ctx context.Context, _ *fulciogrpc.GetCo
}, nil
}

func (g *GRPCCAServer) Check(_ context.Context, _ *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
func (g *grpcaCAServer) Check(_ context.Context, _ *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
return &health.HealthCheckResponse{Status: health.HealthCheckResponse_SERVING}, nil
}

func (g *GRPCCAServer) Watch(_ *health.HealthCheckRequest, _ health.Health_WatchServer) error {
func (g *grpcaCAServer) Watch(_ *health.HealthCheckRequest, _ health.Health_WatchServer) error {
return status.Error(codes.Unimplemented, "unimplemented")
}