de181afb7e1d76c969ab0ec23c0b71de5aa7f1e4
chmalee
  Fri Jul 18 11:25:13 2025 -0700
Fix hubspace pre-create hook to check for an apiKey only if a valid login cookie was not provided. Add a new hg.conf statement that allows for the data directory to be on a separate mount from the CGI, and swap strings around in the path appropriately to verify file existence when the file exists on another server

diff --git src/hg/hgHubConnect/hooks/pre-create.c src/hg/hgHubConnect/hooks/pre-create.c
index 357e42a0197..d107bb89f2b 100644
--- src/hg/hgHubConnect/hooks/pre-create.c
+++ src/hg/hgHubConnect/hooks/pre-create.c
@@ -62,34 +62,41 @@
         char *request = lineFileReadAll(lf);
         struct jsonElement *req = jsonParse(request);
         fprintf(stderr, "Hook request:\n");
         jsonPrintToFile(req, NULL, stderr, 0);
         char *reqCookie= jsonQueryString(req, "", "Event.HTTPRequest.Header.Cookie[0]", NULL);
         if (reqCookie)
             {
             setenv("HTTP_COOKIE", reqCookie, 0);
             }
         fprintf(stderr, "reqCookie='%s'\n", reqCookie);
         char *userName = getUserName();
         if (!userName)
             {
             // maybe an apiKey was provided, use that instead to look up the userName
             char *apiKey = jsonQueryString(req, "", "Event.Upload.MetaData.apiKey", NULL);
+            if (!apiKey)
+                {
+                errAbort("You are not logged in. Please navigate to My Data -> My Sessions and log in or create an account.");
+                }
+            else
+                {
                 userName = userNameForApiKey(apiKey);
                 if (!userName)
                     errAbort("You are not logged in. Please navigate to My Data -> My Sessions and log in or create an account.");
                 }
+            }
         fprintf(stderr, "userName='%s'\n'", userName);
         long reqFileSize = jsonQueryInt(req, "", "Event.Upload.Size", 0, NULL);
         char *reqFileName = jsonQueryString(req, "", "Event.Upload.MetaData.fileName", NULL);
         char *reqParentDir = jsonQueryString(req, "", "Event.Upload.MetaData.parentDir", NULL);
         boolean isHubToolsUpload = FALSE;
         char *hubtoolsStr = jsonQueryString(req, "", "Event.Upload.MetaData.hubtools", NULL);
         if (hubtoolsStr)
             isHubToolsUpload = sameString(hubtoolsStr, "TRUE") || sameString(hubtoolsStr, "true");
         long currQuota = checkUserQuota(userName);
         long newQuota = currQuota + reqFileSize;
         long maxQuota = getMaxUserQuota(userName);
         if (newQuota > maxQuota)
             {
             errAbort("File '%s' is too large, need %s free space but current used space is %s out of %s", reqFileName, prettyFileSize(reqFileSize), prettyFileSize(currQuota), prettyFileSize(maxQuota));
             }