diff --git a/.reek b/.reek new file mode 100644 index 000000000..6926df187 --- /dev/null +++ b/.reek @@ -0,0 +1,7 @@ +--- +# this file should be name reel.yml in reek 5 +#Detectors: # reek 5 +DuplicateMethodCall: + max_calls: 2 +TooManyStatements: + max_statements: 8 # to be more consistent with rubocop Metrics/MethodLength: 10 \ No newline at end of file diff --git a/Gemfile b/Gemfile index 003a9923d..31a96a780 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.3.1' +ruby '~>2.3.1' gem 'rhcl', '>= 0.1.0' diff --git a/Readme.md b/Readme.md index b89fe503e..3dc38055a 100644 --- a/Readme.md +++ b/Readme.md @@ -582,11 +582,11 @@ or in multiple files. An example file can be found at [/lib/coa_env_bootstrapper It can contain up to 8 main keys: * inactive_steps, _optional_: pass a list of steps that will be deactivated in case you wouldn't need them to run, for instance in case you have some resources already installed. You can deactivate: - * deploy_transiant_infra: you can deactivate this step if you already have an infrastructure with BOSH and Concourse + * deploy_transient_infra: you can deactivate this step if you already have an infrastructure with BOSH and Concourse * upload_stemcell: you can deactivate this step if you don't want a new stemcell to be uploaded to the BOSH Director * upload_cloud_config: you can deactivate this step if you don't want to overwrite the cloud config of the BOSH Director * install_git_server: you can deactivate this step if you have the git-server deployment already deployed on the BOSH Director -* bucc, _optional_: you have to pass this key unless you deactivate the deploy_transiant_infra step: +* bucc, _optional_: you have to pass this key unless you deactivate the deploy_transient_infra step: * bin_path: the path to your installation of the bucc project. The project can be found at [https://github.com/starkandwayne/bucc](https://github.com/starkandwayne/bucc) * cpi: the cpi you want to use for the deployment. The list of existing CPIs can be found on the bucc GitHub project * cpi_specific_options: options you want to pass to the bucc CLI for the bucc deployment @@ -598,12 +598,12 @@ It can contain up to 8 main keys: * git_server_manifest, _mandatory_: a BOSH manifest to deploy the git-server deployment. The example one can be used to be deployed with VirtualBox, in any other case, you will want to adapt it for your IaaS. * cloud_config, _optional_: you have to pass this key unless you deactivate the "upload_cloud_config" step. This will be used by the BOSH CLI to upload a cloud-config to the BOSH Director * pipeline_credentials, _mandatory_: this passes a list of credentials that will by used by fly to upload the pipelines to Concourse. -* concourse, _optional_: you have to pass this object if you deactivated the deploy_transiant_infra step or if you want to overwrite the BUCC Concourse and want to use another one. The options are self-explanatory. +* concourse, _optional_: you have to pass this object if you deactivated the deploy_transient_infra step or if you want to overwrite the BUCC Concourse and want to use another one. The options are self-explanatory. * target * url * username * password -* bosh, _optional_: you have to pass this key if you deactivate the deploy_transiant_infra step or if you want to overwrite BUCC's BOSH and want to use another one. The options are self-explanatory. +* bosh, _optional_: you have to pass this key if you deactivate the deploy_transient_infra step or if you want to overwrite BUCC's BOSH and want to use another one. The options are self-explanatory. * bosh_environment * bosh_client * bosh_client_secret diff --git a/ci/bootstrap_coa_env/prereqs.yml b/ci/bootstrap_coa_env/prereqs.yml index 7d0a39c21..23a225241 100644 --- a/ci/bootstrap_coa_env/prereqs.yml +++ b/ci/bootstrap_coa_env/prereqs.yml @@ -1,5 +1,5 @@ inactive_steps: - - deploy_transiant_infra + - deploy_transient_infra - upload_stemcell # - upload_cloud_config # - install_git_server diff --git a/lib/bosh_certificates.rb b/lib/bosh_certificates.rb index 67ccda9de..80e90be1c 100644 --- a/lib/bosh_certificates.rb +++ b/lib/bosh_certificates.rb @@ -1,5 +1,6 @@ require 'openssl' +# Create or load SSL certificates to be able to connect to a Bosh Director class BoshCertificates attr_reader :base_dir, :bosh_cert_hash, :certs diff --git a/lib/coa_env_bootstrapper.rb b/lib/coa_env_bootstrapper.rb index 800626546..b0a0065b2 100644 --- a/lib/coa_env_bootstrapper.rb +++ b/lib/coa_env_bootstrapper.rb @@ -1,5 +1,6 @@ require 'pathname' +# Bootstrap an new COA environment from scratch module CoaEnvBootstrapper require_relative './coa_env_bootstrapper/base' require_relative './coa_env_bootstrapper/bosh' diff --git a/lib/coa_env_bootstrapper/base.rb b/lib/coa_env_bootstrapper/base.rb index f93be156f..0c3df4520 100644 --- a/lib/coa_env_bootstrapper/base.rb +++ b/lib/coa_env_bootstrapper/base.rb @@ -28,11 +28,11 @@ def self.run(prereqs_path) def run @config_dir = Dir.mktmpdir write_source_profile - env_creator_adapter.deploy_transiant_infra unless inactive_step?("deploy_transiant_infra") + env_creator_adapter.deploy_transient_infra unless inactive_step?("deploy_transient_infra") prepare_bosh_environment prepare_git_environment run_pipeline_jobs - env_creator_adapter.display_concourse_login_information unless inactive_step?("deploy_transiant_infra") + env_creator_adapter.display_concourse_login_information unless inactive_step?("deploy_transient_infra") end def generated_concourse_credentials diff --git a/lib/coa_env_bootstrapper/bosh.rb b/lib/coa_env_bootstrapper/bosh.rb index b3079e3ea..57c9e0473 100644 --- a/lib/coa_env_bootstrapper/bosh.rb +++ b/lib/coa_env_bootstrapper/bosh.rb @@ -1,6 +1,7 @@ require_relative './command_runner' module CoaEnvBootstrapper + # Manage interaction with a Bosh Director (stemcell upload, cloud config, prerequisite deployment,etc..) during bootstrap class Bosh include CommandRunner diff --git a/lib/coa_env_bootstrapper/bucc.rb b/lib/coa_env_bootstrapper/bucc.rb index 58d2f46f9..4f0576fd8 100644 --- a/lib/coa_env_bootstrapper/bucc.rb +++ b/lib/coa_env_bootstrapper/bucc.rb @@ -3,6 +3,7 @@ require_relative './errors' module CoaEnvBootstrapper + # Manage BUCC deployment class Bucc include CommandRunner attr_reader :prereqs @@ -11,7 +12,7 @@ def initialize(prereqs) @prereqs = prereqs || {} end - def deploy_transiant_infra + def deploy_transient_infra run_cmd "#{bucc_cli_path} up --cpi #{prereqs['cpi']} \ #{prereqs['cpi_specific_options']} --lite --debug" end diff --git a/lib/coa_env_bootstrapper/command_runner.rb b/lib/coa_env_bootstrapper/command_runner.rb index 4701ed9ce..382226541 100644 --- a/lib/coa_env_bootstrapper/command_runner.rb +++ b/lib/coa_env_bootstrapper/command_runner.rb @@ -1,6 +1,7 @@ require 'open3' module CoaEnvBootstrapper + # Base class for executing command and checking command result module CommandRunner def run_cmd(cmd, opts = {}) source_file_path = opts[:source_file_path] @@ -10,7 +11,7 @@ def run_cmd(cmd, opts = {}) write_header(cmd, ignore_error) stdout, stderr, status = Open3.capture3(cmd) - determine_sucess(stdout, stderr, status, ignore_error) + determine_success(stdout, stderr, status, ignore_error) stdout end @@ -24,9 +25,9 @@ def write_header(command, error_ignored) puts "while ignoring errors." if error_ignored end - def determine_sucess(stdout, stderr, status, error_ignored) + def determine_success(stdout, stderr, status, error_ignored) if status.success? - puts "Command ran succesfully with the following output:", stdout + puts "Command ran successfully with the following output:", stdout elsif error_ignored puts "Command errored, but continuing:", "stderr:", stderr, "stdout:", stdout else diff --git a/lib/coa_env_bootstrapper/concourse.rb b/lib/coa_env_bootstrapper/concourse.rb index cf3626055..7c8161870 100644 --- a/lib/coa_env_bootstrapper/concourse.rb +++ b/lib/coa_env_bootstrapper/concourse.rb @@ -2,6 +2,7 @@ require_relative '../coa_env_bootstrapper' module CoaEnvBootstrapper + # Manage interactions with concourse during bootstrap class Concourse include CommandRunner diff --git a/lib/coa_env_bootstrapper/env_creator_adapter.rb b/lib/coa_env_bootstrapper/env_creator_adapter.rb index b15780dd8..ce37a4785 100644 --- a/lib/coa_env_bootstrapper/env_creator_adapter.rb +++ b/lib/coa_env_bootstrapper/env_creator_adapter.rb @@ -16,8 +16,8 @@ def initialize(adapter_name, prereqs) end end - def deploy_transiant_infra - adapter.deploy_transiant_infra + def deploy_transient_infra + adapter.deploy_transient_infra end def vars diff --git a/lib/coa_env_bootstrapper/errors.rb b/lib/coa_env_bootstrapper/errors.rb index 447bfff84..9deda962d 100644 --- a/lib/coa_env_bootstrapper/errors.rb +++ b/lib/coa_env_bootstrapper/errors.rb @@ -1,4 +1,5 @@ module CoaEnvBootstrapper + # Error raised by BUCC class BuccCommandError < StandardError; end class EnvCreatorAdapterNotImplementedError < StandardError; end class ConfigDirNotFound < StandardError diff --git a/lib/coa_env_bootstrapper/git.rb b/lib/coa_env_bootstrapper/git.rb index bb0e442ce..84711db48 100644 --- a/lib/coa_env_bootstrapper/git.rb +++ b/lib/coa_env_bootstrapper/git.rb @@ -2,6 +2,7 @@ require_relative './errors' module CoaEnvBootstrapper + # Manage interaction with COA embedded git repository class Git include CommandRunner attr_reader :ceb diff --git a/lib/coa_env_bootstrapper/prereqs.example.yml b/lib/coa_env_bootstrapper/prereqs.example.yml index ac349abf6..9507bc467 100644 --- a/lib/coa_env_bootstrapper/prereqs.example.yml +++ b/lib/coa_env_bootstrapper/prereqs.example.yml @@ -1,7 +1,7 @@ # With this key you can deactive some of the steps of the script, if you've got # some elements installed already. inactive_steps: [] - # - deploy_transiant_infra + # - deploy_transient_infra # - upload_stemcell # - upload_cloud_config # - install_git_server diff --git a/scripts/extract_pipeline_credentials_list.rb b/scripts/extract_pipeline_credentials_list.rb index 90db6b45c..39e77324e 100755 --- a/scripts/extract_pipeline_credentials_list.rb +++ b/scripts/extract_pipeline_credentials_list.rb @@ -1,21 +1,24 @@ #!/usr/bin/env ruby -w -def credential_list(pipelines_path) - creds_list = [] +# scan pipelines to list concourse variables +class CredentialsList + def self.list(pipelines_path) + creds_list = [] - files = File.directory?(pipelines_path) ? Dir["#{pipelines_path}/*"] : [pipelines_path] + files = File.directory?(pipelines_path) ? Dir["#{pipelines_path}/*"] : [pipelines_path] - files.each do |path| - next if File.directory?(path) - pipeline_content = File.read(path) - creds_list << pipeline_content.scan(%r{\(\(([\w|-]*)\)\)}).flatten.uniq - end + files.each do |path| + next if File.directory?(path) + pipeline_content = File.read(path) + creds_list << pipeline_content.scan(/\(\(([\w|-]*)\)\)/).flatten.uniq + end - creds_list.flatten.uniq.sort + creds_list.flatten.uniq.sort + end end if (path = ARGV[0]) - creds = credential_list(path) + creds = CredentialsList.list(path) puts "Found credentials in alphabetical order:" puts creds.join("\n") else diff --git a/spec/lib/coa_env_bootstrapper/base_spec.rb b/spec/lib/coa_env_bootstrapper/base_spec.rb index 970600ff5..967652c69 100644 --- a/spec/lib/coa_env_bootstrapper/base_spec.rb +++ b/spec/lib/coa_env_bootstrapper/base_spec.rb @@ -32,7 +32,7 @@ let(:ceb) { described_class.new([]) } it "runs all steps" do - allow(ceb.env_creator_adapter).to receive(:deploy_transiant_infra) + allow(ceb.env_creator_adapter).to receive(:deploy_transient_infra) allow(ceb).to receive(:write_source_profile) allow(ceb.bosh).to receive(:upload_stemcell) allow(ceb.bosh).to receive(:upload_cloud_config) @@ -49,7 +49,7 @@ ceb.run - expect(ceb.env_creator_adapter).to have_received(:deploy_transiant_infra) + expect(ceb.env_creator_adapter).to have_received(:deploy_transient_infra) expect(ceb).to have_received(:write_source_profile) expect(ceb.bosh).to have_received(:upload_stemcell) expect(ceb.bosh).to have_received(:upload_cloud_config) @@ -70,7 +70,7 @@ let(:ceb) { described_class.new([inactive_steps_yml_path]) } it "ignores the deactivated steps" do - allow(ceb.env_creator_adapter).to receive(:deploy_transiant_infra) + allow(ceb.env_creator_adapter).to receive(:deploy_transient_infra) allow(ceb).to receive(:write_source_profile) allow(ceb.bosh).to receive(:upload_stemcell) allow(ceb.bosh).to receive(:upload_cloud_config) @@ -87,7 +87,7 @@ ceb.run - expect(ceb.env_creator_adapter).not_to have_received(:deploy_transiant_infra) + expect(ceb.env_creator_adapter).not_to have_received(:deploy_transient_infra) expect(ceb).to have_received(:write_source_profile) expect(ceb.bosh).not_to have_received(:upload_stemcell) expect(ceb.bosh).to have_received(:upload_cloud_config) diff --git a/spec/lib/coa_env_bootstrapper/bucc_spec.rb b/spec/lib/coa_env_bootstrapper/bucc_spec.rb index 0c48db053..aebfb3304 100644 --- a/spec/lib/coa_env_bootstrapper/bucc_spec.rb +++ b/spec/lib/coa_env_bootstrapper/bucc_spec.rb @@ -4,7 +4,7 @@ describe CoaEnvBootstrapper::Bucc do describe '.new' - describe '#deploy_transiant_infra' do + describe '#deploy_transient_infra' do context "with no given bucc config" do let(:bucc) { described_class.new({}) } @@ -20,7 +20,7 @@ it "runs a bucc command with the config" do allow(bucc).to receive(:run_cmd) - bucc.deploy_transiant_infra + bucc.deploy_transient_infra expect(bucc).to have_received(:run_cmd). with("/path/to/bucc/bin/bucc up --cpi virtualbox --verbose --lite --debug") diff --git a/spec/lib/fixtures/coa_env_bootstrapper/inactive_steps.yml b/spec/lib/fixtures/coa_env_bootstrapper/inactive_steps.yml index d1a49d8a2..365143a73 100644 --- a/spec/lib/fixtures/coa_env_bootstrapper/inactive_steps.yml +++ b/spec/lib/fixtures/coa_env_bootstrapper/inactive_steps.yml @@ -1,4 +1,4 @@ inactive_steps: -- "deploy_transiant_infra" +- "deploy_transient_infra" - "upload_stemcell" - "deploy_git_server"