Class: Superhosting::Controller::Admin::Container

Inherits:
Base
  • Object
show all
Defined in:
lib/superhosting/controller/admin/container.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #lib

Instance Method Summary collapse

Methods inherited from Base

#repair

Methods inherited from Base

#get_base_controller_options, #get_controller

Methods included from Helpers

#instance_variables_to_hash

Methods included from Helper::Config

#_config, #_config_options, #_save_registry!, #apply, #configure, #configure_with_apply, #reconfig, #unapply, #unconfigure, #unconfigure_with_unapply

Methods included from Helper::Cmd

#_command, #_command_without_debug, #command, #command!

Methods included from Helper::File

#chmod!, #chown!, #chown_r!, #safe_link!, #safe_unlink!

Methods included from Helper::Logger

#__debug, #__dry_run, #__dry_run=, #__logger, #__logger=, #debug, #debug_block, #debug_operation, #indent, #indent=, #indent_reset, #indent_step, #indent_step_back, #info, #storage, #t, #with_dry_run, #with_indent, #with_logger

Constructor Details

#initialize(name:, **kwargs) ⇒ Container

Returns a new instance of Container.



5
6
7
8
9
10
11
12
13
14
# File 'lib/superhosting/controller/admin/container.rb', line 5

def initialize(name:, **kwargs)
  super(kwargs)
  @admin_name = name
  @user_controller = self.get_controller(User)
  @admin_controller = self.get_controller(Admin)
  @container_controller = self.get_controller(Controller::Container)
  @admin_passwd = @config.admins.f(@admin_name).passwd

  @admin_controller.existing_validation(name: @admin_name).net_status_ok!
end

Instance Method Details

#_containers_listObject



50
51
52
53
54
55
56
57
# File 'lib/superhosting/controller/admin/container.rb', line 50

def _containers_list
  if (resp = self.list).net_status_ok?
    containers = resp[:data].map {|elm| elm[:container] }
    { data: containers }
  else
    resp
  end
end

#_delete_all_usersObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/superhosting/controller/admin/container.rb', line 68

def _delete_all_users
  if (resp = self._containers_list).net_status_ok?
    containers = resp[:data]
    containers.each do |container_name|
      unless (resp = self.delete(name: container_name)).net_status_ok?
        return resp
      end
    end
    {}
  else
    resp
  end
end

#_users_listObject



59
60
61
62
63
64
65
66
# File 'lib/superhosting/controller/admin/container.rb', line 59

def _users_list
  if (resp = self.list).net_status_ok?
    users = resp[:data].map {|elm| elm[:user] }
    { data: users }
  else
    resp
  end
end

#add(name:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/superhosting/controller/admin/container.rb', line 27

def add(name:)
  admin_name = "admin_#{@admin_name}"

  if (resp = @container_controller.available_validation(name: name)).net_status_ok? and
      (resp = @user_controller.not_existing_validation(name: admin_name, container_name: name)).net_status_ok?
    user, encrypted_password = @admin_passwd.split(':')
    if (resp = @user_controller._add(name: admin_name, container_name: name, shell: '/bin/bash')).net_status_ok?
      resp = encrypted_password.nil? ? {} : @user_controller._update_password(name: "#{name}_#{admin_name}", encrypted_password: encrypted_password)
    end
  end
  resp
end

#delete(name:) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/superhosting/controller/admin/container.rb', line 40

def delete(name:)
  admin_name = "admin_#{@admin_name}"

  if (resp = @container_controller.available_validation(name: name)).net_status_ok? and
      (resp = @user_controller.existing_validation(name: admin_name, container_name: name)).net_status_ok?
    resp = @user_controller.delete(name: admin_name, container_name: name)
  end
  resp
end

#listObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/superhosting/controller/admin/container.rb', line 16

def list
  containers = @container_controller._list
  container_users = containers.map do |container_name, data|
    unless @user_controller._get(name: "#{container_name}_admin_#{@admin_name}").nil?
      { container: container_name, user: "#{container_name}_admin_#{@admin_name}" }
    end
  end.compact

  { data: container_users }
end