| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | package accesscontrol | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-07 18:30:45 +08:00
										 |  |  | import ( | 
					
						
							|  |  |  | 	"errors" | 
					
						
							|  |  |  | 	"fmt" | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | var ( | 
					
						
							|  |  |  | 	ErrFixedRolePrefixMissing = errors.New("fixed role should be prefixed with '" + FixedRolePrefix + "'") | 
					
						
							|  |  |  | 	ErrInvalidBuiltinRole     = errors.New("built-in role is not valid") | 
					
						
							| 
									
										
										
										
											2022-01-19 00:34:35 +08:00
										 |  |  | 	ErrInvalidScope           = errors.New("invalid scope") | 
					
						
							| 
									
										
										
										
											2022-08-25 18:50:27 +08:00
										 |  |  | 	ErrResolverNotFound       = errors.New("no resolver found") | 
					
						
							| 
									
										
										
										
											2022-11-07 18:30:45 +08:00
										 |  |  | 	ErrPluginIDRequired       = errors.New("plugin ID is required") | 
					
						
							| 
									
										
										
										
											2023-05-09 19:19:38 +08:00
										 |  |  | 	ErrRoleNotFound           = errors.New("role not found") | 
					
						
							| 
									
										
										
										
											2021-08-04 20:44:37 +08:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2022-11-07 18:30:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type ErrorInvalidRole struct{} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (e *ErrorInvalidRole) Error() string { | 
					
						
							|  |  |  | 	return "role is invalid" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type ErrorRolePrefixMissing struct { | 
					
						
							|  |  |  | 	Role     string | 
					
						
							|  |  |  | 	Prefixes []string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (e *ErrorRolePrefixMissing) Error() string { | 
					
						
							|  |  |  | 	return fmt.Sprintf("expected role '%s' to be prefixed with any of '%v'", e.Role, e.Prefixes) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (e *ErrorRolePrefixMissing) Unwrap() error { | 
					
						
							|  |  |  | 	return &ErrorInvalidRole{} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type ErrorActionPrefixMissing struct { | 
					
						
							|  |  |  | 	Action   string | 
					
						
							|  |  |  | 	Prefixes []string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (e *ErrorActionPrefixMissing) Error() string { | 
					
						
							|  |  |  | 	return fmt.Sprintf("expected action '%s' to be prefixed with any of '%v'", e.Action, e.Prefixes) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (e *ErrorActionPrefixMissing) Unwrap() error { | 
					
						
							|  |  |  | 	return &ErrorInvalidRole{} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-11-30 20:55:07 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type ErrorScopeTarget struct { | 
					
						
							|  |  |  | 	Action        string | 
					
						
							|  |  |  | 	Scope         string | 
					
						
							|  |  |  | 	ExpectedScope string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (e *ErrorScopeTarget) Error() string { | 
					
						
							|  |  |  | 	return fmt.Sprintf("expected action '%s' to be scoped with '%v', found '%v'", e.Action, e.ExpectedScope, e.Scope) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (e *ErrorScopeTarget) Unwrap() error { | 
					
						
							|  |  |  | 	return &ErrorInvalidRole{} | 
					
						
							|  |  |  | } |