base.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 driver
  15. import (
  16. "yunion.io/x/pkg/object"
  17. api "yunion.io/x/onecloud/pkg/apis/identity"
  18. )
  19. var (
  20. idpDriverClasses = make(map[string]IIdentityBackendClass)
  21. )
  22. func RegisterDriverClass(drv IIdentityBackendClass) {
  23. idpDriverClasses[drv.Name()] = drv
  24. }
  25. func GetDriverClass(drv string) IIdentityBackendClass {
  26. if cls, ok := idpDriverClasses[drv]; ok {
  27. return cls
  28. }
  29. return nil
  30. }
  31. func GetDriver(driver string, idpId, idpName, template, targetDomainId string, conf api.TConfigs) (IIdentityBackend, error) {
  32. drvCls := GetDriverClass(driver)
  33. if drvCls == nil {
  34. return nil, ErrNoSuchDriver
  35. }
  36. return drvCls.NewDriver(idpId, idpName, template, targetDomainId, conf)
  37. }
  38. type SBaseIdentityDriver struct {
  39. object.SObject
  40. Config api.TConfigs
  41. IdpId string
  42. IdpName string
  43. Template string
  44. TargetDomainId string
  45. // AutoCreateProject bool
  46. }
  47. func (base *SBaseIdentityDriver) IIdentityBackend() IIdentityBackend {
  48. return base.GetVirtualObject().(IIdentityBackend)
  49. }
  50. func (base *SBaseIdentityDriver) GetSsoCallbackUri(callbackUrl string) string {
  51. return callbackUrl
  52. }
  53. func NewBaseIdentityDriver(idpId, idpName, template, targetDomainId string, conf api.TConfigs) (SBaseIdentityDriver, error) {
  54. drv := SBaseIdentityDriver{}
  55. drv.IdpId = idpId
  56. drv.IdpName = idpName
  57. drv.Template = template
  58. drv.TargetDomainId = targetDomainId
  59. // drv.AutoCreateProject = autoCreateProject
  60. drv.Config = conf
  61. return drv, nil
  62. }