0dab88f8198e8e8d35bbb65673186ad8df1a7f64 max Thu Nov 7 06:49:40 2024 -0800 adding API key section to hgHubConnect, for the "hubtools up" command, refs #34405 diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c index 2f7c769..d8c7b6c 100644 --- src/hg/hgHubConnect/hgHubConnect.c +++ src/hg/hgHubConnect/hgHubConnect.c @@ -18,31 +18,31 @@ #include "cart.h" #include "dbDb.h" #include "web.h" #include "trackHub.h" #include "hubConnect.h" #include "dystring.h" #include "hPrint.h" #include "jsHelper.h" #include "obscure.h" #include "hgConfig.h" #include "trix.h" #include "net.h" #include "hubSearchText.h" #include "pipeline.h" #include "hubPublic.h" - +#include "wikiLink.h" static boolean measureTiming; struct cart *cart; /* The user's ui state. */ struct hash *oldVars = NULL; static char *pageTitle = "Track Data Hubs"; char *database = NULL; char *organism = NULL; struct hubOutputStructure { struct hubOutputStructure *next; struct dyString *metaTags; struct dyString *descriptionMatch; @@ -403,30 +403,53 @@ jsInlineF("%s", line); pipelineClose(&pl); // the 'false' below prevents a few hub-search specific jstree configuration options jsInline("hubSearchTree.init(false);"); } errCatchEnd(errCatch); if (errCatch->gotError || errCatch->gotWarning) { printf("hubCheck timed out after running for %d minute%s. Please try on a Unix command line", hubCheckTimeout / 60, hubCheckTimeout/60 > 1 ? "s" : ""); ret = 1; } errCatchFree(&errCatch); return ret; } +void printApiKeySection() +{ +puts("<div id='apiKey' class='tabSection'>"); +puts("<h4>Hubtools API key</h4>"); +char *userName = wikiLinkUserName(); +char *userId = wikiLinkUserId(); +if (userName==NULL || userId==NULL) + { + char *hgsid = cartSessionId(cart); + char *loginUrl = wikiLinkUserLoginUrlReturning(hgsid, wikiLinkEncodeReturnUrl(hgsid, "hgHubConnect", "#dev")); + printf("<div class='help'>You are not logged in. Please <a href='%s'>Login</a> now, then this page will show the API key.</div>", loginUrl); + } +else + { + puts("<div class='help'>To use the <tt>hubtools up</tt> command, create a file ~/.hubtools.conf and add this line:</div>"); + puts("<div style='margin-left: 15px; font-family: monospace'>"); + printf("apiKey='%s@%s'", userName, userId); + puts("</div>"); + } + +puts("</div>"); // tabSection apiKey +} + void hgHubConnectDeveloperMode() /* Put up the controls for the "Hub Development" Tab, which includes a button to run the * hubCheck utility on a hub and load a hub with the udcTimeout and measureTiming * variables turned on */ { // put out the top of our page char *hubUrl = cartOptionalString(cart, "validateHubUrl"); // the outer div for all the elements in the tab puts("<div id=\"hubDeveloper\" class=\"hubList\">"); char *hubUrlVal = ""; if (hubUrl != NULL) hubUrlVal = catThreeStrings(" value='", hubUrl, "'"); @@ -495,33 +518,38 @@ { timeLabel = "Hide timings"; timeVal = ""; timeDesc = "Shows loading time in milliseconds for each track, to help debug performance problems."; timeStatus = "ON"; } printf("<b style='font-size:90%%'>Show load times: %s</b> ", timeStatus); printf("<button type='submit' name='measureTiming' value='%s'>Change to: %s</button>", timeVal, timeLabel); printf("<div class='help'>Current setting: %s</div>\n", timeDesc); puts("</FORM>"); puts("</div>"); // margin-left puts("</div>"); // tabSection -puts("</div>"); // #hubDeveloper jsOnEventById("click", "hubValidateButton", "makeIframe(event)"); + +// API Key section +if (cfgOptionBooleanDefault("showHubApiKey", FALSE)) // This should probably not be shown on mirrors, so default to FALSE + printApiKeySection(); +puts("</div>"); // hub developement tab + } void printSearchAndFilterBoxes(int searchEnabled, char *hubSearchTerms, char *dbFilter) /* Create the text boxes for search and database filtering along with the required * javscript */ { printf("<FORM ACTION=\"%s\" NAME=\"searchHubForm\">\n", "../cgi-bin/hgHubConnect"); if (searchEnabled) { cgiMakeHiddenVar(hgHubDoSearch, "on"); cgiMakeHiddenVar(hgHubDbFilter, ""); cartSaveSession(cart); printf("The list below can be filtered on words in the hub description pages or by assemblies.<BR>" "Search terms: "