nonlocal_users.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 models
  15. import (
  16. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  17. )
  18. // +onecloud:swagger-gen-ignore
  19. type SNonlocalUserManager struct {
  20. db.SModelBaseManager
  21. }
  22. var NonlocalUserManager *SNonlocalUserManager
  23. func init() {
  24. NonlocalUserManager = &SNonlocalUserManager{
  25. SModelBaseManager: db.NewModelBaseManager(
  26. SNonlocalUser{},
  27. "nonlocal_user",
  28. "nonlocal_user",
  29. "nonlocal_users",
  30. ),
  31. }
  32. NonlocalUserManager.SetVirtualObject(NonlocalUserManager)
  33. }
  34. /*
  35. +-----------+--------------+------+-----+---------+-------+
  36. | Field | Type | Null | Key | Default | Extra |
  37. +-----------+--------------+------+-----+---------+-------+
  38. | domain_id | varchar(64) | NO | PRI | NULL | |
  39. | name | varchar(255) | NO | PRI | NULL | |
  40. | user_id | varchar(64) | NO | UNI | NULL | |
  41. +-----------+--------------+------+-----+---------+-------+
  42. */
  43. type SNonlocalUser struct {
  44. db.SModelBase
  45. DomainId string `width:"64" charset:"ascii" primary:"true"`
  46. Name string `width:"191" charset:"utf8" primary:"true"`
  47. UserId string `width:"64" charset:"ascii" nullable:"false" index:"true"`
  48. }
  49. /*
  50. func (manager *SNonlocalUserManager) Register(ctx context.Context, domainId string, name string) (*SNonlocalUser, error) {
  51. key := fmt.Sprintf("%s-%s", domainId, name)
  52. lockman.LockRawObject(ctx, manager.Keyword(), key)
  53. defer lockman.ReleaseRawObject(ctx, manager.Keyword(), key)
  54. obj, err := db.NewModelObject(manager)
  55. if err != nil {
  56. return nil, errors.Wrap(err, "NewModelObject")
  57. }
  58. nonlocalUser := obj.(*SNonlocalUser)
  59. q := manager.Query().Equals("domain_id", domainId).Equals("name", name)
  60. err = q.First(nonlocalUser)
  61. if err == nil {
  62. return nonlocalUser, nil
  63. }
  64. if err != nil && err != sql.ErrNoRows {
  65. return nil, errors.Wrap(err, "Query")
  66. }
  67. pubId, err := IdmappingManager.registerIdMap(ctx, domainId, name, api.IdMappingEntityUser)
  68. if err != nil {
  69. return nil, errors.Wrap(err, "IdmappingManager.registerIdMap")
  70. }
  71. nonlocalUser.UserId = pubId
  72. nonlocalUser.Name = name
  73. nonlocalUser.DomainId = domainId
  74. err = manager.TableSpec().Insert(nonlocalUser)
  75. if err != nil {
  76. return nil, errors.Wrap(err, "Insert")
  77. }
  78. return nonlocalUser, nil
  79. }
  80. */