[ARVADOS] created: 1.1.2-278-gcfa10d9

Git user git at public.curoverse.com
Thu Feb 8 14:50:05 EST 2018


        at  cfa10d90137e49008c08bc88bf2b79d1429fd0f8 (commit)


commit cfa10d90137e49008c08bc88bf2b79d1429fd0f8
Author: Lucas Di Pentima <ldipentima at veritasgenetics.com>
Date:   Thu Feb 8 16:49:42 2018 -0300

    11454: Syntax errors fixes.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima at veritasgenetics.com>

diff --git a/apps/workbench/app/assets/javascripts/components/sessions.js b/apps/workbench/app/assets/javascripts/components/sessions.js
index 231db9b..8e947cb 100644
--- a/apps/workbench/app/assets/javascripts/components/sessions.js
+++ b/apps/workbench/app/assets/javascripts/components/sessions.js
@@ -3,28 +3,28 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 $(document).on('ready', function() {
-    var db = new SessionDB()
-    db.checkForNewToken()
-    db.fillMissingUUIDs()
-    db.migrateNonFederatedSessions()
-    db.autoLoadRemoteHosts()
-})
+    var db = new SessionDB();
+    db.checkForNewToken();
+    db.fillMissingUUIDs();
+    db.migrateNonFederatedSessions();
+    db.autoLoadRemoteHosts();
+});
 
 window.SessionsTable = {
     oninit: function(vnode) {
-        vnode.state.db = new SessionDB()
-        vnode.state.hostToAdd = m.stream('')
-        vnode.state.error = m.stream()
-        vnode.state.checking = m.stream()
+        vnode.state.db = new SessionDB();
+        vnode.state.hostToAdd = m.stream('');
+        vnode.state.error = m.stream();
+        vnode.state.checking = m.stream();
     },
     view: function(vnode) {
-        var db = vnode.state.db
-        var sessions = db.loadAll()
+        var db = vnode.state.db;
+        var sessions = db.loadAll();
         return m('.container', [
             m('p', [
                 'You can log in to multiple Arvados sites here, then use the ',
                 m('a[href="/search"]', 'multi-site search'),
-                ' page to search collections and projects on all sites at once.',
+                ' page to search collections and projects on all sites at once.'
             ]),
             m('table.table.table-condensed.table-hover', [
                 m('thead', m('tr', [
@@ -33,7 +33,7 @@ window.SessionsTable = {
                     m('th', 'username'),
                     m('th', 'email'),
                     m('th', 'actions'),
-                    m('th'),
+                    m('th')
                 ])),
                 m('tbody', [
                     Object.keys(sessions).map(function(uuidPrefix) {
@@ -46,14 +46,14 @@ window.SessionsTable = {
                                 m('td', {title: session.baseURL}, [
                                     m('a', {
                                         href: db.workbenchBaseURL(session) + '?api_token=' + session.token
-                                    }, uuidPrefix),
+                                    }, uuidPrefix)
                                 ]),
                                 m('td', session.user.username),
                                 m('td', session.user.email),
                                 m('td', session.isFromRails ? null : m('button.btn.btn-xs.btn-default', {
                                     uuidPrefix: uuidPrefix,
                                     onclick: m.withAttr('uuidPrefix', db.logout),
-                                }, session.listedHost ? 'Disable ':'Log out ', m('span.glyphicon.glyphicon-log-out'))),
+                                }, session.listedHost ? 'Disable ':'Log out ', m('span.glyphicon.glyphicon-log-out')))
                             ] : [
                                 m('td', m('span.label.label-default', 'logged out')),
                                 m('td', {title: session.baseURL}, uuidPrefix),
@@ -62,7 +62,7 @@ window.SessionsTable = {
                                 m('td', m('a.btn.btn-xs.btn-primary', {
                                     uuidPrefix: uuidPrefix,
                                     onclick: db.login.bind(db, session.baseURL),
-                                }, session.listedHost ? 'Enable ':'Log in ', m('span.glyphicon.glyphicon-log-in'))),
+                                }, session.listedHost ? 'Enable ':'Log in ', m('span.glyphicon.glyphicon-log-in')))
                             ],
                             m('td', session.isFromRails ? null : m('button.btn.btn-xs.btn-default', {
                                 uuidPrefix: uuidPrefix,
diff --git a/apps/workbench/app/assets/javascripts/models/session_db.js b/apps/workbench/app/assets/javascripts/models/session_db.js
index f9e17b2..99768db 100644
--- a/apps/workbench/app/assets/javascripts/models/session_db.js
+++ b/apps/workbench/app/assets/javascripts/models/session_db.js
@@ -3,80 +3,85 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 window.SessionDB = function() {
-    var db = this
+    var db = this;
     Object.assign(db, {
         discoveryCache: {},
         tokenUUIDCache: null,
         loadFromLocalStorage: function() {
             try {
-                return JSON.parse(window.localStorage.getItem('sessions')) || {}
+                return JSON.parse(window.localStorage.getItem('sessions')) || {};
             } catch(e) {}
-            return {}
+            return {};
         },
         loadAll: function() {
-            var all = db.loadFromLocalStorage()
+            var all = db.loadFromLocalStorage();
             if (window.defaultSession) {
-                window.defaultSession.isFromRails = true
-                all[window.defaultSession.user.uuid.slice(0, 5)] = window.defaultSession
+                window.defaultSession.isFromRails = true;
+                all[window.defaultSession.user.uuid.slice(0, 5)] = window.defaultSession;
             }
-            return all
+            return all;
         },
         loadActive: function() {
-            var sessions = db.loadAll()
+            var sessions = db.loadAll();
             Object.keys(sessions).forEach(function(key) {
-                if (!sessions[key].token || (sessions[key].user && !sessions[key].user.is_active))
-                    delete sessions[key]
-            })
-            return sessions
+                if (!sessions[key].token || (sessions[key].user && !sessions[key].user.is_active)) {
+                    delete sessions[key];
+                }
+            });
+            return sessions;
         },
         loadLocal: function() {
-            var sessions = db.loadActive()
-            var s = false
-            Object.values(sessions).forEach(function(session) {
-                if (session.isFromRails) {
-                    s = session
-                    return
+            var sessions = db.loadActive();
+            var s = false;
+            Object.keys(sessions).forEach(function(key) {
+                if (sessions[key].isFromRails) {
+                    s = sessions[key];
+                    return;
                 }
-            })
-            return s
+            });
+            return s;
         },
         save: function(k, v) {
-            var sessions = db.loadAll()
-            sessions[k] = v
+            var sessions = db.loadAll();
+            sessions[k] = v;
             Object.keys(sessions).forEach(function(key) {
-                if (sessions[key].isFromRails)
-                    delete sessions[key]
-            })
-            window.localStorage.setItem('sessions', JSON.stringify(sessions))
+                if (sessions[key].isFromRails) {
+                    delete sessions[key];
+                }
+            });
+            window.localStorage.setItem('sessions', JSON.stringify(sessions));
         },
         trash: function(k) {
-            var sessions = db.loadAll()
-            delete sessions[k]
-            window.localStorage.setItem('sessions', JSON.stringify(sessions))
+            var sessions = db.loadAll();
+            delete sessions[k];
+            window.localStorage.setItem('sessions', JSON.stringify(sessions));
         },
         findAPI: function(url) {
             // Given a Workbench or API host or URL, return a promise
             // for the corresponding API server's base URL.  Typical
             // use:
             // sessionDB.findAPI('https://workbench.example/foo').then(sessionDB.login)
-            if (url.length === 5 && url.indexOf('.') < 0)
-                url += '.arvadosapi.com'
-            if (url.indexOf('://') < 0)
-                url = 'https://' + url
-            url = new URL(url)
+            if (url.length === 5 && url.indexOf('.') < 0) {
+                url += '.arvadosapi.com';
+            }
+            if (url.indexOf('://') < 0) {
+                url = 'https://' + url;
+            }
+            url = new URL(url);
             return m.request(url.origin + '/discovery/v1/apis/arvados/v1/rest').then(function() {
-                return url.origin + '/'
+                return url.origin + '/';
             }).catch(function(err) {
                 // If url is a Workbench site (and isn't too old),
                 // /status.json will tell us its API host.
                 return m.request(url.origin + '/status.json').then(function(resp) {
-                    if (!resp.apiBaseURL)
-                        throw 'no apiBaseURL in status response'
-                    return resp.apiBaseURL
-                })
-            })
+                    if (!resp.apiBaseURL) {
+                        throw 'no apiBaseURL in status response';
+                    }
+                    return resp.apiBaseURL;
+                });
+            });
         },
-        login: function(baseURL, fallbackLogin = true) {
+        login: function(baseURL, fallbackLogin) {
             // Initiate login procedure with given API base URL (e.g.,
             // "http://api.example/").
             //
@@ -84,9 +89,12 @@ window.SessionDB = function() {
             // also call checkForNewToken() on (at least) its first
             // render. Otherwise, the login procedure can't be
             // completed.
-            var session = db.loadLocal()
-            var uuidPrefix = session.user.owner_uuid.slice(0, 5)
-            var apiHostname = new URL(session.baseURL).hostname
+            if (fallbackLogin === undefined) {
+                fallbackLogin = true;
+            }
+            var session = db.loadLocal();
+            var uuidPrefix = session.user.owner_uuid.slice(0, 5);
+            var apiHostname = new URL(session.baseURL).hostname;
             m.request(session.baseURL+'discovery/v1/apis/arvados/v1/rest').then(function(localDD) {
                 m.request(baseURL+'discovery/v1/apis/arvados/v1/rest').then(function(dd) {
                     if (uuidPrefix in dd.remoteHosts ||
@@ -95,17 +103,17 @@ window.SessionDB = function() {
                         db.saltedToken(dd.uuidPrefix).then(function(token) {
                             m.request(baseURL+'arvados/v1/users/current', {
                                 headers: {
-                                    authorization: 'Bearer '+token,
-                                },
+                                    authorization: 'Bearer '+token
+                                }
                             }).then(function(user) {
                                 // Federated login successful.
                                 var remoteSession = {
                                     user: user,
                                     baseURL: baseURL,
                                     token: token,
-                                    listedHost: (dd.uuidPrefix in localDD.remoteHosts),
-                                }
-                                db.save(dd.uuidPrefix, remoteSession)
+                                    listedHost: (dd.uuidPrefix in localDD.remoteHosts)
+                                };
+                                db.save(dd.uuidPrefix, remoteSession);
                             }).catch(function(e) {
                                 if (dd.uuidPrefix in localDD.remoteHosts) {
                                     // If the remote system is configured to allow federated
@@ -113,170 +121,174 @@ window.SessionDB = function() {
                                     // token, save as a logged out session anyways.
                                     var remoteSession = {
                                         baseURL: baseURL,
-                                        listedHost: true,
-                                    }
-                                    db.save(dd.uuidPrefix, remoteSession)
+                                        listedHost: true
+                                    };
+                                    db.save(dd.uuidPrefix, remoteSession);
                                 } else if (fallbackLogin) {
                                     // Remote cluster not listed as a remote host and rejecting
                                     // the salted token, try classic login.
-                                    db.loginClassic(baseURL)
+                                    db.loginClassic(baseURL);
                                 }
-                            })
-                        })
+                            });
+                        });
                     } else if (fallbackLogin) {
                         // Classic login will be used when the remote system doesn't list this
                         // cluster as part of the federation.
-                        db.loginClassic(baseURL)
+                        db.loginClassic(baseURL);
                     }
-                })
-            })
-            return false
+                });
+            });
+            return false;
         },
         loginClassic: function(baseURL) {
-            document.location = baseURL + 'login?return_to=' + encodeURIComponent(document.location.href.replace(/\?.*/, '')+'?baseURL='+encodeURIComponent(baseURL))
+            document.location = baseURL + 'login?return_to=' + encodeURIComponent(document.location.href.replace(/\?.*/, '')+'?baseURL='+encodeURIComponent(baseURL));
         },
         logout: function(k) {
             // Forget the token, but leave the other info in the db so
             // the user can log in again without providing the login
             // host again.
-            var sessions = db.loadAll()
-            delete sessions[k].token
-            db.save(k, sessions[k])
+            var sessions = db.loadAll();
+            delete sessions[k].token;
+            db.save(k, sessions[k]);
         },
         saltedToken: function(uuid_prefix) {
             // Takes a cluster UUID prefix and returns a salted token to allow
             // log into said cluster using federated identity.
-            var session = db.loadLocal()
-            return db.tokenUUID().then(function(token_uuid){
-                var shaObj = new jsSHA("SHA-1", "TEXT")
-                shaObj.setHMACKey(session.token, "TEXT")
-                shaObj.update(uuid_prefix)
-                var hmac = shaObj.getHMAC("HEX")
-                return 'v2/' + token_uuid + '/' + hmac
-            })
+            var session = db.loadLocal();
+            return db.tokenUUID().then(function(token_uuid) {
+                var shaObj = new jsSHA("SHA-1", "TEXT");
+                shaObj.setHMACKey(session.token, "TEXT");
+                shaObj.update(uuid_prefix);
+                var hmac = shaObj.getHMAC("HEX");
+                return 'v2/' + token_uuid + '/' + hmac;
+            });
         },
         checkForNewToken: function() {
             // If there's a token and baseURL in the location bar (i.e.,
             // we just landed here after a successful login), save it and
             // scrub the location bar.
-            if (document.location.search[0] != '?')
-                return
-            var params = {}
+            if (document.location.search[0] != '?') { return; }
+            var params = {};
             document.location.search.slice(1).split('&').map(function(kv) {
-                var e = kv.indexOf('=')
-                if (e < 0)
-                    return
-                params[decodeURIComponent(kv.slice(0, e))] = decodeURIComponent(kv.slice(e+1))
-            })
-            if (!params.baseURL || !params.api_token)
+                var e = kv.indexOf('=');
+                if (e < 0) {
+                    return;
+                }
+                params[decodeURIComponent(kv.slice(0, e))] = decodeURIComponent(kv.slice(e+1));
+            });
+            if (!params.baseURL || !params.api_token) {
                 // Have a query string, but it's not a login callback.
-                return
-            params.token = params.api_token
-            delete params.api_token
-            db.save(params.baseURL, params)
-            history.replaceState({}, '', document.location.origin + document.location.pathname)
+                return;
+            }
+            params.token = params.api_token;
+            delete params.api_token;
+            db.save(params.baseURL, params);
+            history.replaceState({}, '', document.location.origin + document.location.pathname);
         },
         fillMissingUUIDs: function() {
-            var sessions = db.loadAll()
+            var sessions = db.loadAll();
             Object.keys(sessions).map(function(key) {
-                if (key.indexOf('://') < 0)
-                    return
+                if (key.indexOf('://') < 0) {
+                    return;
+                }
                 // key is the baseURL placeholder. We need to get our user
                 // record to find out the cluster's real uuid prefix.
-                var session = sessions[key]
+                var session = sessions[key];
                 m.request(session.baseURL+'arvados/v1/users/current', {
                     headers: {
-                        authorization: 'OAuth2 '+session.token,
-                    },
+                        authorization: 'OAuth2 '+session.token
+                    }
                 }).then(function(user) {
-                    session.user = user
-                    db.save(user.owner_uuid.slice(0, 5), session)
-                    db.trash(key)
-                })
-            })
+                    session.user = user;
+                    db.save(user.owner_uuid.slice(0, 5), session);
+                    db.trash(key);
+                });
+            });
         },
         // Return the Workbench base URL advertised by the session's
         // API server, or a reasonable guess, or (if neither strategy
         // works out) null.
         workbenchBaseURL: function(session) {
-            var dd = db.discoveryDoc(session)()
-            if (!dd)
+            var dd = db.discoveryDoc(session)();
+            if (!dd) {
                 // Don't fall back to guessing until we receive the discovery doc
-                return null
-            if (dd.workbenchUrl)
-                return dd.workbenchUrl
+                return null;
+            }
+            if (dd.workbenchUrl) {
+                return dd.workbenchUrl;
+            }
             // Guess workbench.{apihostport} is a Workbench... unless
             // the host part of apihostport is an IPv4 or [IPv6]
             // address.
             if (!session.baseURL.match('://(\\[|\\d+\\.\\d+\\.\\d+\\.\\d+[:/])')) {
-                var wbUrl = session.baseURL.replace('://', '://workbench.')
+                var wbUrl = session.baseURL.replace('://', '://workbench.');
                 // Remove the trailing slash, if it's there.
-                return wbUrl.slice(-1) == '/' ? wbUrl.slice(0, -1) : wbUrl
+                return wbUrl.slice(-1) === '/' ? wbUrl.slice(0, -1) : wbUrl;
             }
-            return null
+            return null;
         },
         // Return a m.stream that will get fulfilled with the
         // discovery doc from a session's API server.
         discoveryDoc: function(session) {
-            var cache = db.discoveryCache[session.baseURL]
+            var cache = db.discoveryCache[session.baseURL];
             if (!cache) {
-                db.discoveryCache[session.baseURL] = cache = m.stream()
-                m.request(session.baseURL+'discovery/v1/apis/arvados/v1/rest').then(cache)
+                db.discoveryCache[session.baseURL] = cache = m.stream();
+                m.request(session.baseURL+'discovery/v1/apis/arvados/v1/rest').then(cache);
             }
-            return cache
+            return cache;
         },
         // Return a promise with the local session token's UUID from the API server.
         tokenUUID: function() {
-            var cache = db.tokenUUIDCache
+            var cache = db.tokenUUIDCache;
             if (!cache) {
-                var session = db.loadLocal()
+                var session = db.loadLocal();
                 return db.request(session, '/arvados/v1/api_client_authorizations', {
                     data: {
-                        filters: JSON.stringify([['api_token', '=', session.token]]),
+                        filters: JSON.stringify([['api_token', '=', session.token]])
                     }
                 }).then(function(resp) {
-                    var uuid = resp.items[0].uuid
-                    db.tokenUUIDCache = uuid
-                    return uuid
-                })
+                    var uuid = resp.items[0].uuid;
+                    db.tokenUUIDCache = uuid;
+                    return uuid;
+                });
             } else {
                 return new Promise(function(resolve, reject) {
-                    resolve(cache)
-                })
+                    resolve(cache);
+                });
             }
         },
         request: function(session, path, opts) {
-            opts = opts || {}
-            opts.headers = opts.headers || {}
-            opts.headers.authorization = 'OAuth2 '+ session.token
-            return m.request(session.baseURL + path, opts)
+            opts = opts || {};
+            opts.headers = opts.headers || {};
+            opts.headers.authorization = 'OAuth2 '+ session.token;
+            return m.request(session.baseURL + path, opts);
         },
         // Check non-federated remote active sessions if they should be migrated to
         // a salted token.
         migrateNonFederatedSessions: function() {
-            var sessions = db.loadActive()
+            var sessions = db.loadActive();
             Object.keys(sessions).map(function(uuidPrefix) {
-                session = sessions[uuidPrefix]
+                session = sessions[uuidPrefix];
                 if (!session.isFromRails && session.token && session.token.indexOf('v2/') < 0) {
                     // Only try the federated login
-                    db.login(session.baseURL, false)
+                    db.login(session.baseURL, false);
                 }
-            })
+            });
         },
         // If remoteHosts is listed on the local API discovery doc, try to add any
         // listed remote without an active session.
         autoLoadRemoteHosts: function() {
-            var activeSessions = db.loadActive()
-            var doc = db.discoveryDoc(db.loadLocal())
+            var activeSessions = db.loadActive();
+            var doc = db.discoveryDoc(db.loadLocal());
             doc.map(function(d) {
                 Object.keys(d.remoteHosts).map(function(uuidPrefix) {
                     if (!(uuidPrefix in Object.keys(activeSessions))) {
                         db.findAPI(d.remoteHosts[uuidPrefix]).then(function(baseURL) {
-                            db.login(baseURL, false)
-                        })
+                            db.login(baseURL, false);
+                        });
                     }
-                })
-            })
+                });
+            });
         },
         // If the current logged in account is from a remote federated cluster,
         // redirect the user to their home cluster's workbench.
@@ -284,34 +296,35 @@ window.SessionDB = function() {
         // result on the home cluster's multi site search page, landing on the
         // remote workbench and later trying to do another search by just clicking
         // on the multi site search button instead of going back with the browser.
-        autoRedirectToHomeCluster: function(path = '/') {
-            var session = db.loadLocal()
-            var userUUIDPrefix = session.user.uuid.slice(0, 5)
+        autoRedirectToHomeCluster: function(path) {
+            path = path || '/';
+            var session = db.loadLocal();
+            var userUUIDPrefix = session.user.uuid.slice(0, 5);
             // If the current user is local to the cluster, do nothing.
-            if (userUUIDPrefix == session.user.owner_uuid.slice(0, 5)) {
-                return
+            if (userUUIDPrefix === session.user.owner_uuid.slice(0, 5)) {
+                return;
             }
-            var doc = db.discoveryDoc(session)
+            var doc = db.discoveryDoc(session);
             doc.map(function(d) {
                 // Guess the remote host from the local discovery doc settings
-                var rHost = null
+                var rHost = null;
                 if (d.remoteHosts[userUUIDPrefix]) {
-                    rHost = d.remoteHosts[userUUIDPrefix]
+                    rHost = d.remoteHosts[userUUIDPrefix];
                 } else if (d.remoteHostsViaDNS) {
-                    rHost = userUUIDPrefix + '.arvadosapi.com'
+                    rHost = userUUIDPrefix + '.arvadosapi.com';
                 } else {
                     // This should not happen: having remote user whose uuid prefix
                     // isn't listed on remoteHosts and dns mechanism is deactivated
-                    return
+                    return;
                 }
                 // Get the remote cluster workbench url & redirect there.
-                db.findAPI(rHost).then(function(apiUrl) {
-                    var doc = db.discoveryDoc({baseURL: apiUrl})
-                    doc.map(function(d) {
-                        document.location = d.workbenchUrl + path
-                    })
-                })
-            })
-        },
-    })
-}
+                db.findAPI(rHost).then(function (apiUrl) {
+                    var doc = db.discoveryDoc({baseURL: apiUrl});
+                    doc.map(function (d) {
+                        document.location = d.workbenchUrl + path;
+                    });
+                });
+            });
+        }
+    });
+};

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list