Skip to content

Commit

Permalink
support azure labeling and tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Zagaynov committed Apr 16, 2018
1 parent 7558ac5 commit ccfe3c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
15 changes: 8 additions & 7 deletions app/models/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ class Classification < ApplicationRecord
before_destroy :delete_tags_and_entries

validates :description, :presence => true, :length => {:maximum => 255}
validates :description, :uniqueness => {:scope => [:parent_id]}, :if => proc { |c|
cond = ["parent_id = ? AND description = ?", c.parent_id, c.description]
unless c.new_record?
cond.first << " AND id != ?"
cond << c.id
end
c.class.in_region(region_id).exists?(cond)
validates :description, :uniqueness => { :scope => %i(parent_id tag_id) }, :if => proc { |c|
relation = c.class.in_region(region_id).where(
:tag_id => c.tag_id,
:parent_id => c.parent_id,
:description => c.description,
)
relation = relation.where.not(:id => c.id) unless c.new_record?
relation.exists?
}

NAME_MAX_LENGTH = 50
Expand Down
2 changes: 1 addition & 1 deletion app/models/container_label_tag_mapping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ContainerLabelTagMapping < ApplicationRecord

require_nested :Mapper

TAG_PREFIXES = ['/managed/amazon:', '/managed/kubernetes:'].freeze
TAG_PREFIXES = %w(amazon azure kubernetes).map { |name| "/managed/#{name}:" }.freeze
validate :validate_tag_prefix

# Return ContainerLabelTagMapping::Mapper instance that holds all current mappings,
Expand Down
1 change: 1 addition & 0 deletions app/models/container_label_tag_mapping/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def self.references_to_tags(tag_references)
private

def map_label(type, label)
type = 'VmAzure' if type == 'Vm' && label[:source] == 'azure'
# Apply both specific-type and any-type, independently.
(map_name_type_value(label[:name], type, label[:value]) +
map_name_type_value(label[:name], nil, label[:value]))
Expand Down

0 comments on commit ccfe3c0

Please sign in to comment.