add included

This commit is contained in:
Aditya Siregar
2026-05-07 09:45:48 +07:00
parent 56d854fbc0
commit 25f438237c
3 changed files with 71 additions and 13 deletions
+32 -13
View File
@@ -8,12 +8,14 @@ import (
"fmt"
"io"
"net/http"
"os"
"strings"
"time"
"go-backend-template/config"
"go-backend-template/internal/contract"
"go-backend-template/internal/logger"
"go-backend-template/internal/util"
)
// DukcapilClient performs HTTPS calls to the Dukcapil 1:N face recognition endpoint (CALL_FN).
@@ -37,20 +39,37 @@ func (c *DukcapilClient) FaceMatch(ctx context.Context, req *contract.FaceMatchR
return nil, errors.New("dukcapil: incomplete configuration")
}
ip := req.IP
if strings.TrimSpace(ip) == "" {
ip = c.cfg.DefaultIP
}
body := contract.DukcapilFaceRequest{
TransactionID: req.TransactionID,
TransactionSource: req.TransactionSource,
Threshold: req.Threshold,
Image: req.Image,
UserID: c.cfg.UserID,
Password: c.cfg.Password,
IP: ip,
}
ip := req.IP
if strings.TrimSpace(ip) == "" {
ip = c.cfg.DefaultIP
}
// Load PEM public key from file
pemBytes, err := os.ReadFile("infra/990030524100001.pem")
if err != nil {
return nil, fmt.Errorf("dukcapil: failed to read PEM file: %w", err)
}
// Encrypt UserID and Password
encryptedUserID, err := util.EncryptWithPublicKey(c.cfg.UserID, pemBytes)
if err != nil {
return nil, fmt.Errorf("dukcapil: encrypt user_id: %w", err)
}
encryptedPassword, err := util.EncryptWithPublicKey(c.cfg.Password, pemBytes)
if err != nil {
return nil, fmt.Errorf("dukcapil: encrypt password: %w", err)
}
body := contract.DukcapilFaceRequest{
TransactionID: req.TransactionID,
TransactionSource: req.TransactionSource,
Threshold: req.Threshold,
Image: req.Image,
UserID: encryptedUserID,
Password: encryptedPassword,
IP: ip,
}
payload, err := json.Marshal(body)
if err != nil {