diff --git a/.gitignore b/.gitignore index 99adeb7..b23009b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ scm go.sum +certs diff --git a/api/RootCert.go b/api/RootCert.go new file mode 100644 index 0000000..ce031c3 --- /dev/null +++ b/api/RootCert.go @@ -0,0 +1,35 @@ +package api + +import ( + "encoding/json" + "fmt" + "net/http" + "os" + "scm/model" +) + +func RootCert(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case "GET": + _, err := os.Stat(fmt.Sprintf("%s/%s", os.Getenv("CERTS_PATH"), "root/root.crt")) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + fmt.Fprintf(w, `{"status":"ok"}`) + case "POST": + var rootCertRequest model.CreateRootCertRequest + err := json.NewDecoder(r.Body).Decode(&rootCertRequest) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + + + fmt.Fprintf(w, `{"status":"ok"}`) + default: + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + } +} diff --git a/api/frontend/index.html b/api/frontend/index.html index 0d5cfa6..800d4ba 100644 --- a/api/frontend/index.html +++ b/api/frontend/index.html @@ -305,5 +305,87 @@ +