diff --git a/app/models/plugin.rb b/app/models/plugin.rb index f0b8c223..5857f968 100644 --- a/app/models/plugin.rb +++ b/app/models/plugin.rb @@ -30,6 +30,11 @@ def plugin klass.new(self) end + def hook_priority + attributes = self.plugin_attributes || {} + attributes['hook_priority'].to_i + end + private def default_attributes diff --git a/db/migrate/20240228032657_add_hook_order_to_plugin.rb b/db/migrate/20240228032657_add_hook_order_to_plugin.rb deleted file mode 100644 index 6e209947..00000000 --- a/db/migrate/20240228032657_add_hook_order_to_plugin.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddHookOrderToPlugin < ActiveRecord::Migration[5.2] - def change - add_column :plugins, :hook_priority, :integer, :default => 10 - end -end diff --git a/db/schema.rb b/db/schema.rb index c560a0bf..355dc116 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2024_02_28_032657) do +ActiveRecord::Schema.define(version: 2022_12_08_045503) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -134,7 +134,6 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.text "plugin_attributes" - t.integer "hook_priority", default: 10 t.index ["district_id"], name: "index_plugins_on_district_id" end diff --git a/lib/barcelona/plugins/datadog_plugin.rb b/lib/barcelona/plugins/datadog_plugin.rb index c433f2af..927692eb 100644 --- a/lib/barcelona/plugins/datadog_plugin.rb +++ b/lib/barcelona/plugins/datadog_plugin.rb @@ -1,6 +1,10 @@ module Barcelona module Plugins class DatadogPlugin < Base + # This plugin must be the last of the instalation order + # Usage sample: + # bcn district put-plugin -a api_key=8e53.... -a hook_priority=10 ec-staging datadog + def on_container_instance_user_data(_instance, user_data) add_files!(user_data) user_data.run_commands += [ diff --git a/spec/models/district_spec.rb b/spec/models/district_spec.rb index d1c2b5d9..37fc9e29 100644 --- a/spec/models/district_spec.rb +++ b/spec/models/district_spec.rb @@ -72,7 +72,7 @@ user_data = InstanceUserData.new district.save! district.plugins.create(name: 'secure_instance') - district.plugins.create(name: 'datadog', plugin_attributes: { "api_key": 'abcdefg'}, 'hook_priority': 20) + district.plugins.create(name: 'datadog', plugin_attributes: { "api_key": 'abcdefg', "hook_priority": 10}) district.plugins.create(name: 'itamae', plugin_attributes: { "recipe_url": "s3://barcelona-district1-12345/itamae_recipes/recipe.tar.gz"}) user_data = district.hook_plugins(:container_instance_user_data, self, user_data) user_data_hash = YAML.load(Base64.decode64(user_data.build)) diff --git a/spec/models/plugin_spec.rb b/spec/models/plugin_spec.rb index ffbba26c..b50fb551 100644 --- a/spec/models/plugin_spec.rb +++ b/spec/models/plugin_spec.rb @@ -32,4 +32,20 @@ end end end + + describe "#hook_priority" do + context "when not specified" do + let(:plugin) { Plugin.new(name: 'test') } + it "should be zero" do + expect(plugin.hook_priority).to eq(0) + end + end + + context "when specified" do + let(:plugin) { Plugin.new(name: 'test', plugin_attributes:{ "api_key": 'abcdefg', hook_priority: '10'}) } + it "should be the specified value" do + expect(plugin.hook_priority).to eq(10) + end + end + end end