-
Notifications
You must be signed in to change notification settings - Fork 223
/
Copy pathconnection.go
158 lines (123 loc) · 5.19 KB
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
_____ _____ _____ ____ ______ _____ ------
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| --- | | | | |-----| |---- | | |-----| |----- ------
| | | | | | | | | | | | |
| ____| |_____ | ____| | ____| | |_____| _____| |_____ |_____
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
Copyright © 2020-2024 Microsoft Corporation. All rights reserved.
Author : <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
*/
package azstorage
import (
"os"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
"github.com/Azure/azure-storage-fuse/v2/common"
"github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/Azure/azure-storage-fuse/v2/internal"
"github.com/vibhansa-msft/blobfilter"
)
// Example for azblob usage : https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob#pkg-examples
// For methods help refer : https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob#Client
type AzStorageConfig struct {
authConfig azAuthConfig
container string
prefixPath string
blockSize int64
maxConcurrency uint16
// tier to be set on every upload
defaultTier *blob.AccessTier
// Return back readDir on mount for given amount of time
cancelListForSeconds uint16
// Retry policy config
maxRetries int32
maxTimeout int32
backoffTime int32
maxRetryDelay int32
proxyAddress string
ignoreAccessModifiers bool
mountAllContainers bool
updateMD5 bool
validateMD5 bool
virtualDirectory bool
maxResultsForList int32
disableCompression bool
telemetry string
honourACL bool
disableSymlink bool
preserveACL bool
// CPK related config
cpkEnabled bool
cpkEncryptionKey string
cpkEncryptionKeySha256 string
// Blob filters
filter *blobfilter.BlobFilter
}
type AzStorageConnection struct {
Config AzStorageConfig
}
type AzConnection interface {
Configure(cfg AzStorageConfig) error
UpdateConfig(cfg AzStorageConfig) error
SetupPipeline() error
TestPipeline() error
ListContainers() ([]string, error)
// This is just for test, shall not be used otherwise
SetPrefixPath(string) error
CreateFile(name string, mode os.FileMode) error
CreateDirectory(name string) error
CreateLink(source string, target string) error
DeleteFile(name string) error
DeleteDirectory(name string) error
RenameFile(string, string) error
RenameDirectory(string, string) error
GetAttr(name string) (attr *internal.ObjAttr, err error)
// Standard operations to be supported by any account type
List(prefix string, marker *string, count int32) ([]*internal.ObjAttr, *string, error)
ReadToFile(name string, offset int64, count int64, fi *os.File) error
ReadBuffer(name string, offset int64, len int64) ([]byte, error)
ReadInBuffer(name string, offset int64, len int64, data []byte) error
WriteFromFile(name string, metadata map[string]*string, fi *os.File) error
WriteFromBuffer(name string, metadata map[string]*string, data []byte) error
Write(options internal.WriteFileOptions) error
GetFileBlockOffsets(name string) (*common.BlockOffsetList, error)
ChangeMod(string, os.FileMode) error
ChangeOwner(string, int, int) error
TruncateFile(string, int64) error
StageAndCommit(name string, bol *common.BlockOffsetList) error
GetCommittedBlockList(string) (*internal.CommittedBlockList, error)
StageBlock(string, []byte, string) error
CommitBlocks(string, []string) error
UpdateServiceClient(_, _ string) error
}
// NewAzStorageConnection : Based on account type create respective AzConnection Object
func NewAzStorageConnection(cfg AzStorageConfig) AzConnection {
if cfg.authConfig.AccountType == EAccountType.INVALID_ACC() {
log.Err("NewAzStorageConnection : Invalid account type")
} else if cfg.authConfig.AccountType == EAccountType.BLOCK() {
stg := &BlockBlob{}
_ = stg.Configure(cfg)
return stg
} else if cfg.authConfig.AccountType == EAccountType.ADLS() {
stg := &Datalake{}
_ = stg.Configure(cfg)
return stg
}
return nil
}