(rubocop) Fix Style/IfUnlessModifier

This commit is contained in:
Tim Sharpe 2019-02-03 11:14:23 +11:00
parent c7c8e48e2f
commit 7bafee35a7
7 changed files with 15 additions and 45 deletions

View file

@ -212,9 +212,7 @@ class Vmfloaty
# Confirm deletion # Confirm deletion
puts puts
confirmed = true confirmed = true
unless force confirmed = agree('Delete all these VMs? [y/N]') unless force
confirmed = agree('Delete all these VMs? [y/N]')
end
if confirmed if confirmed
response = service.delete(verbose, running_vms) response = service.delete(verbose, running_vms)
response.each do |hostname, result| response.each do |hostname, result|
@ -381,9 +379,7 @@ class Vmfloaty
puts result puts result
when 'status' when 'status'
token_value = options.token token_value = options.token
if token_value.nil? token_value = args[1] if token_value.nil?
token_value = args[1]
end
status = service.token_status(verbose, token_value) status = service.token_status(verbose, token_value)
puts status puts status
when nil when nil

View file

@ -20,9 +20,7 @@ class Auth
end end
def self.delete_token(verbose, url, user, password, token) def self.delete_token(verbose, url, user, password, token)
if token.nil? raise TokenError, 'You did not provide a token' if token.nil?
raise TokenError, 'You did not provide a token'
end
conn = Http.get_conn_with_auth(verbose, url, user, password) conn = Http.get_conn_with_auth(verbose, url, user, password)
@ -36,9 +34,7 @@ class Auth
end end
def self.token_status(verbose, url, token) def self.token_status(verbose, url, token)
if token.nil? raise TokenError, 'You did not provide a token' if token.nil?
raise TokenError, 'You did not provide a token'
end
conn = Http.get_conn(verbose, url) conn = Http.get_conn(verbose, url)

View file

@ -11,21 +11,15 @@ class Http
uri = URI.parse(url) uri = URI.parse(url)
if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) return true if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
return true
end
false false
end end
def self.get_conn(verbose, url) def self.get_conn(verbose, url)
if url.nil? raise 'Did not provide a url to connect to' if url.nil?
raise 'Did not provide a url to connect to'
end
unless is_url(url) url = "https://#{url}" unless is_url(url)
url = "https://#{url}"
end
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
faraday.request :url_encoded faraday.request :url_encoded
@ -37,17 +31,11 @@ class Http
end end
def self.get_conn_with_auth(verbose, url, user, password) def self.get_conn_with_auth(verbose, url, user, password)
if url.nil? raise 'Did not provide a url to connect to' if url.nil?
raise 'Did not provide a url to connect to'
end
if user.nil? raise 'You did not provide a user to authenticate with' if user.nil?
raise 'You did not provide a user to authenticate with'
end
unless is_url(url) url = "https://#{url}" unless is_url(url)
url = "https://#{url}"
end
conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday| conn = Faraday.new(:url => url, :ssl => {:verify => false}) do |faraday|
faraday.request :url_encoded faraday.request :url_encoded

View file

@ -94,9 +94,7 @@ class NonstandardPooler
response_body = {} response_body = {}
unless hosts.is_a? Array hosts = hosts.split(',') unless hosts.is_a? Array
hosts = hosts.split(',')
end
hosts.each do |host| hosts.each do |host|
response = conn.delete "host/#{host}" response = conn.delete "host/#{host}"
res_body = JSON.parse(response.body) res_body = JSON.parse(response.body)

View file

@ -35,9 +35,7 @@ class Pooler
# Developers can use `Utils.generate_os_hash` to # Developers can use `Utils.generate_os_hash` to
# generate the os_type param. # generate the os_type param.
conn = Http.get_conn(verbose, url) conn = Http.get_conn(verbose, url)
if token conn.headers['X-AUTH-TOKEN'] = token if token
conn.headers['X-AUTH-TOKEN'] = token
end
os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+') os_string = os_type.map { |os, num| Array(os) * num }.flatten.join('+')
if os_string.empty? if os_string.empty?
@ -106,9 +104,7 @@ class Pooler
conn = Http.get_conn(verbose, url) conn = Http.get_conn(verbose, url)
if token conn.headers['X-AUTH-TOKEN'] = token if token
conn.headers['X-AUTH-TOKEN'] = token
end
response_body = {} response_body = {}

View file

@ -17,9 +17,7 @@ class Ssh
def self.ssh(verbose, host_os, token, url) def self.ssh(verbose, host_os, token, url)
ssh_path = which('ssh') ssh_path = which('ssh')
if !ssh_path raise 'Could not determine path to ssh' if !ssh_path
raise 'Could not determine path to ssh'
end
os_types = {} os_types = {}
os_types[host_os] = 1 os_types[host_os] = 1

View file

@ -41,9 +41,7 @@ class Utils
response_body.each do |os, value| response_body.each do |os, value|
hostnames = Array(value['hostname']) hostnames = Array(value['hostname'])
if domain hostnames.map! {|host| "#{host}.#{domain}"} if domain
hostnames.map! {|host| "#{host}.#{domain}"}
end
result[os] = hostnames result[os] = hostnames
end end