You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

storage.go 4.2 kB

1 year ago
1 year ago
10 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package cdssdk
  2. import (
  3. "fmt"
  4. "gitlink.org.cn/cloudream/common/pkgs/types"
  5. "gitlink.org.cn/cloudream/common/utils/serder"
  6. )
  7. type Storage struct {
  8. StorageID StorageID `json:"storageID" gorm:"column:StorageID; primaryKey; type:bigint; autoIncrement;"`
  9. Name string `json:"name" gorm:"column:Name; type:varchar(256); not null"`
  10. // 完全管理此存储服务的Hub的ID
  11. MasterHub HubID `json:"masterHub" gorm:"column:MasterHub; type:bigint; not null"`
  12. // 存储服务的类型,包含地址信息以及鉴权所需数据
  13. Type StorageType `json:"type" gorm:"column:Type; type:json; not null; serializer:union"`
  14. // 分片存储服务的配置数据
  15. ShardStore ShardStoreConfig `json:"shardStore" gorm:"column:ShardStore; type:json; serializer:union"`
  16. // 共享存储服务的配置数据
  17. PublicStore PublicStoreConfig `json:"publicStore" gorm:"column:PublicStore; type:json; serializer:union"`
  18. // 存储服务拥有的特别功能
  19. Features []StorageFeature `json:"features" gorm:"column:Features; type:json; serializer:union"`
  20. }
  21. func (Storage) TableName() string {
  22. return "Storage"
  23. }
  24. func (s *Storage) String() string {
  25. return fmt.Sprintf("%v(%v)", s.Name, s.StorageID)
  26. }
  27. // 存储服务地址
  28. type StorageType interface {
  29. GetStorageType() string
  30. // 输出调试用的字符串,不要包含敏感信息
  31. String() string
  32. }
  33. var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[StorageType](
  34. (*MashupStorageType)(nil),
  35. (*LocalStorageType)(nil),
  36. (*OBSType)(nil),
  37. (*OSSType)(nil),
  38. (*COSType)(nil),
  39. (*EFileType)(nil),
  40. )), "type")
  41. // 多种存储服务的混合存储服务。需谨慎选择存储服务的组合,避免出Bug
  42. type MashupStorageType struct {
  43. serder.Metadata `union:"Mashup"`
  44. Type string `json:"type"`
  45. Agent StorageType `json:"agent"` // 创建Agent时,使用的存储服务类型
  46. Feature StorageType `json:"feature"` // 根据Feature创建组件时使用的存储服务类型
  47. }
  48. func (a *MashupStorageType) GetStorageType() string {
  49. return "Mashup"
  50. }
  51. func (a *MashupStorageType) String() string {
  52. return "Mashup"
  53. }
  54. type LocalStorageType struct {
  55. serder.Metadata `union:"Local"`
  56. Type string `json:"type"`
  57. }
  58. func (a *LocalStorageType) GetStorageType() string {
  59. return "Local"
  60. }
  61. func (a *LocalStorageType) String() string {
  62. return "Local"
  63. }
  64. type OSSType struct {
  65. serder.Metadata `union:"OSS"`
  66. Type string `json:"type"`
  67. Region string `json:"region"`
  68. AK string `json:"accessKeyId"`
  69. SK string `json:"secretAccessKey"`
  70. Endpoint string `json:"endpoint"`
  71. Bucket string `json:"bucket"`
  72. }
  73. func (a *OSSType) GetStorageType() string {
  74. return "OSS"
  75. }
  76. func (a *OSSType) String() string {
  77. return "OSS"
  78. }
  79. type OBSType struct {
  80. serder.Metadata `union:"OBS"`
  81. Type string `json:"type"`
  82. Region string `json:"region"`
  83. AK string `json:"accessKeyId"`
  84. SK string `json:"secretAccessKey"`
  85. Endpoint string `json:"endpoint"`
  86. Bucket string `json:"bucket"`
  87. ProjectID string `json:"projectID"`
  88. }
  89. func (a *OBSType) GetStorageType() string {
  90. return "OBS"
  91. }
  92. func (a *OBSType) String() string {
  93. return "OBS"
  94. }
  95. type COSType struct {
  96. serder.Metadata `union:"COS"`
  97. Type string `json:"type"`
  98. Region string `json:"region"`
  99. AK string `json:"accessKeyId"`
  100. SK string `json:"secretAccessKey"`
  101. Endpoint string `json:"endpoint"`
  102. Bucket string `json:"bucket"`
  103. }
  104. func (a *COSType) GetStorageType() string {
  105. return "COS"
  106. }
  107. func (a *COSType) String() string {
  108. return "COS"
  109. }
  110. type EFileType struct {
  111. serder.Metadata `union:"EFile"`
  112. Type string `json:"type"`
  113. TokenURL string `json:"tokenURL"`
  114. APIURL string `json:"apiURL"`
  115. TokenExpire int `json:"tokenExpire"` // 单位秒
  116. User string `json:"user"`
  117. Password string `json:"password"`
  118. OrgID string `json:"orgID"`
  119. ClusterID string `json:"clusterID"`
  120. }
  121. func (a *EFileType) GetStorageType() string {
  122. return "EFile"
  123. }
  124. func (a *EFileType) String() string {
  125. return "EFile"
  126. }