MCPcopy Index your code
hub / github.com/coder/coder / RoleNameFromString

Function RoleNameFromString

coderd/rbac/roles.go:73–99  ·  view source on GitHub ↗

RoleNameFromString takes a formatted string ' [:org_id]'.

(input string)

Source from the content-addressed store, hash-verified

71
72// RoleNameFromString takes a formatted string '<role_name>[:org_id]'.
73func RoleNameFromString(input string) (RoleIdentifier, error) {
74 var role RoleIdentifier
75
76 arr := strings.Split(input, ":")
77 if len(arr) > 2 {
78 return role, xerrors.Errorf("too many colons in role name")
79 }
80
81 if len(arr) == 0 {
82 return role, xerrors.Errorf("empty string not a valid role")
83 }
84
85 if arr[0] == "" {
86 return role, xerrors.Errorf("role cannot be the empty string")
87 }
88
89 role.Name = arr[0]
90
91 if len(arr) == 2 {
92 orgID, err := uuid.Parse(arr[1])
93 if err != nil {
94 return role, xerrors.Errorf("%q not a valid uuid: %w", arr[1], err)
95 }
96 role.OrganizationID = orgID
97 }
98 return role, nil
99}
100
101func (r RoleIdentifier) String() string {
102 if r.OrganizationID != uuid.Nil {

Callers 2

RoleNamesMethod · 0.92
UnmarshalJSONMethod · 0.85

Calls 2

ParseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected