github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/models/role.go (about)

     1  package models
     2  
     3  import (
     4  	"errors"
     5  	"strings"
     6  )
     7  
     8  type Role int
     9  
    10  const (
    11  	RoleUnknown Role = iota - 1
    12  	RoleOrgUser
    13  	RoleOrgManager
    14  	RoleBillingManager
    15  	RoleOrgAuditor
    16  	RoleSpaceManager
    17  	RoleSpaceDeveloper
    18  	RoleSpaceAuditor
    19  )
    20  
    21  var ErrUnknownRole = errors.New("Unknown Role")
    22  
    23  func RoleFromString(roleString string) (Role, error) {
    24  	switch strings.ToLower(roleString) {
    25  	case "orgmanager":
    26  		return RoleOrgManager, nil
    27  	case "billingmanager":
    28  		return RoleBillingManager, nil
    29  	case "orgauditor":
    30  		return RoleOrgAuditor, nil
    31  	case "spacemanager":
    32  		return RoleSpaceManager, nil
    33  	case "spacedeveloper":
    34  		return RoleSpaceDeveloper, nil
    35  	case "spaceauditor":
    36  		return RoleSpaceAuditor, nil
    37  	default:
    38  		return RoleUnknown, ErrUnknownRole
    39  	}
    40  }
    41  
    42  func (r Role) ToString() string {
    43  	switch r {
    44  	case RoleUnknown:
    45  		return "RoleUnknown"
    46  	case RoleOrgUser:
    47  		return "RoleOrgUser"
    48  	case RoleOrgManager:
    49  		return "RoleOrgManager"
    50  	case RoleBillingManager:
    51  		return "RoleBillingManager"
    52  	case RoleOrgAuditor:
    53  		return "RoleOrgAuditor"
    54  	case RoleSpaceManager:
    55  		return "RoleSpaceManager"
    56  	case RoleSpaceDeveloper:
    57  		return "RoleSpaceDeveloper"
    58  	case RoleSpaceAuditor:
    59  		return "RoleSpaceAuditor"
    60  	default:
    61  		return ""
    62  	}
    63  }
    64  
    65  func (r Role) Display() string {
    66  	return strings.TrimPrefix(r.ToString(), "Role")
    67  }