Class: CapistranoUsers::CapistranoIntegration

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano_users/capistrano_integration.rb

Constant Summary collapse

TASKS =
[
  'users:groups',
  'users:add_to_group',
  'users:remove_from_group',
  'users:add_to_admin_group',
  'users:remove_from_admin_group'
]

Class Method Summary collapse

Class Method Details

.load_into(capistrano_config) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/capistrano_users/capistrano_integration.rb', line 14

def self.load_into(capistrano_config)
  capistrano_config.load do

    # Fetches groups that deploy user belongs to
    #
    def groups_command
      "groups #{user}"
    end

    def add_to_group_command to_group
      "#{try_sudo} usermod -a -G #{to_group} #{user}"
    end

    def remove_from_group_command from_group
      "#{try_sudo} deluser #{user} #{from_group}"
    end

    namespace :users do
      desc "Get groups that deploy user belongs to"
      task :groups do
        run groups_command
      end

      desc "Add user to group, 'cap users:add_to_group GROUP=developers'."
      task :add_to_group do
        if ENV['GROUP']
          run add_to_group_command(ENV['GROUP'])
          run "id #{user}"
        else
          raise "Usage: 'cap users:add_to_group GROUP=developers'"
        end
      end

      desc "Remove user from group, 'cap users:remove_from_group GROUP=developers'"
      task :remove_from_group do
        if ENV['GROUP']
          run remove_from_group_command(ENV['GROUP'])
          run "id #{user}"
        else
          raise "Usage: 'cap users:remove_from_group_command GROUP=developers'"
        end
      end

    end
  end
end