mirror of
https://github.com/hanzoai/agent.git
synced 2026-09-11 21:08:51 +00:00
Consolidate all Hanzo agent infrastructure into one repo: - control-plane/: Go control plane server (was agents-new) - sdk/: Go, Python, TypeScript SDKs - deployments/: Docker, Kubernetes, Helm configs - Dockerfile.sdk: Python SDK image (ghcr.io/hanzoai/agent:latest) - CI builds both SDK + control-plane images No more agentfield — everything is hanzoai/agent.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/metadata"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
// APIKeyUnaryInterceptor enforces API key authentication on gRPC calls.
|
|
func APIKeyUnaryInterceptor(apiKey string) grpc.UnaryServerInterceptor {
|
|
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
|
|
// No auth configured, allow everything.
|
|
if apiKey == "" {
|
|
return handler(ctx, req)
|
|
}
|
|
|
|
md, ok := metadata.FromIncomingContext(ctx)
|
|
if !ok {
|
|
return nil, status.Error(codes.Unauthenticated, "missing metadata")
|
|
}
|
|
|
|
// Check x-api-key
|
|
if keys := md.Get("x-api-key"); len(keys) > 0 && keys[0] == apiKey {
|
|
return handler(ctx, req)
|
|
}
|
|
|
|
// Check Authorization: Bearer
|
|
if auths := md.Get("authorization"); len(auths) > 0 && strings.HasPrefix(auths[0], "Bearer ") {
|
|
if strings.TrimPrefix(auths[0], "Bearer ") == apiKey {
|
|
return handler(ctx, req)
|
|
}
|
|
}
|
|
|
|
return nil, status.Error(codes.Unauthenticated, "invalid or missing api key")
|
|
}
|
|
}
|