Skip to content
Snippets Groups Projects
Select Git revision
  • 7e41041b931c9d76850e92f361ba6d23c924f519
  • live_exam_os_ubuntu default protected
2 results

vmDelAccess.go

Blame
  • vmDelAccess.go 880 B
    package cmdVM
    
    import (
    	u "nexus-client/utils"
    	g "nexus-client/globals"
    )
    
    type DelAccess struct {
        Name string
    }
    
    func (cmd *DelAccess)GetName() string {
    	return cmd.Name
    }
     
    func (cmd *DelAccess)GetDesc() string {
    	return "Delete the VM access for a given user."
    }
    
    func (cmd *DelAccess)PrintUsage() {
    	u.PrintlnErr(cmd.GetDesc())
    	u.PrintlnErr("Usage: "+cmd.Name+" vmID email")
    }
    
    func (cmd *DelAccess)Run(args []string) int {
    	client := g.GetInstance().Client
    	host := g.GetInstance().Host
    
    	argc := len(args)
    	if argc != 2 {
    		cmd.PrintUsage()
    		return 1
    	}
    
    	vmID := args[0]
    	email := args[1]
    
    	resp, err := client.R().Delete(host+"/vms/"+vmID+"/access/"+email)
    	if err != nil {
    		u.PrintlnErr("Error: "+err.Error())
    		return 1
    	}
    
    	if resp.IsSuccess() {
    		u.Println(resp)
    		return 0
    	} else {
    		u.PrintlnErr("Error: "+resp.Status()+": "+resp.String())
    		return 1
    	}
    }