Skip to content

Commit

Permalink
Make hook_priority as a plugin_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
essa committed Feb 28, 2024
1 parent 3cb09ed commit 24e9954
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
5 changes: 5 additions & 0 deletions app/models/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions db/migrate/20240228032657_add_hook_order_to_plugin.rb

This file was deleted.

3 changes: 1 addition & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/barcelona/plugins/datadog_plugin.rb
Original file line number Diff line number Diff line change
@@ -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 += [
Expand Down
2 changes: 1 addition & 1 deletion spec/models/district_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
16 changes: 16 additions & 0 deletions spec/models/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 24e9954

Please sign in to comment.