mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 03:12:55 +09:00
Feature #687: ACL string syntax for oneacl
This commit is contained in:
1 parent
7520a50dd3
commit
19d3db124e
5 files changed
+93
-76
No files matched your search
+14
-8
@@ -1,25 +1,31 @@
|
||||
---
|
||||
:ID:
|
||||
:desc: To which resource owner the rule applies to
|
||||
:size: 5
|
||||
:right: true
|
||||
|
||||
:USER:
|
||||
:desc: To which resource owner the rule applies to
|
||||
:size: 4
|
||||
:size: 8
|
||||
:right: true
|
||||
|
||||
:RESOURCE_VHNIUTG:
|
||||
:RES_VHNIUTG:
|
||||
:desc: Which resource the rule applies to
|
||||
:size: 16
|
||||
:size: 11
|
||||
|
||||
:RID:
|
||||
:desc: Resource ID
|
||||
:size: 4
|
||||
:size: 5
|
||||
:right: true
|
||||
|
||||
:OPERATION_CDUMIPpTW:
|
||||
:OPE_CDUMIPpTW:
|
||||
:desc: Operation to which the rule applies
|
||||
:size: 19
|
||||
:size: 13
|
||||
:right: true
|
||||
|
||||
:default:
|
||||
- :ID
|
||||
- :USER
|
||||
- :RESOURCE_VHNIUTG
|
||||
- :RES_VHNIUTG
|
||||
- :RID
|
||||
- :OPERATION_CDUMIPpTW
|
||||
- :OPE_CDUMIPpTW
|
||||
@@ -24,6 +24,43 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
|
||||
def self.conf_file
|
||||
"oneacl.yaml"
|
||||
end
|
||||
|
||||
def add_rule(options, arg0, arg1=nil, arg2=nil)
|
||||
aclp = OpenNebula::AclPool.new( OpenNebula::Client.new() )
|
||||
|
||||
if arg2
|
||||
rc = aclp.addrule( arg0, arg1, arg2 )
|
||||
else
|
||||
rc = aclp.addrule_with_str( arg0 )
|
||||
end
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
if !rc
|
||||
puts "Rule added" if options[:verbose]
|
||||
return 0
|
||||
end
|
||||
return [-1, rc[:users].message] if OpenNebula.is_error?(rc[:users])
|
||||
return [-1, rc[:resources].message] if OpenNebula.is_error?(
|
||||
rc[:resources])
|
||||
return [-1, rc[:rights].message] if OpenNebula.is_error?(
|
||||
rc[:rights])
|
||||
end
|
||||
end
|
||||
|
||||
def delete_rule(id)
|
||||
acl = OpenNebula::AclPool.new( OpenNebula::Client.new() )
|
||||
|
||||
rc = acl.delrule( id )
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
puts "Rule deleted" if options[:verbose]
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -92,27 +129,33 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
|
||||
config_file=self.class.table_conf
|
||||
|
||||
table=CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "Rule Identifier",
|
||||
:size=>5 do |d|
|
||||
d['ID']
|
||||
end
|
||||
|
||||
column :USER, "To which resource owner the rule applies to",
|
||||
:size=>4 do |d|
|
||||
:size=>8 do |d|
|
||||
d['STRING'].split(" ")[0]
|
||||
end
|
||||
|
||||
column :RESOURCE_VHNIUTG, "Resource to which the rule applies" do |d|
|
||||
column :RES_VHNIUTG, "Resource to which the rule applies" do |d|
|
||||
OneAclHelper::resource_mask d['STRING'].split(" ")[1]
|
||||
end
|
||||
|
||||
column :RID, "Resource ID", :right, :size=>4 do |d|
|
||||
column :RID, "Resource ID", :right, :size=>8 do |d|
|
||||
d['STRING'].split(" ")[1].split("/")[1]
|
||||
end
|
||||
|
||||
column :OPERATION_CDUMIPpTW, "Operation to which the rule applies" do |d|
|
||||
column :OPE_CDUMIPpTW, "Operation to which the rule applies" do |d|
|
||||
OneAclHelper::right_mask d['STRING'].split(" ")[2]
|
||||
end
|
||||
|
||||
default :USER, :RESOURCE_VHNIUTG, :RID, :OPERATION_CDUMIPpTW
|
||||
default :ID, :USER, :RESOURCE_VHNIUTG, :RID, :OPERATION_CDUMIPpTW
|
||||
end
|
||||
|
||||
table.show(pool, options)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
+4
-23
@@ -54,17 +54,8 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
Adds a new ACL rule
|
||||
EOT
|
||||
|
||||
command :addrule, addrule_desc, :user, :resource, :rights do
|
||||
acl = OpenNebula::AclPool.new( OpenNebula::Client.new() )
|
||||
|
||||
rc = acl.addrule( args[0], args[1], args[2] )
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
puts "Rule added" if options[:verbose]
|
||||
0
|
||||
end
|
||||
command :addrule, addrule_desc, [:user,:rulestr], [:resource, nil], [:rights, nil] do
|
||||
helper.add_rule(options, args[0], args[1], args[2] )
|
||||
end
|
||||
|
||||
delrule_desc = <<-EOT.unindent
|
||||
@@ -72,17 +63,7 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :delrule, delrule_desc, :id do
|
||||
acl = OpenNebula::Acl.new( OpenNebula::Client.new() )
|
||||
|
||||
rc = acl.delrule( args[0] )
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
[-1, rc.message]
|
||||
else
|
||||
puts "Rule deleted" if options[:verbose]
|
||||
0
|
||||
end
|
||||
|
||||
helper.delete_rule( args[0] )
|
||||
end
|
||||
|
||||
list_desc = <<-EOT.unindent
|
||||
@@ -90,6 +71,6 @@ cmd = CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :list, list_desc,:options=>OpenNebulaHelper::XML do
|
||||
helper.list_pool(options)
|
||||
helper.list_pool( options )
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user