@@ -50,43 +50,37 @@ func GetAbsoluteFSPath(fieldName string, p string) (string, error) {
50
50
return ret , nil
51
51
}
52
52
53
- // ProvisionedRateSpec is an optional part of the StoreSpec.
54
- type ProvisionedRateSpec struct {
55
- // ProvisionedBandwidth is the bandwidth provisioned for this store in bytes/s.
56
- ProvisionedBandwidth int64
57
- }
58
-
59
- func newStoreProvisionedRateSpec (
53
+ func parseStoreProvisionedRate (
60
54
field redact.SafeString , value string ,
61
- ) (ProvisionedRateSpec , error ) {
55
+ ) (storageconfig. ProvisionedRate , error ) {
62
56
split := strings .Split (value , "=" )
63
57
if len (split ) != 2 {
64
- return ProvisionedRateSpec {}, errors .Errorf ("%s field has invalid value %s" , field , value )
58
+ return storageconfig. ProvisionedRate {}, errors .Errorf ("%s field has invalid value %s" , field , value )
65
59
}
66
60
subField := split [0 ]
67
61
subValue := split [1 ]
68
62
if subField != "bandwidth" {
69
- return ProvisionedRateSpec {}, errors .Errorf ("%s field does not have bandwidth sub-field" , field )
63
+ return storageconfig. ProvisionedRate {}, errors .Errorf ("%s field does not have bandwidth sub-field" , field )
70
64
}
71
65
if len (subValue ) == 0 {
72
- return ProvisionedRateSpec {}, errors .Errorf ("%s field has no value specified for bandwidth" , field )
66
+ return storageconfig. ProvisionedRate {}, errors .Errorf ("%s field has no value specified for bandwidth" , field )
73
67
}
74
68
if len (subValue ) <= 2 || subValue [len (subValue )- 2 :] != "/s" {
75
- return ProvisionedRateSpec {},
69
+ return storageconfig. ProvisionedRate {},
76
70
errors .Errorf ("%s field does not have bandwidth sub-field %s ending in /s" ,
77
71
field , subValue )
78
72
}
79
73
bandwidthString := subValue [:len (subValue )- 2 ]
80
74
bandwidth , err := humanizeutil .ParseBytes (bandwidthString )
81
75
if err != nil {
82
- return ProvisionedRateSpec {},
76
+ return storageconfig. ProvisionedRate {},
83
77
errors .Wrapf (err , "could not parse bandwidth in field %s" , field )
84
78
}
85
79
if bandwidth == 0 {
86
- return ProvisionedRateSpec {},
80
+ return storageconfig. ProvisionedRate {},
87
81
errors .Errorf ("%s field is trying to set bandwidth to 0" , field )
88
82
}
89
- return ProvisionedRateSpec {ProvisionedBandwidth : bandwidth }, nil
83
+ return storageconfig. ProvisionedRate {ProvisionedBandwidth : bandwidth }, nil
90
84
}
91
85
92
86
// StoreSpec contains the details that can be specified in the cli pertaining
@@ -110,8 +104,8 @@ type StoreSpec struct {
110
104
PebbleOptions string
111
105
// EncryptionOptions is set if encryption is enabled.
112
106
EncryptionOptions * storageconfig.EncryptionOptions
113
- // ProvisionedRateSpec is optional.
114
- ProvisionedRateSpec ProvisionedRateSpec
107
+ // ProvisionedRate is optional.
108
+ ProvisionedRate storageconfig. ProvisionedRate
115
109
}
116
110
117
111
// String returns a fully parsable version of the store spec.
@@ -154,9 +148,9 @@ func (ss StoreSpec) String() string {
154
148
fmt .Fprint (& buffer , optsStr )
155
149
fmt .Fprint (& buffer , "," )
156
150
}
157
- if ss .ProvisionedRateSpec .ProvisionedBandwidth > 0 {
151
+ if ss .ProvisionedRate .ProvisionedBandwidth > 0 {
158
152
fmt .Fprintf (& buffer , "provisioned-rate=bandwidth=%s/s," ,
159
- humanizeutil .IBytes (ss .ProvisionedRateSpec .ProvisionedBandwidth ))
153
+ humanizeutil .IBytes (ss .ProvisionedRate .ProvisionedBandwidth ))
160
154
}
161
155
// Trim the extra comma from the end if it exists.
162
156
if l := buffer .Len (); l > 0 {
@@ -303,11 +297,11 @@ func NewStoreSpec(value string) (StoreSpec, error) {
303
297
}
304
298
ss .PebbleOptions = buf .String ()
305
299
case "provisioned-rate" :
306
- rateSpec , err := newStoreProvisionedRateSpec ("provisioned-rate" , value )
300
+ rateSpec , err := parseStoreProvisionedRate ("provisioned-rate" , value )
307
301
if err != nil {
308
302
return StoreSpec {}, err
309
303
}
310
- ss .ProvisionedRateSpec = rateSpec
304
+ ss .ProvisionedRate = rateSpec
311
305
312
306
default :
313
307
return StoreSpec {}, fmt .Errorf ("%s is not a valid store field" , field )
0 commit comments