Skip to content

Commit

Permalink
rubocop changes
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Hjortshoj <[email protected]>
  • Loading branch information
Paul Warren authored and Julian Hjortshoj committed Nov 8, 2016
1 parent e6f4572 commit 301e923
Show file tree
Hide file tree
Showing 22 changed files with 475 additions and 490 deletions.
8 changes: 4 additions & 4 deletions bin/bcr_check
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env ruby

require "json"
require 'json'

require 'bosh_config_resource'

request = JSON.parse(STDIN.read)

source = request.fetch("source")
target = source["target"] || ""
source = request.fetch('source')
target = source['target'] || ''

auth = BoshConfigResource::Auth.parse(source)
ca_cert = BoshConfigResource::CaCert.new(source["ca_cert"])
ca_cert = BoshConfigResource::CaCert.new(source['ca_cert'])

bosh = BoshConfigResource::Bosh.new(
target,
Expand Down
8 changes: 4 additions & 4 deletions bin/bcr_in
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env ruby

require "json"
require 'json'

require 'bosh_config_resource'

working_dir = ARGV[0]
request = JSON.parse(STDIN.read)

source = request.fetch("source")
source = request.fetch('source')
auth = BoshConfigResource::Auth.parse(source)
ca_cert = BoshConfigResource::CaCert.new(source["ca_cert"])
ca_cert = BoshConfigResource::CaCert.new(source['ca_cert'])

target = source["target"] || request["version"]["target"] || ""
target = source['target'] || request['version']['target'] || ''

bosh = BoshConfigResource::Bosh.new(
target,
Expand Down
14 changes: 7 additions & 7 deletions bin/bcr_out
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
#!/usr/bin/env ruby

require "json"
require 'json'

require 'bosh_config_resource'

working_dir = ARGV[0]
request = JSON.parse(STDIN.read)

source = request.fetch("source")
params = request.fetch("params")
source = request.fetch('source')
params = request.fetch('params')

target_file = params["target_file"]
target_file = params['target_file']

target =
if target_file
File.read(File.expand_path(target_file, working_dir)).strip
else
source.fetch("target")
source.fetch('target')
end

auth = BoshConfigResource::Auth.parse(source)
ca_cert = BoshConfigResource::CaCert.new(source["ca_cert"])
ca_cert = BoshConfigResource::CaCert.new(source['ca_cert'])

bosh = BoshConfigResource::Bosh.new(
target,
ca_cert,
auth
)
manifest = BoshConfigResource::BoshConfig.new(
File.expand_path(params.fetch("manifest"), working_dir)
File.expand_path(params.fetch('manifest'), working_dir)
)

command = BoshConfigResource::OutCommand.new(bosh, manifest)
Expand Down
20 changes: 10 additions & 10 deletions bosh_deployment_resource.gemspec
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# coding: utf-8

Gem::Specification.new do |spec|
spec.name = "bosh_config_resource"
spec.version = "0.0.1"
spec.summary = "a gem for other things"
spec.authors = ["Paul Warren", "Julian Hjortshoj"]
spec.name = 'bosh_config_resource'
spec.version = '0.0.1'
spec.summary = 'a gem for other things'
spec.authors = ['Paul Warren', 'Julian Hjortshoj']

spec.files = Dir.glob("{lib,bin}/**/*")
spec.files = Dir.glob('{lib,bin}/**/*')
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_dependency "minitar"
spec.add_dependency 'minitar'

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency 'bundler', '~> 1.7'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
end
6 changes: 3 additions & 3 deletions gems/json.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "json"
s.version = "1.8.2"
s.name = 'json'
s.version = '1.8.2'
s.summary = "please don't ask"
s.authors = ["satan"]
s.authors = ['satan']
end
6 changes: 3 additions & 3 deletions gems/nokogiri.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "nokogiri"
s.version = "1.5.11"
s.name = 'nokogiri'
s.version = '1.5.11'
s.summary = "please don't ask"
s.authors = ["satan"]
s.authors = ['satan']
end
16 changes: 8 additions & 8 deletions lib/bosh_config_resource.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require "bosh_config_resource/bosh"
require 'bosh_config_resource/bosh'

require "bosh_config_resource/bosh_release"
require "bosh_config_resource/bosh_config"
require "bosh_config_resource/ca_cert"
require "bosh_config_resource/auth"
require 'bosh_config_resource/bosh_release'
require 'bosh_config_resource/bosh_config'
require 'bosh_config_resource/ca_cert'
require 'bosh_config_resource/auth'

require "bosh_config_resource/in_command"
require "bosh_config_resource/out_command"
require "bosh_config_resource/check_command"
require 'bosh_config_resource/in_command'
require 'bosh_config_resource/out_command'
require 'bosh_config_resource/check_command'
33 changes: 16 additions & 17 deletions lib/bosh_config_resource/auth.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
module BoshConfigResource
class Auth
def self.parse(options)
default_auth = options["username"] || options["password"]
uaa_auth = options["client_id"] || options["client_secret"]
case
when default_auth && uaa_auth
raise "source must include either username/password or client_id/client_secret, but not both"
when default_auth
return DefaultAuth.parse(options)
when uaa_auth
return UaaAuth.parse(options)
else
raise "source must include either username/password or client_id/client_secret"
default_auth = options['username'] || options['password']
uaa_auth = options['client_id'] || options['client_secret']
if default_auth && uaa_auth
raise 'source must include either username/password or client_id/client_secret, but not both'
elsif default_auth
return DefaultAuth.parse(options)
elsif uaa_auth
return UaaAuth.parse(options)
else
raise 'source must include either username/password or client_id/client_secret'
end
end
end
Expand All @@ -20,11 +19,11 @@ def self.parse(options)

class DefaultAuth
def self.parse(options)
if !options["username"] || !options["password"]
if !options['username'] || !options['password']
raise "source must include both 'username' and 'password'"
end

new(options.fetch("username"), options.fetch("password"))
new(options.fetch('username'), options.fetch('password'))
end

def initialize(username, password)
Expand All @@ -33,17 +32,17 @@ def initialize(username, password)
end

def env
{ "BOSH_USER" => @username, "BOSH_PASSWORD" => @password }
{ 'BOSH_USER' => @username, 'BOSH_PASSWORD' => @password }
end
end

class UaaAuth
def self.parse(options)
if !options["client_id"] || !options["client_secret"]
if !options['client_id'] || !options['client_secret']
raise "source must include both 'client_id' and 'client_secret'"
end

new(options.fetch("client_id"), options.fetch("client_secret"))
new(options.fetch('client_id'), options.fetch('client_secret'))
end

def initialize(client_id, client_secret)
Expand All @@ -52,7 +51,7 @@ def initialize(client_id, client_secret)
end

def env
{ "BOSH_CLIENT" => @client_id, "BOSH_CLIENT_SECRET" => @client_secret }
{ 'BOSH_CLIENT' => @client_id, 'BOSH_CLIENT_SECRET' => @client_secret }
end
end
end
24 changes: 12 additions & 12 deletions lib/bosh_config_resource/bosh.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require "json"
require "pty"
require 'json'
require 'pty'
require 'English'

module BoshConfigResource
class Bosh
attr_reader :target

def initialize(target, ca_cert, auth, command_runner=CommandRunner.new)
def initialize(target, ca_cert, auth, command_runner = CommandRunner.new)
@target = target
@ca_cert = ca_cert
@auth = auth
@command_runner = command_runner
end


# def upload_stemcell(path)
# bosh("upload stemcell #{path} --skip-if-exists")
# end
Expand Down Expand Up @@ -58,26 +58,26 @@ def download_runtime_config(manifest_path)

attr_reader :command_runner

def bosh(command, opts={})
args = ["-n", "--color", "-t", target]
args << ["--ca-cert", @ca_cert.path] if @ca_cert.provided?
def bosh(command, opts = {})
args = ['-n', '--color', '-t', target]
args << ['--ca-cert', @ca_cert.path] if @ca_cert.provided?
run(
"bosh #{args.join(" ")} #{command}",
"bosh #{args.join(' ')} #{command}",
@auth.env,
opts,
opts
)
end

def run(command, env={}, opts={})
def run(command, env = {}, opts = {})
command_runner.run(command, env, opts)
end
end

class CommandRunner
def run(command, env={}, opts={})
def run(command, env = {}, opts = {})
pid = Process.spawn(env, command, { out: :err, err: :err }.merge(opts))
Process.wait(pid)
raise "command '#{command}' failed!" unless $?.success?
raise "command '#{command}' failed!" unless $CHILD_STATUS.success?
end
end
end
26 changes: 12 additions & 14 deletions lib/bosh_config_resource/bosh_config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "tempfile"
require "yaml"
require 'tempfile'
require 'yaml'

module BoshConfigResource
class BoshConfig
Expand All @@ -8,33 +8,32 @@ def initialize(path)
end

def use_release(release)
manifest.fetch("releases").
find(no_release_found(release.name)) { |r| r.fetch("name") == release.name }.
store("version", release.version)
manifest.fetch('releases')
.find(no_release_found(release.name)) { |r| r.fetch('name') == release.name }
.store('version', release.version)
end

def write!
file = Tempfile.new("bosh_manifest")
file = Tempfile.new('bosh_manifest')

File.write(file.path, YAML.dump(manifest))

file
end

def shasum
sum = -> (o, digest) {
case
when o.respond_to?(:keys)
o.sort.each do |k,v|
sum = lambda do |o, digest|
if o.respond_to?(:keys)
o.sort.each do |k, v|
digest << k.to_s
sum[v, digest]
end
when o.respond_to?(:each)
elsif o.respond_to?(:each)
o.each { |x| sum[x, digest] }
else
digest << o.to_s
end
}
end

d = Digest::SHA1.new
sum[manifest, d]
Expand All @@ -47,8 +46,7 @@ def shasum
attr_reader :manifest

def no_release_found(name)
Proc.new { raise "#{name} can not be found in manifest releases" }
proc { raise "#{name} can not be found in manifest releases" }
end

end
end
16 changes: 8 additions & 8 deletions lib/bosh_config_resource/bosh_release.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "open3"
require "yaml"
require "zlib"
require 'open3'
require 'yaml'
require 'zlib'

require "archive/tar/minitar"
require 'archive/tar/minitar'

module BoshConfigResource
class BoshRelease
Expand All @@ -11,11 +11,11 @@ def initialize(path)
end

def name
manifest.fetch("name")
manifest.fetch('name')
end

def version
manifest.fetch("version")
manifest.fetch('version')
end

private
Expand All @@ -29,13 +29,13 @@ def manifest_file_contents

Archive::Tar::Minitar::Reader.open(tgz) do |reader|
reader.each_entry do |entry|
next unless File.basename(entry.full_name) == "release.MF"
next unless File.basename(entry.full_name) == 'release.MF'

return entry.read
end
end

raise "could not find release.MF"
raise 'could not find release.MF'
ensure
tgz.close if tgz
end
Expand Down
Loading

0 comments on commit 301e923

Please sign in to comment.