oninit: function(vnode) {
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
m('.row', m('.col-md-6', [
m('form', {
onsubmit: function() {
- db.login(vnode.state.hostToAdd())
+ vnode.state.error(null)
+ vnode.state.checking(true)
+ db.findAPI(vnode.state.hostToAdd())
+ .then(db.login)
+ .catch(function() {
+ vnode.state.error(true)
+ })
+ .then(vnode.state.checking.bind(null, null))
return false
},
}, [
- m('.input-group', [
- m('input.form-control[type=text][name=apiHost][placeholder="API host"]', {
+ m('p', [
+ 'To add a remote Arvados site, paste the remote site\'s host here (see "ARVADOS_API_HOST" on the "current token" page).',
+ ]),
+ m('.input-group', { className: vnode.state.error() && 'has-error' }, [
+ m('input.form-control[type=text][name=apiHost][placeholder="zzzzz.arvadosapi.com"]', {
oninput: m.withAttr('value', vnode.state.hostToAdd),
}),
m('.input-group-btn', [
]),
]),
]),
+ m('p'),
+ vnode.state.error() && m('p.alert.alert-danger', 'Request failed. Make sure this is a working API server address.'),
+ vnode.state.checking() && m('p.alert.alert-info', 'Checking...'),
])),
])
},
delete sessions[k]
window.localStorage.setItem('sessions', JSON.stringify(sessions))
},
- login: function(host) {
- // Initiate login procedure with given API host (which can
- // optionally include scheme://).
+ 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.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 + '/'
+ }).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
+ })
+ })
+ },
+ login: function(baseURL) {
+ // Initiate login procedure with given API base URL (e.g.,
+ // "http://api.example/").
//
// Any page that has a button that invokes login() must
// also call checkForNewToken() on (at least) its first
// render. Otherwise, the login procedure can't be
// completed.
- var baseURL = host
- if (baseURL.indexOf('://') < 0)
- baseURL = 'https://' + baseURL
- if (!baseURL.endsWith('/'))
- baseURL = baseURL + '/'
document.location = baseURL + 'login?return_to=' + encodeURIComponent(document.location.href.replace(/\?.*/, '')+'?baseURL='+encodeURIComponent(baseURL))
return false
},
--- /dev/null
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+class StatusController < ApplicationController
+ skip_around_filter :require_thread_api_token
+ skip_before_filter :find_object_by_uuid
+ def status
+ # Allow non-credentialed cross-origin requests
+ headers['Access-Control-Allow-Origin'] = '*'
+ resp = {
+ apiBaseURL: arvados_api_client.arvados_v1_base.sub(%r{/arvados/v\d+.*}, '/'),
+ version: AppVersion.hash,
+ }
+ render json: resp
+ end
+end
get '/tests/mithril', to: 'tests#mithril'
+ get '/status', to: 'status#status'
+
# Send unroutable requests to an arbitrary controller
# (ends up at ApplicationController#render_not_found)
match '*a', to: 'links#render_not_found', via: [:get, :post]