(rubocop) Fix Style/GuardClause

This commit is contained in:
Tim Sharpe 2019-02-03 12:22:02 +11:00
parent b7b08c9c9e
commit 6a771a8d76
2 changed files with 13 additions and 25 deletions

View file

@ -12,11 +12,8 @@ class Auth
resp = conn.post 'token'
res_body = JSON.parse(resp.body)
if res_body['ok']
return res_body['token']
else
raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}"
end
return res_body['token'] if res_body['ok']
raise TokenError, "HTTP #{resp.status}: There was a problem requesting a token:\n#{res_body}"
end
def self.delete_token(verbose, url, user, password, token)
@ -26,11 +23,8 @@ class Auth
response = conn.delete "token/#{token}"
res_body = JSON.parse(response.body)
if res_body['ok']
return res_body
else
raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}"
end
return res_body if res_body['ok']
raise TokenError, "HTTP #{response.status}: There was a problem deleting a token:\n#{res_body}"
end
def self.token_status(verbose, url, token)
@ -41,10 +35,7 @@ class Auth
response = conn.get "token/#{token}"
res_body = JSON.parse(response.body)
if res_body['ok']
return res_body
else
raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}"
end
return res_body if res_body['ok']
raise TokenError, "HTTP #{response.status}: There was a problem getting the status of a token:\n#{res_body}"
end
end

View file

@ -22,18 +22,15 @@ class Ssh
os_types[host_os] = 1
response = Pooler.retrieve(verbose, os_types, token, url)
if response['ok'] == true
user = host_os =~ /win/ ? 'Administrator' : 'root'
raise "Could not get vm from vmpooler:\n #{response}" unless response['ok']
user = host_os =~ /win/ ? 'Administrator' : 'root'
hostname = "#{response[host_os]['hostname']}.#{response['domain']}"
cmd = "#{ssh_path} #{user}@#{hostname}"
hostname = "#{response[host_os]['hostname']}.#{response['domain']}"
cmd = "#{ssh_path} #{user}@#{hostname}"
# TODO: Should this respect more ssh settings? Can it be configured
# by users ssh config and does this respect those settings?
Kernel.exec(cmd)
else
raise "Could not get vm from vmpooler:\n #{response}"
end
# TODO: Should this respect more ssh settings? Can it be configured
# by users ssh config and does this respect those settings?
Kernel.exec(cmd)
nil
end
end