info.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package ldap
  15. import (
  16. "yunion.io/x/pkg/errors"
  17. "yunion.io/x/onecloud/pkg/keystone/options"
  18. )
  19. const (
  20. ErrEmptyDN = errors.Error("empty DN")
  21. ErrEmptyId = errors.Error("empty id")
  22. ErrEmptyName = errors.Error("empty name")
  23. ErrDisabledUser = errors.Error("disabled user")
  24. )
  25. type SDomainInfo struct {
  26. DN string
  27. Id string
  28. Name string
  29. }
  30. type SUserInfo struct {
  31. SDomainInfo
  32. Enabled bool
  33. Extra map[string]string
  34. }
  35. type SGroupInfo struct {
  36. SDomainInfo
  37. Members []string
  38. }
  39. func (info SDomainInfo) isValid() error {
  40. if len(info.DN) == 0 {
  41. return ErrEmptyDN
  42. }
  43. if len(info.Id) == 0 {
  44. return ErrEmptyId
  45. }
  46. if len(info.Name) == 0 {
  47. return ErrEmptyName
  48. }
  49. return nil
  50. }
  51. func (info SUserInfo) isValid() error {
  52. err := info.SDomainInfo.isValid()
  53. if err != nil {
  54. return err
  55. }
  56. // regarding disabled LDAP user as invalid
  57. if !options.Options.LdapSyncDisabledUsers && !info.Enabled {
  58. return ErrDisabledUser
  59. }
  60. return nil
  61. }