cdn.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 cloudprovider
  15. import (
  16. "reflect"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/gotypes"
  19. )
  20. // +onecloud:model-api-gen
  21. type SCdnDomain struct {
  22. // cdn加速域名
  23. Domain string
  24. // 状态 rejected(域名未审核)|processing(部署中)|online|offline
  25. Status string
  26. // 区域 mainland|overseas|global
  27. Area string
  28. // cdn Cname
  29. Cname string
  30. // 源站
  31. Origin string
  32. // 源站类型 domain|ip|bucket
  33. OriginType string
  34. }
  35. // +onecloud:model-api-gen
  36. type SCdnOrigin struct {
  37. // 源站类型
  38. // domain: 域名类型, cos:对象存储源站, ip:IP 列表作为源站
  39. // enmu: domain, cos, ip
  40. // required: true
  41. Type string
  42. // 源站地址
  43. Origin string
  44. // 回主源站时 Host 头部
  45. ServerName string
  46. // 回源协议
  47. // enmu: http, follow, https
  48. Protocol string
  49. Path string
  50. Port int
  51. Enabled string
  52. Priority int
  53. }
  54. type CdnCreateOptions struct {
  55. Domain string
  56. ServiceType string
  57. Area string
  58. Origins SCdnOrigins
  59. }
  60. // +onecloud:model-api-gen
  61. type SCdnOrigins []SCdnOrigin
  62. func (origins SCdnOrigins) IsZero() bool {
  63. return len(origins) == 0
  64. }
  65. func (origins SCdnOrigins) String() string {
  66. return jsonutils.Marshal(origins).String()
  67. }
  68. // 是否忽略参数
  69. // +onecloud:model-api-gen
  70. type SCDNCacheKeys struct {
  71. // 开启关闭忽略参数
  72. Enabled *bool
  73. // 是否忽略大小
  74. IgnoreCase *bool
  75. // 分路径缓存键配置
  76. KeyRules []CacheKeyRule
  77. }
  78. type CacheKeyRule struct {
  79. RulePaths []string
  80. RuleType string
  81. FullUrlCache bool
  82. IgnoreCase bool
  83. QueryString CacheKeyRuleQueryString
  84. RuleTag string
  85. }
  86. type CacheKeyRuleQueryString struct {
  87. Enabled bool
  88. Action string
  89. Value string
  90. }
  91. func (keys SCDNCacheKeys) IsZero() bool {
  92. return jsonutils.Marshal(keys) == jsonutils.Marshal(&SCDNCacheKeys{})
  93. }
  94. func (keys SCDNCacheKeys) String() string {
  95. return jsonutils.Marshal(keys).String()
  96. }
  97. // 是否分片回源
  98. // +onecloud:model-api-gen
  99. type SCDNRangeOriginPull struct {
  100. Enabled *bool
  101. RangeOriginPullRules []SRangeOriginPullRule
  102. }
  103. type SRangeOriginPullRule struct {
  104. Enabled bool
  105. RuleType string
  106. RulePaths []string
  107. }
  108. func (pull SCDNRangeOriginPull) IsZero() bool {
  109. return jsonutils.Marshal(pull) == jsonutils.Marshal(&SCDNRangeOriginPull{})
  110. }
  111. func (pull SCDNRangeOriginPull) String() string {
  112. return jsonutils.Marshal(pull).String()
  113. }
  114. type CacheRule struct {
  115. // 规则类型:
  116. // all:所有文件生效
  117. // file:指定文件后缀生效
  118. // directory:指定路径生效
  119. // path:指定绝对路径生效
  120. // index:首页
  121. CacheType string
  122. // CacheType 对应类型下的匹配内容
  123. CacheContents []string
  124. // 过期时间: 秒
  125. CacheTime int
  126. }
  127. // +onecloud:model-api-gen
  128. type SCDNCache struct {
  129. RuleCache []SCacheRuleCache
  130. }
  131. type SCacheRuleCache struct {
  132. RulePaths []string
  133. RuleType string
  134. Priority int
  135. CacheConfig *RuleCacheConfig
  136. }
  137. type RuleCacheConfig struct {
  138. Cache *struct {
  139. Enabled bool
  140. CacheTime int
  141. CompareMaxAge bool
  142. IgnoreCacheControl bool
  143. IgnoreSetCookie bool
  144. }
  145. NoCache *struct {
  146. Enabled bool
  147. Revalidate bool
  148. }
  149. FollowOrigin *struct {
  150. Enabled bool
  151. HeuristicCache struct {
  152. Enabled bool
  153. CacheConfig struct {
  154. HeuristicCacheTimeSwitch bool
  155. HeuristicCacheTime int
  156. }
  157. }
  158. }
  159. }
  160. func (cache SCDNCache) IsZero() bool {
  161. return jsonutils.Marshal(cache) == jsonutils.Marshal(&SCDNCache{})
  162. }
  163. func (cache SCDNCache) String() string {
  164. return jsonutils.Marshal(cache).String()
  165. }
  166. // +onecloud:model-api-gen
  167. type SCDNHttps struct {
  168. // https 配置开关
  169. Enabled *bool
  170. // http2 配置开关
  171. Http2 *bool
  172. }
  173. func (https SCDNHttps) IsZero() bool {
  174. return jsonutils.Marshal(https) == jsonutils.Marshal(&SCDNHttps{})
  175. }
  176. func (https SCDNHttps) String() string {
  177. return jsonutils.Marshal(https).String()
  178. }
  179. // +onecloud:model-api-gen
  180. type SCDNForceRedirect struct {
  181. // 访问强制跳转配置开关
  182. Enabled *bool
  183. // 访问强制跳转类型
  184. // enmu: http, https
  185. RedirectType string
  186. }
  187. func (redirect SCDNForceRedirect) IsZero() bool {
  188. return jsonutils.Marshal(redirect) == jsonutils.Marshal(&SCDNForceRedirect{})
  189. }
  190. func (redirect SCDNForceRedirect) String() string {
  191. return jsonutils.Marshal(redirect).String()
  192. }
  193. type RefererRule struct {
  194. // 规则类型:
  195. // all:所有文件生效
  196. // file:指定文件后缀生效
  197. // directory:指定路径生效
  198. // path:指定绝对路径生效
  199. RuleType string
  200. RulePaths []string
  201. RefererType string
  202. Referers []string
  203. AllowEmpty *bool
  204. }
  205. // +onecloud:model-api-gen
  206. type SCDNReferer struct {
  207. // 是否开启防盗链
  208. Enabled *bool
  209. RefererRules []RefererRule
  210. }
  211. func (referer SCDNReferer) IsZero() bool {
  212. return jsonutils.Marshal(referer) == jsonutils.Marshal(&SCDNReferer{})
  213. }
  214. func (referer SCDNReferer) String() string {
  215. return jsonutils.Marshal(referer).String()
  216. }
  217. type SMaxAgeRule struct {
  218. MaxAgeType string
  219. MaxAgeContents []string
  220. MaxAgeTime int
  221. FollowOrigin bool
  222. }
  223. // 浏览器缓存配置
  224. // +onecloud:model-api-gen
  225. type SCDNMaxAge struct {
  226. Enabled *bool
  227. MaxAgeRules []SMaxAgeRule
  228. }
  229. func (maxAge SCDNMaxAge) IsZero() bool {
  230. return jsonutils.Marshal(maxAge) == jsonutils.Marshal(&SCDNMaxAge{})
  231. }
  232. func (maxAge SCDNMaxAge) String() string {
  233. return jsonutils.Marshal(maxAge).String()
  234. }
  235. type CacheClearOptions struct {
  236. PurgeEverything *bool
  237. Tags []string
  238. Hosts []string
  239. Prefixes []string
  240. Files []interface{}
  241. }
  242. type CacheConfig struct {
  243. DNSSECEnabled *bool
  244. HTTPSEnabled *bool
  245. CacheLevel string
  246. BrowserCacheTTL *int
  247. HTTPSRewrites *bool
  248. SSLSetting string
  249. }
  250. type CustomHostname struct {
  251. Id string
  252. Hostname string
  253. CustomOriginServer string
  254. OwnershipVerification struct {
  255. Name string
  256. Type string
  257. Value string
  258. }
  259. OwnershipVerificationHttp struct {
  260. HttpBody string
  261. HttpUrl string
  262. }
  263. SSL struct {
  264. BundleMethod string
  265. CertificateAuthority string
  266. DcvDelegationRecords []struct {
  267. Cname string
  268. CnameTarget string
  269. }
  270. Id string
  271. Method string
  272. Settings struct {
  273. MinTLSVersion string `json:"min_tls_version"`
  274. }
  275. Status string
  276. Type string
  277. ValidationRecords []struct {
  278. Status string
  279. TxtName string
  280. TxtValue string
  281. }
  282. Wildcard bool
  283. }
  284. Status string
  285. }
  286. type CustomHostnameCreateOptions struct {
  287. CustomOriginServer string
  288. Hostname string
  289. SSL struct {
  290. CertificateAuthority string
  291. Method string
  292. BundleMethod string
  293. CustomCertificate string
  294. CustomKey string
  295. Settings struct {
  296. MinTLSVersion string `json:"min_tls_version"`
  297. }
  298. Type string
  299. Wildcard bool
  300. }
  301. }
  302. func init() {
  303. gotypes.RegisterSerializable(reflect.TypeOf(&SCdnOrigins{}), func() gotypes.ISerializable {
  304. return &SCdnOrigins{}
  305. })
  306. gotypes.RegisterSerializable(reflect.TypeOf(&SCDNCacheKeys{}), func() gotypes.ISerializable {
  307. return &SCDNCacheKeys{}
  308. })
  309. gotypes.RegisterSerializable(reflect.TypeOf(&SCDNRangeOriginPull{}), func() gotypes.ISerializable {
  310. return &SCDNRangeOriginPull{}
  311. })
  312. gotypes.RegisterSerializable(reflect.TypeOf(&SCDNCache{}), func() gotypes.ISerializable {
  313. return &SCDNCache{}
  314. })
  315. gotypes.RegisterSerializable(reflect.TypeOf(&SCDNHttps{}), func() gotypes.ISerializable {
  316. return &SCDNHttps{}
  317. })
  318. gotypes.RegisterSerializable(reflect.TypeOf(&SCDNForceRedirect{}), func() gotypes.ISerializable {
  319. return &SCDNForceRedirect{}
  320. })
  321. gotypes.RegisterSerializable(reflect.TypeOf(&SCDNReferer{}), func() gotypes.ISerializable {
  322. return &SCDNReferer{}
  323. })
  324. gotypes.RegisterSerializable(reflect.TypeOf(&SCDNMaxAge{}), func() gotypes.ISerializable {
  325. return &SCDNMaxAge{}
  326. })
  327. }