Skip to content

Commit

Permalink
Create interface for GRPC server which encompasses the GRPC HealthSer…
Browse files Browse the repository at this point in the history
…ver (#1334)

Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
  • Loading branch information
priyawadhwa committed Aug 24, 2023
1 parent 8729242 commit e36369c
Showing 1 changed file with 18 additions and 13 deletions.
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")
}

0 comments on commit e36369c

Please sign in to comment.