1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

B #4134: Permissions changes (breaking) (#4142)

* Remove permission pointers
* Update helpers

Signed-off-by: Pierre Lafievre <pierre.lafievre@iguanesolutions.com>
This commit is contained in:
Pierre Lafievre 2020-01-30 18:18:20 +01:00 committed by GitHub
parent c2eb293393
commit 20a5d5e5c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 47 additions and 38 deletions

View File

@ -129,7 +129,8 @@ func (dc *DatastoreController) Update(tpl string, uType parameters.UpdateType) e
// Chmod changes the permission bits of a datastore.
func (dc *DatastoreController) Chmod(perm *shared.Permissions) error {
_, err := dc.c.Client.Call("one.datastore.chmod", perm.ToArgs(dc.ID)...)
args := append([]interface{}{dc.ID}, perm.ToArgs()...)
_, err := dc.c.Client.Call("one.datastore.chmod", args...)
return err
}

View File

@ -143,8 +143,9 @@ func (dc *DocumentController) Update(tpl string, uType parameters.UpdateType) er
}
// Chmod changes the permission bits of a document.
func (dc *DocumentController) Chmod(perm *shared.Permissions) error {
_, err := dc.c.Client.Call("one.document.chmod", perm.ToArgs(dc.ID)...)
func (dc *DocumentController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{dc.ID}, perm.ToArgs()...)
_, err := dc.c.Client.Call("one.document.chmod", args...)
return err
}

View File

@ -157,8 +157,10 @@ func (ic *ImageController) Chown(uid, gid int) error {
// Chmod changes the permissions of the image. If any perm is -1 it will not
// change
func (ic *ImageController) Chmod(perm *shared.Permissions) error {
_, err := ic.c.Client.Call("one.image.chmod", perm.ToArgs(ic.ID)...)
func (ic *ImageController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{ic.ID}, perm.ToArgs()...)
_, err := ic.c.Client.Call("one.image.chmod", args...)
return err
}

View File

@ -133,8 +133,10 @@ func (mc *MarketPlaceController) Update(tpl string, uType parameters.UpdateType)
}
// Chmod changes the permission bits of a marketplace
func (mc *MarketPlaceController) Chmod(perm *shared.Permissions) error {
_, err := mc.c.Client.Call("one.market.chmod", perm.ToArgs(mc.ID)...)
func (mc *MarketPlaceController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{mc.ID}, perm.ToArgs()...)
_, err := mc.c.Client.Call("one.market.chmod", args...)
return err
}

View File

@ -86,7 +86,7 @@ func TestMarketplace(t *testing.T) {
}
//Change permissions for Marketpkace
err = marketCtrl.Chmod(&shared.Permissions{1, 1, 1, 1, 1, 1, 1, 1, 1})
err = marketCtrl.Chmod(shared.Permissions{1, 1, 1, 1, 1, 1, 1, 1, 1})
if err != nil {
t.Errorf("Test failed:\n" + err.Error())

View File

@ -141,8 +141,9 @@ func (mc *MarketPlaceAppController) Update(tpl string, uType parameters.UpdateTy
}
// Chmod changes the permission bits of a marketplace app
func (mc *MarketPlaceAppController) Chmod(perm *shared.Permissions) error {
_, err := mc.c.Client.Call("one.marketapp.chmod", perm.ToArgs(mc.ID)...)
func (mc *MarketPlaceAppController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{mc.ID}, perm.ToArgs()...)
_, err := mc.c.Client.Call("one.marketapp.chmod", args...)
return err
}

View File

@ -40,17 +40,20 @@ type Permissions struct {
var permStr = [8]string{"---", "--a", "-m-", "-ma", "u--", "u-a", "um-", "uma"}
func NewDefaultPermission() Permissions {
return Permissions{-1, -1, -1, -1, -1, -1, -1, -1, -1}
}
// If a bit is set to -1, it will not change when calling Chmod
func (p *Permissions) ToArgs(id int) []interface{} {
func (p Permissions) ToArgs() []interface{} {
return []interface{}{
id,
p.OwnerU, p.OwnerM, p.OwnerA,
p.GroupU, p.GroupM, p.GroupA,
p.OtherU, p.OtherM, p.OtherA,
}
}
func (p *Permissions) String() string {
func (p Permissions) String() string {
owner := permStr[p.OwnerU<<2|p.OwnerM<<1|p.OwnerA]
group := permStr[p.GroupU<<2|p.GroupM<<1|p.GroupA]
other := permStr[p.OtherU<<2|p.OtherM<<1|p.OtherA]

View File

@ -150,8 +150,9 @@ func (sc *SecurityGroupController) Commit(recovery bool) error {
}
// Chmod changes the permission bits of a security group
func (sc *SecurityGroupController) Chmod(perm *shared.Permissions) error {
_, err := sc.c.Client.Call("one.secgroup.chmod", perm.ToArgs(sc.ID)...)
func (sc *SecurityGroupController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{sc.ID}, perm.ToArgs()...)
_, err := sc.c.Client.Call("one.secgroup.chmod", args...)
return err
}

View File

@ -109,7 +109,7 @@ func TestSGAllocate(t *testing.T) {
testCtrl.SecurityGroup(clone_id).Delete()
//Change permission of SG
err = sgC.Chmod(&shared.Permissions{1, 1, 1, 1, 1, 1, 1, 1, 1})
err = sgC.Chmod(shared.Permissions{1, 1, 1, 1, 1, 1, 1, 1, 1})
if err != nil {
t.Errorf("Test failed:\n" + err.Error())

View File

@ -134,8 +134,9 @@ func (tc *TemplateController) Chown(uid, gid int) error {
// Chmod changes the permissions of a template. If any perm is -1 it will not
// change
func (tc *TemplateController) Chmod(perm *shared.Permissions) error {
_, err := tc.c.Client.Call("one.template.chmod", perm.ToArgs(tc.ID)...)
func (tc *TemplateController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{tc.ID}, perm.ToArgs()...)
_, err := tc.c.Client.Call("one.template.chmod", args...)
return err
}

View File

@ -194,8 +194,9 @@ func (vc *VirtualNetworkController) Update(tpl string, uType parameters.UpdateTy
}
// Chmod changes the permission bits of a virtual network.
func (vc *VirtualNetworkController) Chmod(perm *shared.Permissions) error {
_, err := vc.c.Client.Call("one.vn.chmod", perm.ToArgs(vc.ID)...)
func (vc *VirtualNetworkController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{vc.ID}, perm.ToArgs()...)
_, err := vc.c.Client.Call("one.vn.chmod", args...)
return err
}

View File

@ -144,8 +144,10 @@ func (vc *VirtualRouterController) Chown(uid, gid int) error {
// Chmod changes the permissions of a virtual router. If any perm is -1 it will not
// change
func (vc *VirtualRouterController) Chmod(perm *shared.Permissions) error {
_, err := vc.c.Client.Call("one.vrouter.chmod", perm.ToArgs(vc.ID)...)
func (vc *VirtualRouterController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{vc.ID}, perm.ToArgs()...)
_, err := vc.c.Client.Call("one.vrouter.chmod", args...)
return err
}

View File

@ -89,7 +89,7 @@ func TestVirtualRouter(t *testing.T) {
}
//Change permissions of VirtualRouter
err = vrC.Chmod(&shared.Permissions{1, 1, 1, 1, 1, 1, 1, 1, 1})
err = vrC.Chmod(shared.Permissions{1, 1, 1, 1, 1, 1, 1, 1, 1})
if err != nil {
t.Errorf("Test failed:\n" + err.Error())

View File

@ -285,8 +285,9 @@ func (vc *VMController) Chown(uid, gid int) error {
// Chmod changes the permissions of a VM. If any perm is -1 it will not
// change
func (vc *VMController) Chmod(perm *shared.Permissions) error {
_, err := vc.c.Client.Call("one.vm.chmod", perm.ToArgs(vc.ID)...)
func (vc *VMController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{vc.ID}, perm.ToArgs()...)
_, err := vc.c.Client.Call("one.vm.chmod", args...)
return err
}

View File

@ -137,17 +137,9 @@ func (vc *VMGroupController) Update(tpl string, uType int) error {
}
// Chmod changes the permission bits of a vmGroup.
// * uu: USER USE bit. If set to -1, it will not change.
// * um: USER MANAGE bit. If set to -1, it will not change.
// * ua: USER ADMIN bit. If set to -1, it will not change.
// * gu: GROUP USE bit. If set to -1, it will not change.
// * gm: GROUP MANAGE bit. If set to -1, it will not change.
// * ga: GROUP ADMIN bit. If set to -1, it will not change.
// * ou: OTHER USE bit. If set to -1, it will not change.
// * om: OTHER MANAGE bit. If set to -1, it will not change.
// * oa: OTHER ADMIN bit. If set to -1, it will not change.
func (vc *VMGroupController) Chmod(uu, um, ua, gu, gm, ga, ou, om, oa int) error {
_, err := vc.c.Client.Call("one.vmgroup.chmod", vc.ID, uu, um, ua, gu, gm, ga, ou, om, oa)
func (vc *VMGroupController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{vc.ID}, perm.ToArgs()...)
_, err := vc.c.Client.Call("one.vmgroup.chmod", args...)
return err
}

View File

@ -137,8 +137,9 @@ func (vc *VNTemplateController) Chown(uid, gid int) error {
// Chmod changes the permissions of a vntemplate. If any perm is -1 it will not
// change
func (vc *VNTemplateController) Chmod(perm *shared.Permissions) error {
_, err := vc.c.Client.Call("one.vntemplate.chmod", perm.ToArgs(vc.ID)...)
func (vc *VNTemplateController) Chmod(perm shared.Permissions) error {
args := append([]interface{}{vc.ID}, perm.ToArgs()...)
_, err := vc.c.Client.Call("one.vntemplate.chmod", args...)
return err
}