class Kontena::Plugin::Cloud::Platform::User::RemoveCommand
Public Instance Methods
execute()
click to toggle source
# File lib/kontena/plugin/cloud/platform/user/remove_command.rb, line 14 def execute require_platform(name) platform = find_platform_by_name(current_grid, current_organization) self.username_list = prompt_users(platform) if self.username_list.count == 0 confirm_command(self.username_list.join(',')) unless forced? remove_users(platform, username_list) end
prompt_users(platform)
click to toggle source
# File lib/kontena/plugin/cloud/platform/user/remove_command.rb, line 22 def prompt_users(platform) platform_members = [] spinner "Resolving organization #{pastel.cyan(name)} current users" do platform_members = cloud_client.get("/organizations/#{current_organization}/platforms/#{platform.id}/relationships/users")['data'] end users = prompt.multi_select("Choose users:") do |menu| platform_members.each do |u| menu.choice u.dig('attributes', 'username'), u['id'] end end if platform_members.size - users.size < 1 exit_with_error "Cannot remove the last user of the platform" end users end
remove_users(platform, user_ids)
click to toggle source
# File lib/kontena/plugin/cloud/platform/user/remove_command.rb, line 38 def remove_users(platform, user_ids) users = [] user_ids.each do |u| users << { type: 'users', id: u } end spinner "Removing users from platform #{pastel.cyan(name)}" do data = {data: users} cloud_client.delete("/organizations/#{current_organization}/platforms/#{platform.id}/relationships/users", data) end end