From 84872a6f6826ab4722df41cd203db27af52360e4 Mon Sep 17 00:00:00 2001 From: Matthew Boedicker and Tony Hansmann Date: Tue, 9 Apr 2013 17:54:35 -0700 Subject: [PATCH] add biff erb helper 'random_string' for unique password generation in manifests --- .travis.yml | 4 +- Gemfile.lock | 2 + bosh_cli/bosh_cli.gemspec | 2 + bosh_cli/lib/cli.rb | 2 + bosh_cli/lib/cli/commands/biff.rb | 13 ++++++ bosh_cli/spec/assets/biff/random_string.yml | 37 ++++++++++++++++++ .../assets/biff/random_string_template.erb | 10 +++++ bosh_cli/spec/unit/cli_commands/biff_spec.rb | 29 ++++++++++++++ vendor/cache/haddock-0.2.2.gem | Bin 0 -> 7168 bytes 9 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 bosh_cli/spec/assets/biff/random_string.yml create mode 100644 bosh_cli/spec/assets/biff/random_string_template.erb create mode 100644 vendor/cache/haddock-0.2.2.gem diff --git a/.travis.yml b/.travis.yml index 0a48e2ec5a..991a7630c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,4 +14,6 @@ notifications: on_failure: always matrix: allow_failures: - - rvm: ruby-2.0.0 \ No newline at end of file + - rvm: ruby-2.0.0 +before_install: + - sudo apt-get --assume-yes install wamerican diff --git a/Gemfile.lock b/Gemfile.lock index ca6aa1b801..c41b0eacb8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,7 @@ PATH archive-tar-minitar (~> 0.5) blobstore_client (~> 1.5.0.pre.3) bosh_common (~> 1.5.0.pre.3) + haddock highline (~> 1.6.2) httpclient (= 2.2.4) json_pure (~> 1.7.6) @@ -281,6 +282,7 @@ GEM guard-rspec (2.5.1) guard (>= 1.1) rspec (~> 2.11) + haddock (0.2.2) highline (1.6.16) httpclient (2.2.4) json (1.7.7) diff --git a/bosh_cli/bosh_cli.gemspec b/bosh_cli/bosh_cli.gemspec index 673342efbb..83dd050f27 100644 --- a/bosh_cli/bosh_cli.gemspec +++ b/bosh_cli/bosh_cli.gemspec @@ -31,4 +31,6 @@ Gem::Specification.new do |s| s.add_dependency "net-scp", "~>1.1.0" s.add_dependency "netaddr", "~>1.5.0" s.add_dependency "archive-tar-minitar", "~>0.5" + s.add_dependency "haddock" + end diff --git a/bosh_cli/lib/cli.rb b/bosh_cli/lib/cli.rb index 1aea8a4db4..5bf2fdceba 100644 --- a/bosh_cli/lib/cli.rb +++ b/bosh_cli/lib/cli.rb @@ -32,6 +32,8 @@ module Cli require "netaddr" require "zlib" require "archive/tar/minitar" +require "haddock" +Haddock::Password.delimiters='!@#%^&()-,./' include Archive::Tar unless defined?(Bosh::Cli::VERSION) diff --git a/bosh_cli/lib/cli/commands/biff.rb b/bosh_cli/lib/cli/commands/biff.rb index f4fa2145a5..4e5eb4d39a 100644 --- a/bosh_cli/lib/cli/commands/biff.rb +++ b/bosh_cli/lib/cli/commands/biff.rb @@ -384,5 +384,18 @@ def setup(template) @temp_file_path_2 = "#{@dir_name}/bosh_biff_2" end + # Generate a random string for passwords and tokens. + # Length is the length of the string. + # name is an optional name of a previously generated string. This is used + # to allow setting the same passwd for different components. + def random_string(length, name=nil) + @random_cache ||= {} + if name + @random_cache[name] ||= Haddock::Password.generate(length) + else + Haddock::Password.generate(length) + end + end + end end diff --git a/bosh_cli/spec/assets/biff/random_string.yml b/bosh_cli/spec/assets/biff/random_string.yml new file mode 100644 index 0000000000..63ff0061ff --- /dev/null +++ b/bosh_cli/spec/assets/biff/random_string.yml @@ -0,0 +1,37 @@ +--- +name: cf-spec +director_uuid: xxxxxx-xxx-xxx-xxxxxxxx +release: + name: Spec-manifest + version: latest +networks: +- name: cf + type: manual + subnets: + - range: 10.10.2.0/23 + name: default_unused + reserved: + - 10.10.2.2 - 10.10.2.9 + static: + - 10.10.2.10 - 10.10.2.50 + gateway: 10.10.2.1 + dns: + - 10.10.0.2 +- name: services + type: manual + subnets: + - range: 10.10.4.0/24 + name: default_unused + reserved: + - 10.10.4.2 - 10.10.4.9 + static: + - 10.10.4.10 - 10.10.4.200 + gateway: 10.10.4.1 + dns: + - 10.10.0.2 + +properties: + defined_but_no_passwd: + password: + defined_with_passwd: + password: passwd_set_in_yml diff --git a/bosh_cli/spec/assets/biff/random_string_template.erb b/bosh_cli/spec/assets/biff/random_string_template.erb new file mode 100644 index 0000000000..6089d00bec --- /dev/null +++ b/bosh_cli/spec/assets/biff/random_string_template.erb @@ -0,0 +1,10 @@ +--- +properties: + defined_but_no_passwd: + password: "<%= random_string 12, :foo %>" + defined_with_passwd: + password: <%= find("properties.defined_with_passwd.password") %> + same_passwd: + password: "<%= random_string 12, :foo %>" + diff_passwd: + password: "<%= random_string 12, :bar %>" \ No newline at end of file diff --git a/bosh_cli/spec/unit/cli_commands/biff_spec.rb b/bosh_cli/spec/unit/cli_commands/biff_spec.rb index fc46fec2a9..39518c1a72 100644 --- a/bosh_cli/spec/unit/cli_commands/biff_spec.rb +++ b/bosh_cli/spec/unit/cli_commands/biff_spec.rb @@ -117,6 +117,35 @@ }.should raise_error Bosh::Cli::CliError, "There were 1 errors." end end + + context "randomized strings" do + let(:template_file) { spec_asset("biff/random_string_template.erb") } + let(:config_file) { spec_asset("biff/random_string.yml") } + + before { + biff.stub!(:deployment).and_return(config_file) + biff.should_receive(:agree).with( + "Would you like to keep the new version? [yn]").once.and_return(false) + } + + subject { + biff.biff(template_file) + Psych.load(biff.template_output)['properties'] + } + + it "Generate a password and put it in" do + expect(subject["defined_but_no_passwd"]["password"]).to_not be_nil + end + + it "Retain an existing" do + expect(subject["defined_with_passwd"]["password"]).to eq "passwd_set_in_yml" + end + + it "Duplicate passwords with same name" do + expect(subject["same_passwd"]["password"]).to eq subject["defined_but_no_passwd"]["password"] + end + end + end context "with good_simple_config" do diff --git a/vendor/cache/haddock-0.2.2.gem b/vendor/cache/haddock-0.2.2.gem new file mode 100644 index 0000000000000000000000000000000000000000..14250239b6aa2a9b2d0d3ab9e78747c9cc321724 GIT binary patch literal 7168 zcmeHLS5y;Pv!;aJL0ag&NJ;1&0@4D~r3%uE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