TODO: Unit tests
( prefix string, settings map[string]string, rootWraps ...storage.WrapRootFolder, )
| 43 | |
| 44 | // TODO: Unit tests |
| 45 | func ConfigureStorage( |
| 46 | prefix string, |
| 47 | settings map[string]string, |
| 48 | rootWraps ...storage.WrapRootFolder, |
| 49 | ) (storage.HashableStorage, error) { |
| 50 | accountName, ok := settings[AccountSetting] |
| 51 | if !ok { |
| 52 | return nil, fmt.Errorf("%q is not specified", AccountSetting) |
| 53 | } |
| 54 | |
| 55 | authType, sasToken, accessKey := configureAuthType(settings) |
| 56 | |
| 57 | tryTimeoutInt, err := setting.IntOptional(settings, TryTimeoutSetting, defaultTryTimeout) |
| 58 | if err != nil { |
| 59 | return nil, err |
| 60 | } |
| 61 | tryTimeout := time.Minute * time.Duration(tryTimeoutInt) |
| 62 | |
| 63 | containerName, path, err := storage.GetPathFromPrefix(prefix) |
| 64 | if err != nil { |
| 65 | return nil, fmt.Errorf("extract container and path from prefix %q: %w", prefix, err) |
| 66 | } |
| 67 | path = storage.AddDelimiterToPath(path) |
| 68 | |
| 69 | var endpointSuffix string |
| 70 | if endpointSuffix, ok = settings[EndpointSuffix]; !ok { |
| 71 | var environmentName string |
| 72 | if environmentName, ok = settings[EnvironmentName]; !ok { |
| 73 | environmentName = defaultEnvName |
| 74 | } |
| 75 | endpointSuffix = getStorageEndpointSuffix(environmentName) |
| 76 | } |
| 77 | |
| 78 | bufferSize, err := setting.Int64Optional(settings, BufferSizeSetting, defaultBufferSize) |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | if bufferSize < minBufferSize { |
| 83 | bufferSize = minBufferSize |
| 84 | } |
| 85 | |
| 86 | buffers, err := setting.IntOptional(settings, BuffersSetting, defaultBuffers) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | if buffers < minBuffers { |
| 91 | buffers = minBuffers |
| 92 | } |
| 93 | |
| 94 | config := &Config{ |
| 95 | Secrets: &Secrets{ |
| 96 | AccessKey: accessKey, |
| 97 | SASToken: sasToken, |
| 98 | }, |
| 99 | RootPath: path, |
| 100 | Container: containerName, |
| 101 | AuthType: authType, |
| 102 | AccountName: accountName, |