Class: Wdmc::Acl

Inherits:
Thor
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wdmc/acl.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Acl

Returns a new instance of Acl.



7
8
9
10
# File 'lib/wdmc/acl.rb', line 7

def initialize(*args)
  @wdmc = Wdmc::Client.new
  super
end

Instance Method Details

#delete(name) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/wdmc/acl.rb', line 74

def delete( name )
  share_exists = @wdmc.share_exists?( name )
  abort "\nShare does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless share_exists.include?( name )
  begin
    data = {
      :share_name => name,
      :username => options['user']
    }
    unless options['force']
      puts "\nYou are going to delete #{options['access']} access for user #{options['user']} to #{name}".color(:orange)
      return unless yes?("DELETE? (yes/no): ")
    end
    puts "Remove ACL:\s".color(:whitesmoke) + "OK".color(:green) if @wdmc.delete_acl( data )
    share = @wdmc.get_acl( name )
    share[:share_access].map do |access|
      puts "\s- Username\t:\s".color(:whitesmoke) + access[:username]
      puts "\s- User ID\t:\s".color(:whitesmoke) + access[:user_id]
      puts "\s- Access\t:\s".color(:whitesmoke) + access[:access].color(:green) if access[:access] == 'RW'
      puts "\s- Access\t:\s".color(:whitesmoke) + access[:access].color(:yellow) if access[:access] == 'RO'
      puts
    end
  rescue RestClient::ExceptionWithResponse => e
    puts e.response
  end
end

#edit(name) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wdmc/acl.rb', line 48

def edit( name )
  share_exists = @wdmc.share_exists?( name )
  abort "\nShare does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless share_exists.include?( name )
  begin
    data = {
      :share_name => name,
      :username => options['user'],
      :access => options['access']
    }
    puts "Modify ACL:\s".color(:whitesmoke) + "OK".color(:green) if @wdmc.modify_acl( data )
    share = @wdmc.get_acl( name )
    share[:share_access].map do |access|
      puts "\s- Username\t:\s".color(:whitesmoke) + access[:username]
      puts "\s- User ID\t:\s".color(:whitesmoke) + access[:user_id]
      puts "\s- Access\t:\s".color(:whitesmoke) + access[:access].color(:green) if access[:access] == 'RW'
      puts "\s- Access\t:\s".color(:whitesmoke) + access[:access].color(:yellow) if access[:access] == 'RO'
      puts
    end
  rescue RestClient::ExceptionWithResponse => e
    puts e.response
  end
end

#get(name) ⇒ Object



13
14
15
16
17
# File 'lib/wdmc/acl.rb', line 13

def get( name )
  share_exists = @wdmc.share_exists?( name )
  abort "\nShare does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless share_exists.include?( name )
  Wdmc::Share.new.show( name )
end

#set(name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wdmc/acl.rb', line 22

def set( name )
  share_exists = @wdmc.share_exists?( name )
  abort "\nShare does not exist: ".color(:yellow) + "#{name}".color(:cyan) unless share_exists.include?( name )
  begin
    data = {
      :share_name => name,
      :username => options['user'],
      :access => options['access']
    }
    puts "Set ACL:\s".color(:whitesmoke) + "OK".color(:green) if @wdmc.set_acl( data )
    share = @wdmc.get_acl( name )
    share[:share_access].map do |access|
      puts "\s- Username\t:\s".color(:whitesmoke) + access[:username]
      puts "\s- User ID\t:\s".color(:whitesmoke) + access[:user_id]
      puts "\s- Access\t:\s".color(:whitesmoke) + access[:access].color(:green) if access[:access] == 'RW'
      puts "\s- Access\t:\s".color(:whitesmoke) + access[:access].color(:yellow) if access[:access] == 'RO'
      puts
    end
  rescue RestClient::ExceptionWithResponse => e
    puts e.response
  end
end