Skip to content

Commit

Permalink
treewide: intercom -> meshapi
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Meyer <[email protected]>
  • Loading branch information
katexochen committed Feb 26, 2024
1 parent c8b003e commit 3f307bd
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 203 deletions.
10 changes: 5 additions & 5 deletions coordinator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/edgelesssys/nunki/internal/ca"
"github.com/edgelesssys/nunki/internal/coordapi"
"github.com/edgelesssys/nunki/internal/intercom"
"github.com/edgelesssys/nunki/internal/logger"
"github.com/edgelesssys/nunki/internal/meshapi"
"golang.org/x/sync/errgroup"
)

Expand Down Expand Up @@ -39,7 +39,7 @@ func run() (retErr error) {

meshAuth := newMeshAuthority(caInstance, logger)
coordS := newCoordAPIServer(meshAuth, caInstance, logger)
intercomS := newIntercomServer(meshAuth, caInstance, logger)
meshAPI := newMeshAPIServer(meshAuth, caInstance, logger)

eg := errgroup.Group{}

Expand All @@ -52,9 +52,9 @@ func run() (retErr error) {
})

eg.Go(func() error {
logger.Info("Coordinator intercom listening")
if err := intercomS.Serve(net.JoinHostPort("0.0.0.0", intercom.Port)); err != nil {
return fmt.Errorf("serving intercom API: %w", err)
logger.Info("Coordinator mesh API listening")
if err := meshAPI.Serve(net.JoinHostPort("0.0.0.0", meshapi.Port)); err != nil {
return fmt.Errorf("serving mesh API: %w", err)
}
return nil
})
Expand Down
22 changes: 11 additions & 11 deletions coordinator/intercom.go → coordinator/meshapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ import (
"github.com/edgelesssys/nunki/internal/atls"
"github.com/edgelesssys/nunki/internal/attestation/snp"
"github.com/edgelesssys/nunki/internal/grpc/atlscredentials"
"github.com/edgelesssys/nunki/internal/intercom"
"github.com/edgelesssys/nunki/internal/logger"
"github.com/edgelesssys/nunki/internal/memstore"
"github.com/edgelesssys/nunki/internal/meshapi"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/status"
"k8s.io/utils/clock"
)

type intercomServer struct {
type meshAPIServer struct {
grpc *grpc.Server
certGet certGetter
caChainGetter certChainGetter
ticker clock.Ticker
logger *slog.Logger

intercom.UnimplementedIntercomServer
meshapi.UnimplementedMeshAPIServer
}

type certGetter interface {
GetCert(peerPublicKeyHashStr string) ([]byte, error)
}

func newIntercomServer(meshAuth *meshAuthority, caGetter certChainGetter, log *slog.Logger) *intercomServer {
func newMeshAPIServer(meshAuth *meshAuthority, caGetter certChainGetter, log *slog.Logger) *meshAPIServer {
ticker := clock.RealClock{}.NewTicker(24 * time.Hour)
kdsGetter := snp.NewCachedHTTPSGetter(memstore.New[string, []byte](), ticker, logger.NewNamed(log, "kds-getter"))
validator := snp.NewValidatorWithCallbacks(meshAuth, kdsGetter, logger.NewNamed(log, "snp-validator"), meshAuth)
Expand All @@ -43,18 +43,18 @@ func newIntercomServer(meshAuth *meshAuthority, caGetter certChainGetter, log *s
grpc.Creds(credentials),
grpc.KeepaliveParams(keepalive.ServerParameters{Time: 15 * time.Second}),
)
s := &intercomServer{
s := &meshAPIServer{
grpc: grpcServer,
certGet: meshAuth,
caChainGetter: caGetter,
ticker: ticker,
logger: log.WithGroup("intercom"),
logger: log.WithGroup("meshapi"),
}
intercom.RegisterIntercomServer(s.grpc, s)
meshapi.RegisterMeshAPIServer(s.grpc, s)
return s
}

func (i *intercomServer) Serve(endpoint string) error {
func (i *meshAPIServer) Serve(endpoint string) error {
lis, err := net.Listen("tcp", endpoint)
if err != nil {
return fmt.Errorf("failed to listen: %w", err)
Expand All @@ -64,8 +64,8 @@ func (i *intercomServer) Serve(endpoint string) error {
return i.grpc.Serve(lis)
}

func (i *intercomServer) NewMeshCert(_ context.Context, req *intercom.NewMeshCertRequest,
) (*intercom.NewMeshCertResponse, error) {
func (i *meshAPIServer) NewMeshCert(_ context.Context, req *meshapi.NewMeshCertRequest,
) (*meshapi.NewMeshCertResponse, error) {
i.logger.Info("NewMeshCert called")

cert, err := i.certGet.GetCert(req.PeerPublicKeyHash)
Expand All @@ -77,7 +77,7 @@ func (i *intercomServer) NewMeshCert(_ context.Context, req *intercom.NewMeshCer
meshCACert := i.caChainGetter.GetMeshCACert()
intermCert := i.caChainGetter.GetIntermCert()

return &intercom.NewMeshCertResponse{
return &meshapi.NewMeshCertResponse{
MeshCACert: meshCACert,
CertChain: append(cert, intermCert...),
RootCACert: i.caChainGetter.GetRootCACert(),
Expand Down
2 changes: 1 addition & 1 deletion deployments/emojivoto/coordinator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ metadata:
namespace: edg-default
spec:
ports:
- name: intercom
- name: meshapi
port: 7777
protocol: TCP
- name: coordapi
Expand Down
2 changes: 1 addition & 1 deletion deployments/openssl/coordinator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ metadata:
namespace: edg-default
spec:
ports:
- name: intercom
- name: meshapi
port: 7777
protocol: TCP
- name: coordapi
Expand Down
2 changes: 1 addition & 1 deletion deployments/simple/coordinator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ metadata:
namespace: edg-default
spec:
ports:
- name: intercom
- name: meshapi
port: 7777
protocol: TCP
- name: coordapi
Expand Down
12 changes: 6 additions & 6 deletions initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"github.com/edgelesssys/nunki/internal/atls"
"github.com/edgelesssys/nunki/internal/attestation/snp"
"github.com/edgelesssys/nunki/internal/grpc/dialer"
"github.com/edgelesssys/nunki/internal/intercom"
"github.com/edgelesssys/nunki/internal/logger"
"github.com/edgelesssys/nunki/internal/meshapi"
)

func main() {
Expand Down Expand Up @@ -62,18 +62,18 @@ func run() (retErr error) {
pubKeyHashStr := hex.EncodeToString(pubKeyHash[:])
log.Info("Deriving public key", "pubKeyHash", pubKeyHashStr)

requestCert := func() (*intercom.NewMeshCertResponse, error) {
requestCert := func() (*meshapi.NewMeshCertResponse, error) {
issuer := snp.NewIssuer(logger.NewNamed(log, "snp-issuer"))
dial := dialer.NewWithKey(issuer, atls.NoValidator, &net.Dialer{}, privKey)
conn, err := dial.Dial(ctx, net.JoinHostPort(coordinatorHostname, intercom.Port))
conn, err := dial.Dial(ctx, net.JoinHostPort(coordinatorHostname, meshapi.Port))
if err != nil {
return nil, fmt.Errorf("dialing: %w", err)
}
defer conn.Close()

client := intercom.NewIntercomClient(conn)
client := meshapi.NewMeshAPIClient(conn)

req := &intercom.NewMeshCertRequest{
req := &meshapi.NewMeshCertRequest{
PeerPublicKeyHash: pubKeyHashStr,
}
resp, err := client.NewMeshCert(ctx, req)
Expand All @@ -83,7 +83,7 @@ func run() (retErr error) {
return resp, nil
}

resp := &intercom.NewMeshCertResponse{}
resp := &meshapi.NewMeshCertResponse{}
for {
resp, err = requestCert()
if err == nil {
Expand Down
6 changes: 0 additions & 6 deletions internal/intercom/intercom.go

This file was deleted.

109 changes: 0 additions & 109 deletions internal/intercom/intercom_grpc.pb.go

This file was deleted.

6 changes: 6 additions & 0 deletions internal/meshapi/meshapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package meshapi

//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative meshapi.proto

// Port is the port of the mesh API.
const Port = "7777"
Loading

0 comments on commit 3f307bd

Please sign in to comment.