Compare commits

...

2 Commits

Author SHA1 Message Date
789805b587 Mod tidy
All checks were successful
continuous-integration/drone Build is passing
2025-03-22 21:28:27 +11:00
6b2b60b9ef more code 2025-03-22 21:28:09 +11:00
5 changed files with 42 additions and 6 deletions

3
go.mod
View File

@@ -5,6 +5,7 @@ go 1.24.1
require (
github.com/a-h/templ v0.3.833
github.com/go-co-op/gocron/v2 v2.16.1
github.com/google/uuid v1.6.0
github.com/jmoiron/sqlx v1.4.0
github.com/joho/godotenv v1.5.1
github.com/pressly/goose/v3 v3.24.1
@@ -14,10 +15,8 @@ require (
require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jonboulle/clockwork v0.5.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mfridman/interpolate v0.0.2 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect

View File

@@ -24,7 +24,8 @@ func GenerateCerts(tlsCert string, tlsKey string) {
// Get the hostname
hostname, err := os.Hostname()
if err != nil {
panic(err)
log.Printf("failed to lookup hostname: '%s'\n", err)
hostname = "localhost"
}
// Check that the directory exists

View 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)
}

View File

@@ -9,12 +9,14 @@ import (
"mocksnow/db/queries"
"mocksnow/server/models"
"net/http"
"os"
"github.com/google/uuid"
)
// NewSnow receives data from the DMSP Snow New() function
func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
var hostname string
reqBody, err := io.ReadAll(r.Body)
if err != nil {
@@ -82,7 +84,15 @@ func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
// Simulate response
ticket := fmt.Sprintf("TKT%06d", incidentRecord)
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{
ImportSet: randomImportSet(),

View File

@@ -2,13 +2,13 @@ package router
import (
"log/slog"
"net/http"
"net/http/pprof"
"mocksnow/db"
"mocksnow/dist"
"mocksnow/internal/settings"
"mocksnow/server/handler"
"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 {
@@ -29,6 +29,7 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st
mux.HandleFunc("/", h.Home)
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/modify", h.VmModifyEvent)