From 19e217e387ff4ff11bb6c493401981546a03d6f8 Mon Sep 17 00:00:00 2001 From: Artem Yakimenko Date: Tue, 8 Dec 2020 12:48:38 +1100 Subject: [PATCH 1/3] Fix issue introduced by ShieldedInstanceConfig API --- lib/vagrant-google/action/run_instance.rb | 45 +++++++++++++---------- lib/vagrant-google/config.rb | 6 +-- test/unit/common/config_test.rb | 6 +-- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/lib/vagrant-google/action/run_instance.rb b/lib/vagrant-google/action/run_instance.rb index 496c0e1..6ebe4f6 100644 --- a/lib/vagrant-google/action/run_instance.rb +++ b/lib/vagrant-google/action/run_instance.rb @@ -267,26 +267,33 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize end defaults = { - :name => name, - :zone => zone, - :machine_type => machine_type, - :disk_size => disk_size, - :disk_type => disk_type, - :image => image, - :network_interfaces => network_interfaces, - :metadata => { :items => metadata.each.map { |k, v| {:key => k.to_s, :value => v.to_s} } }, - :labels => labels, - :tags => { :items => tags }, - :can_ip_forward => can_ip_forward, - :use_private_ip => use_private_ip, - :external_ip => external_ip, - :network_ip => network_ip, - :disks => disks, - :scheduling => scheduling, - :service_accounts => service_accounts, - :guest_accelerators => accelerators_url, - :shielded_instance_config => shielded_instance_config, + :name => name, + :zone => zone, + :machine_type => machine_type, + :disk_size => disk_size, + :disk_type => disk_type, + :image => image, + :network_interfaces => network_interfaces, + :metadata => { :items => metadata.each.map { |k, v| { :key => k.to_s, :value => v.to_s } } }, + :labels => labels, + :tags => { :items => tags }, + :can_ip_forward => can_ip_forward, + :use_private_ip => use_private_ip, + :external_ip => external_ip, + :network_ip => network_ip, + :disks => disks, + :scheduling => scheduling, + :service_accounts => service_accounts, + :guest_accelerators => accelerators_url } + + # XXX HACK - only add of the parameters are set in :shielded_instance_config we need to drop the field from + # the API call otherwise we'll error out with Google::Apis::ClientError + # TODO(temikus): Remove if the API changes, see internal GOOG ref: b/175063371 + if shielded_instance_config.has_value?(true) + defaults[:shielded_instance_config] = shielded_instance_config + end + server = env[:google_compute].servers.create(defaults) @logger.info("Machine '#{zone}:#{name}' created.") rescue *FOG_ERRORS => e diff --git a/lib/vagrant-google/config.rb b/lib/vagrant-google/config.rb index 374a6fc..142c040 100644 --- a/lib/vagrant-google/config.rb +++ b/lib/vagrant-google/config.rb @@ -419,13 +419,13 @@ def finalize! # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedC end # enable_secure_boot defaults to nil - @enable_secure_boot = nil if @enable_secure_boot == UNSET_VALUE + @enable_secure_boot = false if @enable_secure_boot == UNSET_VALUE # enable_vtpm defaults to nil - @enable_vtpm = nil if @enable_vtpm == UNSET_VALUE + @enable_vtpm = false if @enable_vtpm == UNSET_VALUE # enable_integrity_monitoring defaults to nil - @enable_integrity_monitoring = nil if @enable_integrity_monitoring == UNSET_VALUE + @enable_integrity_monitoring = false if @enable_integrity_monitoring == UNSET_VALUE # Compile our zone specific configurations only within # NON-zone-SPECIFIC configurations. diff --git a/test/unit/common/config_test.rb b/test/unit/common/config_test.rb index c21145e..9072a9a 100644 --- a/test/unit/common/config_test.rb +++ b/test/unit/common/config_test.rb @@ -51,9 +51,9 @@ its("auto_restart") { should } its("on_host_maintenance") { should == "MIGRATE" } its("accelerators") { should == [] } - its("enable_secure_boot") { should be_nil } - its("enable_vtpm") { should be_nil } - its("enable_integrity_monitoring") { should be_nil } + its("enable_secure_boot") { should be_falsey } + its("enable_vtpm") { should be_falsey } + its("enable_integrity_monitoring") { should be_falsey } end describe "overriding defaults" do From 22ea17e533c183ca168ecb02aeec847c06dc107f Mon Sep 17 00:00:00 2001 From: Artem Yakimenko Date: Tue, 8 Dec 2020 12:48:46 +1100 Subject: [PATCH 2/3] Tune rubocop config --- .rubocop.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index c01e1a1..ff0377d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,4 +13,13 @@ Style/StringLiterals: Enabled: false Style/IfUnlessModifier: - Enabled: false \ No newline at end of file + Enabled: false + +Metrics/LineLength: + Max: 120 + +Layout/HashAlignment: + EnforcedHashRocketStyle: table + +Style/HashSyntax: + EnforcedStyle: no_mixed_keys From d0bd8dfdf7aab0593481a5c9b614610da1232fa8 Mon Sep 17 00:00:00 2001 From: Artem Yakimenko Date: Tue, 8 Dec 2020 13:08:28 +1100 Subject: [PATCH 3/3] Add changelog task for easier change-keeping --- CHANGELOG.md | 3 +++ tasks/changelog.rake | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tasks/changelog.rake diff --git a/CHANGELOG.md b/CHANGELOG.md index b3dd910..8dc2b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## Next + + ## 2.5.0 (September 2019) ### User-facing diff --git a/tasks/changelog.rake b/tasks/changelog.rake new file mode 100644 index 0000000..857e257 --- /dev/null +++ b/tasks/changelog.rake @@ -0,0 +1,37 @@ +require "fileutils" + +# Helper method to insert text after a line that matches the regex +def insert_after_line(file, insert, regex = /^## Next/) + tempfile = File.open("#{file}.tmp", "w") + f = File.new(file) + f.each do |line| + tempfile << line + next unless line =~ regex + + tempfile << "\n" + tempfile << insert + tempfile << "\n" + end + f.close + tempfile.close + + FileUtils.mv("#{file}.tmp", file) +end + +# Extracts all changes that have been made after the latest pushed tag +def changes_since_last_tag + `git --no-pager log $(git describe --tags --abbrev=0)..HEAD --grep="Merge" --pretty=format:"%t - %s%n%b%n"` +end + +# Extracts all github users contributed since last tag +def users_since_last_tag + `git --no-pager log $(git describe --tags --abbrev=0)..HEAD --grep="Merge" --pretty=format:"%s" | cut -d' ' -f 6 | cut -d/ -f1 | uniq` +end + +namespace :changelog do + task :generate do + insert_after_line("CHANGELOG.md", changes_since_last_tag, /^## Next/) + printf("Users contributed since last release:\n") + printf(users_since_last_tag) + end +end