Skip to content
Snippets Groups Projects
Unverified Commit 26c1789b authored by Christine Kim's avatar Christine Kim Committed by GitHub
Browse files

Bugfixes (#55)

* Add rest url env var option

* Fix strToList bug
parent d952cb94
Branches
Tags
No related merge requests found
...@@ -301,6 +301,14 @@ namespace SpiceQL { ...@@ -301,6 +301,14 @@ namespace SpiceQL {
std::string getMissionKeys(nlohmann::json config); std::string getMissionKeys(nlohmann::json config);
/**
* @brief Returns the REST URL
*
* @returns SpiceQL's REST URL as string
**/
std::string getRestUrl();
/** /**
* @brief resolve the dependencies in a config in place * @brief resolve the dependencies in a config in place
* *
......
...@@ -152,30 +152,32 @@ namespace SpiceQL { ...@@ -152,30 +152,32 @@ namespace SpiceQL {
json spiceAPIQuery(std::string functionName, json args, std::string method){ json spiceAPIQuery(std::string functionName, json args, std::string method){
restincurl::Client client; restincurl::Client client;
// Need to be able to set URL externally // Need to be able to set URL externally
std::string queryString = "http://127.0.0.1:8080/" + functionName; std::string queryString = "http://127.0.0.1:8080/" + functionName + "?";
json j; json j;
if (method == "GET"){ if (method == "GET"){
std::cout << "[RestfulSpice] spiceAPIQuery GET" << std::endl; SPDLOG_TRACE("spiceAPIQuery GET");
queryString += "?";
for (auto x : args.items()) { for (auto x : args.items()) {
if (x.value().is_null()) {
continue;
}
queryString+= x.key(); queryString+= x.key();
queryString+= "="; queryString+= "=";
queryString+= x.value().dump(); queryString+= x.value().dump();
queryString+= "&"; queryString+= "&";
} }
SPDLOG_TRACE("queryString = {}", queryString);
std::string encodedString = url_encode(queryString); std::string encodedString = url_encode(queryString);
SPDLOG_TRACE("spiceAPIQuery encodedString = {}", encodedString); SPDLOG_TRACE("encodedString = {}", encodedString);
client.Build()->Get(encodedString).Option(CURLOPT_FOLLOWLOCATION, 1L).AcceptJson().WithCompletion([&](const restincurl::Result& result) { client.Build()->Get(encodedString).Option(CURLOPT_FOLLOWLOCATION, 1L).AcceptJson().WithCompletion([&](const restincurl::Result& result) {
SPDLOG_TRACE("spiceAPIQuery GET result body = {}", result.body); SPDLOG_TRACE("GET result body = {}", result.body);
j = json::parse(result.body); j = json::parse(result.body);
}).ExecuteSynchronous(); }).ExecuteSynchronous();
} else { } else {
SPDLOG_TRACE("spiceAPIQuery POST"); SPDLOG_TRACE("POST");
client.Build()->Post(queryString).Option(CURLOPT_FOLLOWLOCATION, 1L).AcceptJson().WithJson(args.dump()).WithCompletion([&](const restincurl::Result& result) { client.Build()->Post(queryString).Option(CURLOPT_FOLLOWLOCATION, 1L).AcceptJson().WithJson(args.dump()).WithCompletion([&](const restincurl::Result& result) {
SPDLOG_TRACE("spiceAPIQuery POST result = {}", result.body); SPDLOG_TRACE("POST result = {}", result.body);
j = json::parse(result.body); j = json::parse(result.body);
}).ExecuteSynchronous(); }).ExecuteSynchronous();
} }
......
...@@ -1215,6 +1215,19 @@ namespace SpiceQL { ...@@ -1215,6 +1215,19 @@ namespace SpiceQL {
} }
string getRestUrl() {
char* spiceqlRestUrlEnvVar = std::getenv("SPICEQL_REST_URL");
string spiceqlRestUrl;
if (spiceqlRestUrlEnvVar == NULL) {
spiceqlRestUrl = "https://astrogeology.usgs.gov/apis/spiceq/latest/";
} else {
spiceqlRestUrl = string(spiceqlRestUrlEnvVar);
}
SPDLOG_TRACE("SpiceQL REST URL: {}", spiceqlRestUrl);
return spiceqlRestUrl;
}
void resolveConfigDependencies(json &config, const json &dependencies) { void resolveConfigDependencies(json &config, const json &dependencies) {
SPDLOG_TRACE("IN resolveConfigDependencies"); SPDLOG_TRACE("IN resolveConfigDependencies");
vector<json::json_pointer> depLists = findKeyInJson(config, "deps"); vector<json::json_pointer> depLists = findKeyInJson(config, "deps");
......
...@@ -138,7 +138,7 @@ async def getTargetOrientations( ...@@ -138,7 +138,7 @@ async def getTargetOrientations(
toFrame: int, toFrame: int,
refFrame: int, refFrame: int,
mission: str, mission: str,
ets: str | None = None, ets: Annotated[list[float], Query()] | float | str | None = [],
startEts: Annotated[list[float], Query()] | float | str | None = None, startEts: Annotated[list[float], Query()] | float | str | None = None,
stopEts: Annotated[list[float], Query()] | float | str | None = None, stopEts: Annotated[list[float], Query()] | float | str | None = None,
exposureDuration: Annotated[list[float], Query()] | float | str | None = None, exposureDuration: Annotated[list[float], Query()] | float | str | None = None,
...@@ -172,7 +172,6 @@ async def strSclkToEt( ...@@ -172,7 +172,6 @@ async def strSclkToEt(
frameCode: int, frameCode: int,
sclk: str, sclk: str,
mission: str, mission: str,
useWeb: bool = False,
searchKernels: bool = True, searchKernels: bool = True,
kernelList: Annotated[list[str], Query()] | str | None = []): kernelList: Annotated[list[str], Query()] | str | None = []):
try: try:
...@@ -351,7 +350,6 @@ async def frameTrace( ...@@ -351,7 +350,6 @@ async def frameTrace(
ckQualities = strToList(ckQualities) ckQualities = strToList(ckQualities)
kernelList = strToList(kernelList) kernelList = strToList(kernelList)
result, kernels = pyspiceql.frameTrace(et, initialFrame, mission, ckQualities, False, searchKernels, kernelList) result, kernels = pyspiceql.frameTrace(et, initialFrame, mission, ckQualities, False, searchKernels, kernelList)
print("frameTrace result = " + str(result))
body = ResultModel(result=result, kernels=kernels) body = ResultModel(result=result, kernels=kernels)
return ResponseModel(statusCode=200, body=body) return ResponseModel(statusCode=200, body=body)
except Exception as e: except Exception as e:
...@@ -418,7 +416,7 @@ def strToList(value: str) -> list: ...@@ -418,7 +416,7 @@ def strToList(value: str) -> list:
# Converts a string into a list or its literal value # Converts a string into a list or its literal value
if value is not None: if value is not None:
if isinstance(value, str): if isinstance(value, str):
value = literal_eval(value) value = value.replace("[", "").replace("]", "").split(",")
else: else:
try: try:
iter(value) iter(value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment