Skip to content
Snippets Groups Projects
akms-simulator.go 820 B
Newer Older
  • Learn to ignore specific revisions
  • package main
    
    import (
    	"io/ioutil"
    	"log"
    	"net/http"
    
    
    	"github.com/sirupsen/logrus"
    
    )
    
    func main() {
    
    	logrus.Info("Starting AKMS Simulator...")
    
    	http.HandleFunc("/api/v1/keys/push_ksa_key", handlePushKsaKey)
    
    	log.Fatal(http.ListenAndServe(":4444", nil))
    }
    
    func handlePushKsaKey(w http.ResponseWriter, r *http.Request) {
    	if r.Method != http.MethodPost {
    		http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
    
    		logrus.Errorf("Method not allowed: %s", r.Method)
    
    		return
    	}
    
    	body, err := ioutil.ReadAll(r.Body)
    	if err != nil {
    		http.Error(w, "Failed to read request body", http.StatusInternalServerError)
    
    		logrus.Errorf("Failed to read request body: %s", err)
    
    		return
    	}
    
    	ip := r.RemoteAddr
    
    	logrus.Info("Request came from: " + ip + "; Body: " + string(body))
    	w.WriteHeader(http.StatusNoContent)