certmanager updates

This commit is contained in:
Олег Бородин
2024-08-10 15:28:32 +02:00
parent 0bafb086bc
commit 90a9d94405
3 changed files with 22 additions and 17 deletions

View File

@@ -15,8 +15,6 @@ func (hand *Handler) Authentificate(ctx context.Context) (int64, error) {
var accountID int64
meta, _ := metadata.FromIncomingContext(ctx)
hand.log.Debugf("Reqest username: %s", meta["username"])
hand.log.Debugf("Reqest password: %s", meta["password"])
usernameArr := meta["username"]
passwordArr := meta["password"]
if len(usernameArr) == 0 || len(passwordArr) == 0 {

View File

@@ -80,7 +80,7 @@ func (svc *Service) Run() error {
gsrvOpts := []grpc.ServerOption{
grpc.Creds(tlsCredentials),
grpc.UnaryInterceptor(svc.debugInterceptor),
grpc.UnaryInterceptor(svc.logInterceptor),
}
svc.gsrv = grpc.NewServer(gsrvOpts...)
@@ -94,22 +94,20 @@ func (svc *Service) Run() error {
return err
}
func (svc *Service) debugInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
svc.log.Debugf("Called unary interceptor with method: %v", info.FullMethod)
func (svc *Service) logInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
meta, _ := metadata.FromIncomingContext(ctx)
svc.log.Debugf("Reqest username: %v", meta["username"])
svc.log.Debugf("Reqest password: %v", meta["password"])
svc.log.Infof("User %v called %v", meta["username"], info.FullMethod)
return handler(ctx, req)
}
func (svc *Service) logInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
func (svc *Service) debugInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
var err error
svc.log.Debugf("Called unary interceptor with method: %v", info.FullMethod)
reqBinary, err := json.Marshal(req)
requestString := ""
if err == nil {
svc.log.Debugf("Request: %f", string(reqBinary))
requestString = string(reqBinary)
}
svc.log.Debugf("Called method: %v with params %v", info.FullMethod, requestString)
return handler(ctx, req)
}

View File

@@ -221,11 +221,20 @@ func CreateServicePair(params *CreateServicePairParams) (*CreateServicePairResul
res.Name = certSubject.String()
netAddresses := make([]net.IP, 0)
for _, ipAddress := range params.IPAddresses {
netAddress := net.ParseIP(ipAddress)
netAddresses = append(netAddresses, netAddress)
}
var netAddresses []net.IP
if len(params.IPAddresses) > 0 {
netAddresses = make([]net.IP, 0)
for _, ipAddress := range params.IPAddresses {
netAddress := net.ParseIP(ipAddress)
netAddresses = append(netAddresses, netAddress)
}
}
var dnsNames []string
if len(params.DNSNames) > 0 {
dnsNames = make([]string, 0)
dnsNames = append(dnsNames, params.DNSNames...)
}
certTempl := &x509.Certificate{
SerialNumber: big.NewInt(now.Unix()),
@@ -233,7 +242,7 @@ func CreateServicePair(params *CreateServicePairParams) (*CreateServicePairResul
NotAfter: now.AddDate(yearsAfter, 0, 0),
Subject: certSubject,
Issuer: certIssuer,
DNSNames: params.DNSNames,
DNSNames: dnsNames,
IPAddresses: netAddresses,
IsCA: false,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},