From 814d20675daaa32c211f1e97a42fa4fa121c070f Mon Sep 17 00:00:00 2001 From: Kyle Lawson_ONS <108286538+kylelawsonAND@users.noreply.github.com> Date: Fri, 21 Jul 2023 11:17:06 +0100 Subject: [PATCH] Aligning SDS API Base URL naming with runner (#51) --- settings/settings.go | 2 +- surveys/surveys.go | 39 +++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/settings/settings.go b/settings/settings.go index 95248064..ff11e3b2 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -20,7 +20,7 @@ func init() { setSetting("SURVEY_RUNNER_SCHEMA_URL", Get("SURVEY_RUNNER_URL")) setSetting("SCHEMA_VALIDATOR_URL", "") setSetting("SURVEY_REGISTER_URL", "") - setSetting("SDS_API_URL", "http://localhost:5003") + setSetting("SDS_API_BASE_URL", "http://localhost:5003") setSetting("JWT_ENCRYPTION_KEY_PATH", "jwt-test-keys/sdc-user-authentication-encryption-sr-public-key.pem") setSetting("JWT_SIGNING_KEY_PATH", "jwt-test-keys/sdc-user-authentication-signing-launcher-private-key.pem") } diff --git a/surveys/surveys.go b/surveys/surveys.go index 740166ef..fb6013ee 100644 --- a/surveys/surveys.go +++ b/surveys/surveys.go @@ -188,12 +188,12 @@ func FindSurveyByName(name string) LauncherSchema { func GetSupplementaryDataSets(surveyId string, periodId string) ([]DatasetMetadata, error) { datasetList := []DatasetMetadata{} - hostURL := settings.Get("SDS_API_URL") - log.Printf("SDS Api URL: %s", hostURL) + hostURL := settings.Get("SDS_API_BASE_URL") + log.Printf("SDS API Base URL: %s", hostURL) url := fmt.Sprintf("%s/v1/dataset_metadata?survey_id=%s&period_id=%s", hostURL, surveyId, periodId) resp, err := clients.GetHTTPClient().Get(url) - if err != nil || (resp.StatusCode != 200 && resp.StatusCode != 404){ + if err != nil || (resp.StatusCode != 200 && resp.StatusCode != 404) { return datasetList, errors.New("unable to fetch supplementary data") } if resp.StatusCode == 404 { @@ -214,21 +214,20 @@ func GetSupplementaryDataSets(surveyId string, periodId string) ([]DatasetMetada // Return a LauncherSchema instance by loading schema from name or URL func GetLauncherSchema(schemaName string, schemaUrl string) LauncherSchema { - var launcherSchema LauncherSchema - - if schemaUrl != "" { - log.Println("Getting schema by URL: " + schemaUrl) - launcherSchema = LauncherSchema { - URL: schemaUrl, - Name: schemaName, - } - } else if schemaName != "" { - log.Println("Searching for schema by name: " + schemaName) - launcherSchema = FindSurveyByName(schemaName) - } else { - panic("Either `schema_name` or `schema_url` must be provided.") - } - - return launcherSchema -} + var launcherSchema LauncherSchema + if schemaUrl != "" { + log.Println("Getting schema by URL: " + schemaUrl) + launcherSchema = LauncherSchema{ + URL: schemaUrl, + Name: schemaName, + } + } else if schemaName != "" { + log.Println("Searching for schema by name: " + schemaName) + launcherSchema = FindSurveyByName(schemaName) + } else { + panic("Either `schema_name` or `schema_url` must be provided.") + } + + return launcherSchema +}