options.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package storage
  2. // Option for setting params used by chunk manager client.
  3. type config struct {
  4. address string
  5. bucketName string
  6. accessKeyID string
  7. secretAccessKeyID string
  8. useSSL bool
  9. sslCACert string
  10. createBucket bool
  11. rootPath string
  12. useIAM bool
  13. cloudProvider string
  14. iamEndpoint string
  15. useVirtualHost bool
  16. region string
  17. requestTimeoutMs int64
  18. gcpCredentialJSON string
  19. gcpNativeWithoutAuth bool // used for Unit Testing
  20. }
  21. func newDefaultConfig() *config {
  22. return &config{}
  23. }
  24. // Option is used to config the retry function.
  25. type Option func(*config)
  26. func Address(addr string) Option {
  27. return func(c *config) {
  28. c.address = addr
  29. }
  30. }
  31. func BucketName(bucketName string) Option {
  32. return func(c *config) {
  33. c.bucketName = bucketName
  34. }
  35. }
  36. func AccessKeyID(accessKeyID string) Option {
  37. return func(c *config) {
  38. c.accessKeyID = accessKeyID
  39. }
  40. }
  41. func SecretAccessKeyID(secretAccessKeyID string) Option {
  42. return func(c *config) {
  43. c.secretAccessKeyID = secretAccessKeyID
  44. }
  45. }
  46. func UseSSL(useSSL bool) Option {
  47. return func(c *config) {
  48. c.useSSL = useSSL
  49. }
  50. }
  51. func SslCACert(sslCACert string) Option {
  52. return func(c *config) {
  53. c.sslCACert = sslCACert
  54. }
  55. }
  56. func CreateBucket(createBucket bool) Option {
  57. return func(c *config) {
  58. c.createBucket = createBucket
  59. }
  60. }
  61. func RootPath(rootPath string) Option {
  62. return func(c *config) {
  63. c.rootPath = rootPath
  64. }
  65. }
  66. func UseIAM(useIAM bool) Option {
  67. return func(c *config) {
  68. c.useIAM = useIAM
  69. }
  70. }
  71. func CloudProvider(cloudProvider string) Option {
  72. return func(c *config) {
  73. c.cloudProvider = cloudProvider
  74. }
  75. }
  76. func IAMEndpoint(iamEndpoint string) Option {
  77. return func(c *config) {
  78. c.iamEndpoint = iamEndpoint
  79. }
  80. }
  81. func UseVirtualHost(useVirtualHost bool) Option {
  82. return func(c *config) {
  83. c.useVirtualHost = useVirtualHost
  84. }
  85. }
  86. func Region(region string) Option {
  87. return func(c *config) {
  88. c.region = region
  89. }
  90. }
  91. func RequestTimeout(requestTimeoutMs int64) Option {
  92. return func(c *config) {
  93. c.requestTimeoutMs = requestTimeoutMs
  94. }
  95. }
  96. func GcpCredentialJSON(gcpCredentialJSON string) Option {
  97. return func(c *config) {
  98. c.gcpCredentialJSON = gcpCredentialJSON
  99. }
  100. }