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.7 kB

1 year ago
1 year ago
10 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. (*S3Type)(nil),
  41. )), "type")
  42. // 多种存储服务的混合存储服务。需谨慎选择存储服务的组合,避免出Bug
  43. type MashupStorageType struct {
  44. serder.Metadata `union:"Mashup"`
  45. Type string `json:"type"`
  46. Agent StorageType `json:"agent"` // 创建Agent时,使用的存储服务类型
  47. Feature StorageType `json:"feature"` // 根据Feature创建组件时使用的存储服务类型
  48. }
  49. func (a *MashupStorageType) GetStorageType() string {
  50. return "Mashup"
  51. }
  52. func (a *MashupStorageType) String() string {
  53. return "Mashup"
  54. }
  55. type LocalStorageType struct {
  56. serder.Metadata `union:"Local"`
  57. Type string `json:"type"`
  58. }
  59. func (a *LocalStorageType) GetStorageType() string {
  60. return "Local"
  61. }
  62. func (a *LocalStorageType) String() string {
  63. return "Local"
  64. }
  65. type OSSType struct {
  66. serder.Metadata `union:"OSS"`
  67. Type string `json:"type"`
  68. Region string `json:"region"`
  69. AK string `json:"accessKeyId"`
  70. SK string `json:"secretAccessKey"`
  71. Endpoint string `json:"endpoint"`
  72. Bucket string `json:"bucket"`
  73. }
  74. func (a *OSSType) GetStorageType() string {
  75. return "OSS"
  76. }
  77. func (a *OSSType) String() string {
  78. return "OSS"
  79. }
  80. type OBSType struct {
  81. serder.Metadata `union:"OBS"`
  82. Type string `json:"type"`
  83. Region string `json:"region"`
  84. AK string `json:"accessKeyId"`
  85. SK string `json:"secretAccessKey"`
  86. Endpoint string `json:"endpoint"`
  87. Bucket string `json:"bucket"`
  88. ProjectID string `json:"projectID"`
  89. }
  90. func (a *OBSType) GetStorageType() string {
  91. return "OBS"
  92. }
  93. func (a *OBSType) String() string {
  94. return "OBS"
  95. }
  96. type COSType struct {
  97. serder.Metadata `union:"COS"`
  98. Type string `json:"type"`
  99. Region string `json:"region"`
  100. AK string `json:"accessKeyId"`
  101. SK string `json:"secretAccessKey"`
  102. Endpoint string `json:"endpoint"`
  103. Bucket string `json:"bucket"`
  104. }
  105. func (a *COSType) GetStorageType() string {
  106. return "COS"
  107. }
  108. func (a *COSType) String() string {
  109. return "COS"
  110. }
  111. type EFileType struct {
  112. serder.Metadata `union:"EFile"`
  113. Type string `json:"type"`
  114. TokenURL string `json:"tokenURL"`
  115. APIURL string `json:"apiURL"`
  116. TokenExpire int `json:"tokenExpire"` // 单位秒
  117. User string `json:"user"`
  118. Password string `json:"password"`
  119. OrgID string `json:"orgID"`
  120. ClusterID string `json:"clusterID"`
  121. }
  122. func (a *EFileType) GetStorageType() string {
  123. return "EFile"
  124. }
  125. func (a *EFileType) String() string {
  126. return "EFile"
  127. }
  128. // 通用的S3协议的存储服务
  129. type S3Type struct {
  130. serder.Metadata `union:"S3"`
  131. Type string `json:"type"`
  132. Region string `json:"region"`
  133. AK string `json:"accessKeyId"`
  134. SK string `json:"secretAccessKey"`
  135. Endpoint string `json:"endpoint"`
  136. Bucket string `json:"bucket"`
  137. }
  138. func (a *S3Type) GetStorageType() string {
  139. return "S3"
  140. }
  141. func (a *S3Type) String() string {
  142. return "S3"
  143. }