lib/miam/client.rb in miam-0.1.3 vs lib/miam/client.rb in miam-0.1.4

- old
+ new

@@ -57,10 +57,12 @@ def walk_users(expected, actual, group_users) updated = scan_rename(:user, expected, actual, group_users) expected.each do |user_name, expected_attrs| + next unless target_matched?(user_name) + actual_attrs = actual.delete(user_name) if actual_attrs updated = walk_path(:user, user_name, expected_attrs[:path], actual_attrs[:path]) || updated updated = walk_user(user_name, expected_attrs, actual_attrs) || updated @@ -76,10 +78,12 @@ updated = true end end actual.each do |user_name, attrs| + next unless target_matched?(user_name) + @driver.delete_user(user_name, attrs) group_users.each do |group_name, users| users.delete(user_name) end @@ -145,10 +149,12 @@ def walk_groups(expected, actual, actual_users, group_users) updated = scan_rename(:group, expected, actual, group_users) expected.each do |group_name, expected_attrs| + next unless target_matched?(group_name) + actual_attrs = actual.delete(group_name) if actual_attrs updated = walk_path(:group, group_name, expected_attrs[:path], actual_attrs[:path]) || updated updated = walk_group(group_name, expected_attrs, actual_attrs) || updated @@ -158,10 +164,12 @@ updated = true end end actual.each do |group_name, attrs| + next unless target_matched?(group_name) + users_in_group = group_users.delete(group_name) || [] @driver.delete_group(group_name, attrs, users_in_group) actual_users.each do |user_name, user_attrs| user_attrs[:groups].delete(group_name) @@ -179,10 +187,12 @@ def walk_roles(expected, actual, instance_profile_roles) updated = false expected.each do |role_name, expected_attrs| + next unless target_matched?(role_name) + actual_attrs = actual.delete(role_name) if actual_attrs updated = walk_role(role_name, expected_attrs, actual_attrs) || updated else @@ -191,10 +201,12 @@ updated = true end end actual.each do |role_name, attrs| + next unless target_matched?(role_name) + instance_profile_names = [] instance_profile_roles.each do |instance_profile_name, roles| if roles.include?(role_name) instance_profile_names << instance_profile_name @@ -259,10 +271,12 @@ def walk_instance_profiles(expected, actual, actual_roles, instance_profile_roles) updated = false expected.each do |instance_profile_name, expected_attrs| + next unless target_matched?(instance_profile_name) + actual_attrs = actual.delete(instance_profile_name) if actual_attrs updated = walk_instance_profile(instance_profile_name, expected_attrs, actual_attrs) || updated else @@ -271,10 +285,12 @@ updated = true end end actual.each do |instance_profile_name, attrs| + next unless target_matched?(instance_profile_name) + roles_in_instance_profile = instance_profile_roles.delete(instance_profile_name) || [] @driver.delete_instance_profile(instance_profile_name, attrs, roles_in_instance_profile) actual_roles.each do |role_name, role_attrs| role_attrs[:instance_profiles].delete(instance_profile_name) @@ -380,8 +396,16 @@ end elsif file.respond_to?(:read) Miam::DSL.parse(file.read, file.path) else raise TypeError, "can't convert #{file} into File" + end + end + + def target_matched?(name) + if @options[:target] + name =~ @options[:target] + else + true end end end