acl_config.go 835 B

1234567891011121314151617181920212223242526
  1. package v2
  2. import "strings"
  3. var authenticationAllowlistMethods = map[string]bool{
  4. "/memos.api.v2.SystemService/GetSystemInfo": true,
  5. "/memos.api.v2.UserService/GetUser": true,
  6. "/memos.api.v2.MemoService/ListMemos": true,
  7. }
  8. // isUnauthorizeAllowedMethod returns whether the method is exempted from authentication.
  9. func isUnauthorizeAllowedMethod(fullMethodName string) bool {
  10. if strings.HasPrefix(fullMethodName, "/grpc.reflection") {
  11. return true
  12. }
  13. return authenticationAllowlistMethods[fullMethodName]
  14. }
  15. var allowedMethodsOnlyForAdmin = map[string]bool{
  16. "/memos.api.v2.UserService/CreateUser": true,
  17. }
  18. // isOnlyForAdminAllowedMethod returns true if the method is allowed to be called only by admin.
  19. func isOnlyForAdminAllowedMethod(methodName string) bool {
  20. return allowedMethodsOnlyForAdmin[methodName]
  21. }