more code
This commit is contained in:
@@ -24,7 +24,8 @@ func GenerateCerts(tlsCert string, tlsKey string) {
|
|||||||
// Get the hostname
|
// Get the hostname
|
||||||
hostname, err := os.Hostname()
|
hostname, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Printf("failed to lookup hostname: '%s'\n", err)
|
||||||
|
hostname = "localhost"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the directory exists
|
// Check that the directory exists
|
||||||
|
25
server/handler/getIncident.go
Normal file
25
server/handler/getIncident.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetIncident responds to the link generated in the response to a New Snow
|
||||||
|
func (h *Handler) GetIncident(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
path := r.URL.Path
|
||||||
|
// Expected format: /api/now/table/incident/{id}
|
||||||
|
parts := strings.Split(path, "/")
|
||||||
|
|
||||||
|
if len(parts) != 6 || parts[1] != "api" || parts[2] != "now" || parts[3] != "table" || parts[4] != "incident" {
|
||||||
|
http.NotFound(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
id := parts[5] // Extract {id}
|
||||||
|
fmt.Fprintf(w, "Incident ID: %s", id)
|
||||||
|
}
|
@@ -9,12 +9,14 @@ import (
|
|||||||
"mocksnow/db/queries"
|
"mocksnow/db/queries"
|
||||||
"mocksnow/server/models"
|
"mocksnow/server/models"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewSnow receives data from the DMSP Snow New() function
|
// NewSnow receives data from the DMSP Snow New() function
|
||||||
func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var hostname string
|
||||||
|
|
||||||
reqBody, err := io.ReadAll(r.Body)
|
reqBody, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -82,7 +84,15 @@ func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Simulate response
|
// Simulate response
|
||||||
ticket := fmt.Sprintf("TKT%06d", incidentRecord)
|
ticket := fmt.Sprintf("TKT%06d", incidentRecord)
|
||||||
sysID := uuid.New().String()
|
sysID := uuid.New().String()
|
||||||
recordLink := "https://server.fqdn.com/api/now/table/incident/" + sysID
|
|
||||||
|
// Produce dummy record link
|
||||||
|
hostname, err = os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
h.Logger.Error("failed to lookup hostname", "error", err)
|
||||||
|
hostname = "localhost"
|
||||||
|
}
|
||||||
|
|
||||||
|
recordLink := fmt.Sprintf("https://%s/api/now/table/incident/%s", hostname, sysID)
|
||||||
|
|
||||||
response := models.IncidentResponse{
|
response := models.IncidentResponse{
|
||||||
ImportSet: randomImportSet(),
|
ImportSet: randomImportSet(),
|
||||||
|
@@ -2,13 +2,13 @@ package router
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
|
||||||
"net/http/pprof"
|
|
||||||
"mocksnow/db"
|
"mocksnow/db"
|
||||||
"mocksnow/dist"
|
"mocksnow/dist"
|
||||||
"mocksnow/internal/settings"
|
"mocksnow/internal/settings"
|
||||||
"mocksnow/server/handler"
|
"mocksnow/server/handler"
|
||||||
"mocksnow/server/middleware"
|
"mocksnow/server/middleware"
|
||||||
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver string, goVersion string, settings *settings.Settings) http.Handler {
|
func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver string, goVersion string, settings *settings.Settings) http.Handler {
|
||||||
@@ -29,6 +29,7 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st
|
|||||||
mux.HandleFunc("/", h.Home)
|
mux.HandleFunc("/", h.Home)
|
||||||
|
|
||||||
mux.HandleFunc("/api/now/import/x_dusa2_itom_inc_imp", h.NewSnow)
|
mux.HandleFunc("/api/now/import/x_dusa2_itom_inc_imp", h.NewSnow)
|
||||||
|
mux.HandleFunc("/api/now/table/incident/", h.GetIncident)
|
||||||
|
|
||||||
// mux.HandleFunc("/api/event/vm/create", h.VmCreateEvent)
|
// mux.HandleFunc("/api/event/vm/create", h.VmCreateEvent)
|
||||||
// mux.HandleFunc("/api/event/vm/modify", h.VmModifyEvent)
|
// mux.HandleFunc("/api/event/vm/modify", h.VmModifyEvent)
|
||||||
|
Reference in New Issue
Block a user