lib/miam/exporter.rb in miam-0.2.0.beta2 vs lib/miam/exporter.rb in miam-0.2.0.beta3
- old
+ new
@@ -1,5 +1,6 @@
+# coding: utf-8
class Miam::Exporter
def self.export(iam, options = {})
self.new(iam, options).export
end
@@ -18,10 +19,21 @@
roles = account_authorization_details[:role_detail_list]
instance_profiles = list_instance_profiles
group_users = {}
instance_profile_roles = {}
+ unless @options[:no_progress]
+ progress_total = users.length + groups.length + roles.length + instance_profiles.length
+
+ @progressbar = ProgressBar.create(
+ :format => ' %bᗧ%i %p%%',
+ :progress_mark => ' ',
+ :remainder_mark => '・',
+ :total => progress_total,
+ :output => $stderr)
+ end
+
expected = {
:users => export_users(users, group_users),
:groups => export_groups(groups),
:roles => export_roles(roles, instance_profile_roles),
:instance_profiles => export_instance_profiles(instance_profiles),
@@ -54,10 +66,12 @@
}
if login_profile
result[user_name][:login_profile] = login_profile
end
+
+ progress
end
end
result
end
@@ -92,10 +106,12 @@
@mutex.synchronize do
result[group_name] = {
:path => group.path,
:policies => policies,
}
+
+ progress
end
end
result
end
@@ -131,10 +147,12 @@
:path => role.path,
:assume_role_policy_document => JSON.parse(document),
:instance_profiles => instance_profiles,
:policies => policies,
}
+
+ progress
end
end
result
end
@@ -158,10 +176,12 @@
@mutex.synchronize do
result[instance_profile_name] = {
:path => instance_profile.path,
}
+
+ progress
end
end
result
end
@@ -173,10 +193,14 @@
end
def get_account_authorization_details
account_authorization_details = {}
+ unless @options[:no_progress]
+ progressbar = ProgressBar.create(:title => 'Loading', :total => nil, :output => $stderr)
+ end
+
keys = [
:user_detail_list,
:group_detail_list,
:role_detail_list,
]
@@ -186,11 +210,19 @@
end
@iam.get_account_authorization_details.each do |resp|
keys.each do |key|
account_authorization_details[key].concat(resp[key])
+
+ unless @options[:no_progress]
+ progressbar.increment
+ end
end
end
account_authorization_details
+ end
+
+ def progress
+ @progressbar.increment if @progressbar
end
end