Save a copy of the Fieldseeker schema on oauth connect

This will make it easier to debug when we get a new customer which
schema elements are in common and which are specific to Delta.
This commit is contained in:
Eli Ribble 2025-12-02 00:30:08 +00:00
parent 7c4fb02908
commit ff7c5cdb6b
No known key found for this signature in database
3 changed files with 33 additions and 2 deletions

View file

@ -85,6 +85,31 @@ func buildArcGISAuthURL(clientID string) string {
return baseURL + "?" + params.Encode()
}
func downloadFieldseekerSchema(ctx context.Context, fieldseekerClient *fieldseeker.FieldSeeker, arcgis_id string) {
for _, layer := range fieldseekerClient.FeatureServerLayers() {
err := os.MkdirAll(filepath.Join(FieldseekerSchemaDirectory, arcgis_id), os.ModePerm)
if err != nil {
log.Error().Err(err).Msg("Failed to create parent directory")
return
}
output, err := os.Create(fmt.Sprintf("%s/%s/%s.json", FieldseekerSchemaDirectory, arcgis_id, layer.Name))
if err != nil {
log.Error().Err(err).Msg("Failed to open output")
return
}
schema, err := fieldseekerClient.Schema(layer.ID)
if err != nil {
log.Error().Err(err).Msg("Failed to get schema")
return
}
_, err = output.Write(schema)
if err != nil {
log.Error().Err(err).Msg("Failed to write schema file")
continue
}
}
}
func futureUTCTimestamp(secondsFromNow int) time.Time {
return time.Now().UTC().Add(time.Duration(secondsFromNow) * time.Second)
}
@ -195,6 +220,7 @@ func updateArcgisUserData(ctx context.Context, user *models.User, access_token s
}
client.Context = &arcgis_id
maybeCreateWebhook(ctx, fieldseekerClient)
downloadFieldseekerSchema(ctx, fieldseekerClient, arcgis_id)
clearNotificationsOauth(ctx, user)
NewOAuthTokenChannel <- struct{}{}
}

2
db/bob

@ -1 +1 @@
Subproject commit 96da65fd88a50ae532079e8ea69746183f4af3a1
Subproject commit 8e41efed4f7ea4782ee7c2d06e2643967cce71d7

View file

@ -21,7 +21,7 @@ import (
var sessionManager *scs.SessionManager
var BaseURL, ClientID, ClientSecret, Environment, MapboxToken string
var BaseURL, ClientID, ClientSecret, Environment, FieldseekerSchemaDirectory, MapboxToken string
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
@ -65,6 +65,11 @@ func main() {
log.Error().Msg("You must specify a non-empty POSTGRES_DSN")
os.Exit(1)
}
FieldseekerSchemaDirectory = os.Getenv("FIELDSEEKER_SCHEMA_DIRECTORY")
if FieldseekerSchemaDirectory == "" {
log.Error().Msg("You must specify a non-empty FIELDSEEKER_SCHEMA_DIRECTORY")
os.Exit(1)
}
log.Info().Msg("Starting...")
err := db.InitializeDatabase(context.TODO(), pg_dsn)