feat: PKI API Go avec persistance MongoDB et abstraction storage
- API REST complète pour gestion Infrastructure à Clé Publique - Authentification JWT sur tous les endpoints (sauf login) - Hiérarchie de certificats (Root CA, Sub-CA, End Certificates) - Abstraction de stockage avec MemoryStore et MongoStore - Configuration centralisée via variables d'environnement - Support déploiement Docker Compose avec MongoDB - Tests unitaires pour sérialisation des clés RSA - Documentation complète avec exemples API
This commit is contained in:
51
cmd/main.go
Normal file
51
cmd/main.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stef/pkiapi/internal/api"
|
||||
"github.com/stef/pkiapi/internal/config"
|
||||
"github.com/stef/pkiapi/internal/storage"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Charger la configuration
|
||||
cfg := config.LoadConfig()
|
||||
|
||||
// Initialiser le moteur Gin
|
||||
router := gin.Default()
|
||||
|
||||
// Initialiser le store
|
||||
var caStore storage.CertificateStore
|
||||
var certStore storage.CertificateStore
|
||||
|
||||
if cfg.StorageType == "mongodb" {
|
||||
// Connexion à MongoDB
|
||||
mongoStore, err := storage.NewMongoStore(cfg.MongoURI, cfg.MongoDB)
|
||||
if err != nil {
|
||||
log.Fatalf("❌ Erreur connexion MongoDB: %v", err)
|
||||
}
|
||||
defer mongoStore.Close()
|
||||
caStore = mongoStore
|
||||
certStore = mongoStore
|
||||
fmt.Printf("✅ Connecté à MongoDB: %s\n", cfg.MongoDB)
|
||||
} else {
|
||||
// Store mémoire (par défaut)
|
||||
memStore := storage.NewMemoryStore()
|
||||
caStore = memStore
|
||||
certStore = memStore
|
||||
fmt.Println("✅ Utilisation du store mémoire")
|
||||
}
|
||||
|
||||
// Ajouter les routes avec les stores
|
||||
api.RegisterRoutesWithStore(router, caStore, certStore)
|
||||
|
||||
// Démarrer le serveur
|
||||
port := ":" + cfg.Port
|
||||
fmt.Printf("🚀 API PKI démarrée sur %s\n", port)
|
||||
if err := router.Run(port); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user