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
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -301,6 +301,14 @@ namespace SpiceQL {
   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
    *
+12 −10
Original line number Diff line number Diff line
@@ -152,30 +152,32 @@ namespace SpiceQL {
    json spiceAPIQuery(std::string functionName, json args, std::string method){
        restincurl::Client client;
        // 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;

        if (method == "GET"){
            std::cout << "[RestfulSpice] spiceAPIQuery GET" << std::endl;
            queryString += "?";
            SPDLOG_TRACE("spiceAPIQuery GET");
            for (auto x : args.items()) {
                if (x.value().is_null()) {
                    continue;
                }
                queryString+= x.key();
                queryString+= "=";
                queryString+= x.value().dump();
                queryString+= "&";
            }
            
            SPDLOG_TRACE("queryString = {}", 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) {
            SPDLOG_TRACE("spiceAPIQuery GET result body = {}", result.body);
            SPDLOG_TRACE("GET result body = {}", result.body);
            j = json::parse(result.body);
            }).ExecuteSynchronous();
        } 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) {
            SPDLOG_TRACE("spiceAPIQuery POST result = {}", result.body);
            SPDLOG_TRACE("POST result = {}", result.body);
            j = json::parse(result.body);
            }).ExecuteSynchronous();
        }
+13 −0
Original line number Diff line number Diff line
@@ -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) {
    SPDLOG_TRACE("IN resolveConfigDependencies");
    vector<json::json_pointer> depLists = findKeyInJson(config, "deps");
+2 −4
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ async def getTargetOrientations(
    toFrame: int,
    refFrame: int,
    mission: str,
    ets: str | None = None,
    ets: Annotated[list[float], Query()] | float | str | None = [],
    startEts: 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,
@@ -172,7 +172,6 @@ async def strSclkToEt(
    frameCode: int,
    sclk: str,
    mission: str,
    useWeb: bool = False,
    searchKernels: bool = True,
    kernelList: Annotated[list[str], Query()] | str | None = []):
    try:
@@ -351,7 +350,6 @@ async def frameTrace(
        ckQualities = strToList(ckQualities)
        kernelList = strToList(kernelList)
        result, kernels = pyspiceql.frameTrace(et, initialFrame, mission, ckQualities, False, searchKernels, kernelList)
        print("frameTrace result = " + str(result))
        body = ResultModel(result=result, kernels=kernels)
        return ResponseModel(statusCode=200, body=body)
    except Exception as e:
@@ -418,7 +416,7 @@ def strToList(value: str) -> list:
    # Converts a string into a list or its literal value
    if value is not None:
        if isinstance(value, str):
            value = literal_eval(value)
            value = value.replace("[", "").replace("]", "").split(",")
        else:
            try:
                iter(value)