acl_config.go 1.2 KB

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