consts.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 consts
  15. import (
  16. "time"
  17. "yunion.io/x/log"
  18. )
  19. var (
  20. COMMON_SERVICE = "common"
  21. globalRegion = ""
  22. globalZone = ""
  23. globalServiceType = ""
  24. globalServiceName = ""
  25. tenantCacheExpireSeconds = 900
  26. roleCacheExpireHours = 24
  27. nonDefaultDomainProjects = false
  28. defaultPagingLimit int64 = 2048
  29. maxPagingLimit int64 = 2048
  30. domainizedNamespace = true
  31. historicalUniqueName = false
  32. enableQuotaCheck = false
  33. enableDataResp = false
  34. )
  35. func SetRegion(region string) {
  36. globalRegion = region
  37. }
  38. func GetRegion() string {
  39. return globalRegion
  40. }
  41. func SetZone(zone string) {
  42. globalZone = zone
  43. }
  44. func GetZone() string {
  45. return globalZone
  46. }
  47. func SetDataResp(enable bool) {
  48. enableDataResp = enable
  49. }
  50. func GetDataResp() bool {
  51. return enableDataResp
  52. }
  53. func SetServiceType(srvType string) {
  54. globalServiceType = srvType
  55. }
  56. func GetServiceType() string {
  57. return globalServiceType
  58. }
  59. func SetServiceName(srvName string) {
  60. globalServiceName = srvName
  61. }
  62. func GetServiceName() string {
  63. return globalServiceName
  64. }
  65. func SetTenantCacheExpireSeconds(sec int) {
  66. tenantCacheExpireSeconds = sec
  67. }
  68. func GetTenantCacheExpireSeconds() time.Duration {
  69. return time.Duration(tenantCacheExpireSeconds) * time.Second
  70. }
  71. func SetRoleCacheExpireHours(h int) {
  72. roleCacheExpireHours = h
  73. }
  74. func GetRoleCacheExpireHours() time.Duration {
  75. return time.Duration(roleCacheExpireHours) * time.Hour
  76. }
  77. func SetNonDefaultDomainProjects(val bool) {
  78. log.Infof("set non_default_domain_projects to %v", val)
  79. nonDefaultDomainProjects = val
  80. }
  81. func GetNonDefaultDomainProjects() bool {
  82. return nonDefaultDomainProjects
  83. }
  84. func GetDefaultPagingLimit() int64 {
  85. return defaultPagingLimit
  86. }
  87. func GetMaxPagingLimit() int64 {
  88. return maxPagingLimit
  89. }
  90. func SetDomainizedNamespace(domainNS bool) {
  91. domainizedNamespace = domainNS
  92. }
  93. func IsDomainizedNamespace() bool {
  94. return nonDefaultDomainProjects && domainizedNamespace
  95. }
  96. func EnableHistoricalUniqueName() {
  97. historicalUniqueName = true
  98. }
  99. func DisableHistoricalUniqueName() {
  100. historicalUniqueName = false
  101. }
  102. func IsHistoricalUniqueName() bool {
  103. return historicalUniqueName
  104. }
  105. func SetEnableQuotaCheck(val bool) {
  106. enableQuotaCheck = val
  107. }
  108. func EnableQuotaCheck() bool {
  109. return enableQuotaCheck
  110. }