mirror of
https://github.com/Xevion/banner.git
synced 2025-12-06 01:14:22 -06:00
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"banner/internal"
|
|
"net/url"
|
|
|
|
log "github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// Setup makes the initial requests to set up the session cookies for the application.
|
|
func (a *API) Setup() {
|
|
// Makes the initial requests that sets up the session cookies for the rest of the application
|
|
log.Info().Msg("Setting up session...")
|
|
|
|
requestQueue := []string{
|
|
"/registration/registration",
|
|
"/selfServiceMenu/data",
|
|
}
|
|
|
|
for _, path := range requestQueue {
|
|
req := a.config.Client.NewRequest().
|
|
SetQueryParam("_", internal.Nonce()).
|
|
SetExpectResponseContentType("application/json")
|
|
|
|
res, err := req.Get(path)
|
|
if err != nil {
|
|
log.Fatal().Stack().Str("path", path).Err(err).Msg("Failed to make request")
|
|
}
|
|
|
|
if res.StatusCode() != 200 {
|
|
log.Fatal().Stack().Str("path", path).Int("status", res.StatusCode()).Msg("Failed to make request")
|
|
}
|
|
}
|
|
|
|
// Validate that cookies were set
|
|
baseURLParsed, err := url.Parse(a.config.BaseURL)
|
|
if err != nil {
|
|
log.Fatal().Stack().Str("baseURL", a.config.BaseURL).Err(err).Msg("Failed to parse baseURL")
|
|
}
|
|
|
|
currentCookies := a.config.Client.CookieJar().Cookies(baseURLParsed)
|
|
requiredCookies := map[string]bool{
|
|
"JSESSIONID": false,
|
|
"SSB_COOKIE": false,
|
|
}
|
|
|
|
for _, cookie := range currentCookies {
|
|
_, present := requiredCookies[cookie.Name]
|
|
// Check if this cookie is required
|
|
if present {
|
|
requiredCookies[cookie.Name] = true
|
|
}
|
|
}
|
|
|
|
// Check if all required cookies were set
|
|
for cookieName, cookieSet := range requiredCookies {
|
|
if !cookieSet {
|
|
log.Warn().Str("cookieName", cookieName).Msg("Required cookie not set")
|
|
}
|
|
}
|
|
log.Debug().Msg("All required cookies set, session setup complete")
|
|
|
|
// TODO: Validate that the session allows access to termSelection
|
|
}
|