1 # At the time we introduced scopes everywhere, VirtualMachinesController
2 # recognized scopes that gave the URL for a VM to grant access to that VM's
3 # login list. This migration converts those VM-specific scopes to the new
4 # general format, and back.
6 class NewScopeFormat < ActiveRecord::Migration
7 include CurrentApiClient
10 %r{(/arvados/v1/virtual_machines/[0-9a-z]{5}-[0-9a-z]{5}-[0-9a-z]{15})}
11 OLD_SCOPE_REGEX = %r{^https?://[^/]+#{VM_PATH_REGEX.source}$}
12 NEW_SCOPE_REGEX = %r{^GET #{VM_PATH_REGEX.source}/logins$}
14 def fix_scopes_matching(regex)
16 ApiClientAuthorization.find_each do |auth|
17 auth.scopes = auth.scopes.map do |scope|
18 if match = regex.match(scope)
29 fix_scopes_matching(OLD_SCOPE_REGEX) do |match|
30 "GET #{match[1]}/logins"
37 hostname = 'www.example.com'
40 hostname = Socket.gethostname
42 fix_scopes_matching(NEW_SCOPE_REGEX) do |match|
43 Rails.application.routes.url_for(controller: 'virtual_machines',
44 uuid: match[1].split('/').last,
45 host: hostname, protocol: 'https')