Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Fix for bug 1014837
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Gupta committed Oct 3, 2013
1 parent ccb302f commit 9f6c5bf
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions controller/app/models/domain.rb
Expand Up @@ -148,6 +148,18 @@ def inherit_membership
end

def add_system_ssh_keys(ssh_keys)
ssh_keys_to_rm = []
ssh_keys.each do |new_key|
self.system_ssh_keys.each do |cur_key|
if cur_key.name == new_var.name
ssh_keys_to_rm << cur_key.to_key_hash()
end
end
end

# if an ssh key being added has the same name as an existing key, then remove the previous keys first
Domain.where(_id: self.id).update_all({ "$pullAll" => { system_ssh_keys: ssh_keys_to_rm }}) unless ssh_keys_to_rm.empty?

#keys_attrs = ssh_keys.map{|k| k.attributes.dup}
#pending_op = PendingDomainOps.new(op_type: :add_domain_ssh_keys, arguments: { "keys_attrs" => keys_attrs }, on_apps: applications, created_at: Time.now, state: "init")
keys_attrs = ssh_keys.map { |k| k.to_key_hash() }
Expand All @@ -174,18 +186,18 @@ def add_env_variables(variables)
env_vars_to_rm = []
variables.each do |new_var|
self.env_vars.each do |cur_var|
if cur_var["key"] == new_var["key"] && cur_var["value"] != new_var["value"]
if cur_var["key"] == new_var["key"]
env_vars_to_rm << cur_var.dup
end
end
end

# if this is an update to an existing environment variable, remove the previous ones first
Domain.where(_id: self.id).update_all({ "$pullAll" => { env_vars: env_vars_to_rm }}) unless env_vars_to_rm.empty?

#pending_op = PendingDomainOps.new(op_type: :add_env_variables, arguments: {"variables" => variables}, on_apps: applications, created_at: Time.now, state: "init")
pending_op = AddEnvVarsDomainOp.new(variables: variables, on_apps: applications)
Domain.where(_id: self.id).update_all({ "$push" => { pending_ops: pending_op.serializable_hash_with_timestamp }, "$pushAll" => { env_vars: variables }})

# if this is an update to an existing environment variable, remove the previous ones
Domain.where(_id: self.id).update_all({ "$pullAll" => { env_vars: env_vars_to_rm }}) unless env_vars_to_rm.empty?
end

def remove_env_variables(remove_key)
Expand Down

0 comments on commit 9f6c5bf

Please sign in to comment.