Skip to content

Commit 85c9939

Browse files
committed
Fixing check issues
Fixing static check issues, go mod and so on
1 parent dd3ba54 commit 85c9939

29 files changed

+866
-852
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ on:
55
- master
66
pull_request:
77
branches:
8-
- master
8+
- '*'
99
jobs:
10-
build:
10+
check:
1111
strategy:
1212
matrix:
1313
go-version:
14-
- 1.20.x
14+
- 1.21.x
1515
- 1.19.x
1616
os:
1717
- ubuntu
@@ -24,7 +24,7 @@ jobs:
2424
with:
2525
go-version: ${{ matrix.go-version }}
2626

27-
- run: make build
27+
- run: make check
2828

2929
test:
3030
strategy:
@@ -37,10 +37,29 @@ jobs:
3737

3838
name: test (${{ matrix.os }}/go-${{ matrix.go-version }})
3939
runs-on: ${{ matrix.os }}-latest
40+
services:
41+
minio:
42+
image: ${{ (matrix.os == 'ubuntu') && 'bitnami/minio:2023.7.18' || ''}}
43+
ports:
44+
- 45677:9000
45+
options: >-
46+
--health-cmd "curl -I http://localhost:9000/minio/health/live -s"
47+
--health-interval 10s
48+
--health-timeout 5s
49+
--health-retries 5
50+
env:
51+
MINIO_ROOT_USER: minioadmin
52+
MINIO_ROOT_PASSWORD: minioadmin
4053
steps:
4154
- uses: actions/checkout@v2
4255
- uses: actions/setup-go@v2
4356
with:
4457
go-version: ${{ matrix.go-version }}
58+
- uses: actions/setup-java@v4
59+
with:
60+
java-version: '17'
61+
distribution: temurin
4562

4663
- run: make run-test
64+
env:
65+
TEST_ENDPOINT_URL: ${{ (matrix.os == 'ubuntu') && 'http://localhost:45677' || '' }}

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ run-test: s3proxy.jar
1616
./test/run-tests.sh
1717

1818
s3proxy.jar:
19-
wget https://github.com/gaul/s3proxy/releases/download/s3proxy-1.8.0/s3proxy -O s3proxy.jar
19+
wget https://github.com/gaul/s3proxy/releases/download/s3proxy-2.2.0/s3proxy -O s3proxy.jar
2020

2121
get-deps: s3proxy.jar
2222
go get -t ./...
@@ -36,11 +36,11 @@ bootstrap: ## Install tooling
3636
@go install $$(go list -e -f '{{join .Imports " "}}' ./internal/tools/tools.go)
3737

3838
.PHONY: check
39-
check: staticcheck unparam semgrep check-fmt check-codegen check-gomod
39+
check: staticcheck check-fmt check-gomod
4040

4141
.PHONY: staticcheck
4242
staticcheck:
43-
@staticcheck -checks 'all,-ST1000' ./...
43+
@staticcheck -checks 'all,-ST1000,-U1000,-ST1020,-ST1001' ./...
4444

4545
.PHONY: unparam
4646
unparam:
@@ -52,15 +52,11 @@ semgrep: ## Run semgrep
5252

5353
.PHONY: check-fmt
5454
check-fmt:
55-
@if [ $$(go fmt -mod=vendor ./...) ]; then\
55+
@if [ $$(go fmt -mod=mod ./...) ]; then\
5656
echo "Go code is not formatted";\
5757
exit 1;\
5858
fi
5959

60-
.PHONY: check-codegen
61-
check-codegen: gogenerate ## Check generated code is up-to-date
62-
@git diff --exit-code --
63-
6460
.PHONY: check-gomod
6561
check-gomod: ## Check go.mod file
6662
@go mod tidy

api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func Mount(
144144
catfs.Stderr = catfsLog.Writer()
145145
err = catfs.Start()
146146
if err != nil {
147-
err = fmt.Errorf("Failed to start catfs: %v", err)
147+
err = fmt.Errorf("failed to start catfs: %v", err)
148148

149149
// sleep a bit otherwise can't unmount right away
150150
time.Sleep(time.Second)

api/common/conf_azure.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (p returnRequestPolicy) Do(ctx context.Context, r pipeline.Request) (pipeli
6262
return resp, nil
6363
}
6464

65-
// hijack the SharedKeyCredentials signing code from azure-storage-blob-go
65+
// WithAuthorization hijack the SharedKeyCredentials signing code from azure-storage-blob-go
6666
// https://github.com/Azure/go-autorest/issues/456
6767
func (config *AZBlobConfig) WithAuthorization() autorest.PrepareDecorator {
6868
return func(p autorest.Preparer) autorest.Preparer {
@@ -97,7 +97,7 @@ type ADLv2Config struct {
9797

9898
type AzureAuthorizerConfig struct {
9999
Log *LogHandle
100-
TenantId string
100+
TenantID string
101101
}
102102

103103
var azbLog = GetLogger("azblob")
@@ -118,10 +118,10 @@ func tokenToAuthorizer(t *cli.Token) (autorest.Authorizer, error) {
118118
return nil, err
119119
}
120120

121-
tenantId := u.Path
121+
tenantID := u.Path
122122
u.Path = ""
123123

124-
oauth, err := adal.NewOAuthConfig(u.String(), tenantId)
124+
oauth, err := adal.NewOAuthConfig(u.String(), tenantID)
125125
if err != nil {
126126
return nil, err
127127
}
@@ -161,12 +161,12 @@ func msiToAuthorizer(mc auth.MSIConfig) (autorest.Authorizer, error) {
161161
}
162162

163163
func (c AzureAuthorizerConfig) Authorizer() (autorest.Authorizer, error) {
164-
if c.TenantId == "" {
164+
if c.TenantID == "" {
165165
defaultSubscription, err := azureDefaultSubscription()
166166
if err != nil {
167167
return nil, err
168168
}
169-
c.TenantId = defaultSubscription.TenantID
169+
c.TenantID = defaultSubscription.TenantID
170170
}
171171

172172
env, err := auth.GetSettingsFromEnvironment()
@@ -194,7 +194,7 @@ func (c AzureAuthorizerConfig) Authorizer() (autorest.Authorizer, error) {
194194
env.Values[auth.ActiveDirectoryEndpoint] = env.Environment.ActiveDirectoryEndpoint
195195
}
196196
adEndpoint := strings.Trim(env.Values[auth.ActiveDirectoryEndpoint], "/") +
197-
"/" + c.TenantId
197+
"/" + c.TenantID
198198
c.Log.Debugf("looking for access token for %v", adEndpoint)
199199

200200
accessTokensPath, err := cli.AccessTokensPath()
@@ -238,7 +238,7 @@ func azureDefaultSubscription() (*cli.Subscription, error) {
238238
}
239239
}
240240

241-
return nil, fmt.Errorf("Unable to find default azure subscription id")
241+
return nil, fmt.Errorf("unable to find default azure subscription id")
242242
}
243243

244244
func azureAccountsClient(account string) (azblob.AccountsClient, error) {
@@ -253,7 +253,7 @@ func azureAccountsClient(account string) (azblob.AccountsClient, error) {
253253

254254
authorizer, err := AzureAuthorizerConfig{
255255
Log: azbLog,
256-
TenantId: defaultSubscription.TenantID,
256+
TenantID: defaultSubscription.TenantID,
257257
}.Authorizer()
258258
if err != nil {
259259
return c, err
@@ -274,13 +274,13 @@ func azureFindAccount(client azblob.AccountsClient, account string) (*azblob.End
274274
// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/...
275275
parts := strings.SplitN(*acc.ID, "/", 6)
276276
if len(parts) != 6 {
277-
return nil, "", fmt.Errorf("Malformed account id: %v", *acc.ID)
277+
return nil, "", fmt.Errorf("malformed account id: %v", *acc.ID)
278278
}
279279
return acc.PrimaryEndpoints, parts[4], nil
280280
}
281281
}
282282

283-
return nil, "", fmt.Errorf("Azure account not found: %v", account)
283+
return nil, "", fmt.Errorf("azure account not found: %v", account)
284284
}
285285

286286
func AzureBlobConfig(endpoint string, location string, storageType string) (config AZBlobConfig, err error) {
@@ -341,7 +341,7 @@ func AzureBlobConfig(endpoint string, location string, storageType string) (conf
341341
}
342342
// at this point I have to have the account
343343
if account == "" {
344-
err = fmt.Errorf("Missing account: configure via AZURE_STORAGE_ACCOUNT "+
344+
err = fmt.Errorf("missing account: configure via AZURE_STORAGE_ACCOUNT "+
345345
"or %v/config", configDir)
346346
return
347347
}
@@ -355,7 +355,7 @@ func AzureBlobConfig(endpoint string, location string, storageType string) (conf
355355
endpoints, resourceGroup, err = azureFindAccount(client, account)
356356
if err != nil {
357357
if key == "" {
358-
err = fmt.Errorf("Missing key: configure via AZURE_STORAGE_KEY "+
358+
err = fmt.Errorf("missing key: configure via AZURE_STORAGE_KEY "+
359359
"or %v/config", configDir)
360360
return
361361
}
@@ -372,7 +372,7 @@ func AzureBlobConfig(endpoint string, location string, storageType string) (conf
372372
var keysRes azblob.AccountListKeysResult
373373
keysRes, err = client.ListKeys(context.TODO(), resourceGroup, account, azblob.Kerb)
374374
if err != nil || len(*keysRes.Keys) == 0 {
375-
err = fmt.Errorf("Missing key: configure via AZURE_STORAGE_KEY "+
375+
err = fmt.Errorf("missing key: configure via AZURE_STORAGE_KEY "+
376376
"or %v/config", configDir)
377377
return
378378
}
@@ -384,8 +384,10 @@ func AzureBlobConfig(endpoint string, location string, storageType string) (conf
384384
break
385385
}
386386
}
387-
// if not just take the first one
388-
key = *(*keysRes.Keys)[0].Value
387+
if key == "" {
388+
// if not just take the first one
389+
key = *(*keysRes.Keys)[0].Value
390+
}
389391
}
390392
} else {
391393
if key == "" {

api/common/conf_s3.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type S3Config struct {
3232
AccessKey string
3333
SecretKey string
3434
RoleArn string
35-
RoleExternalId string
35+
RoleExternalID string
3636
RoleSessionName string
3737
StsEndpoint string
3838

@@ -109,8 +109,8 @@ func (c *S3Config) ToAwsConfig(flags *FlagStorage) (*aws.Config, error) {
109109
if c.RoleArn != "" {
110110
c.Credentials = stscreds.NewCredentials(stsConfigProvider{c}, c.RoleArn,
111111
func(p *stscreds.AssumeRoleProvider) {
112-
if c.RoleExternalId != "" {
113-
p.ExternalID = &c.RoleExternalId
112+
if c.RoleExternalID != "" {
113+
p.ExternalID = &c.RoleExternalID
114114
}
115115
p.RoleSessionName = c.RoleSessionName
116116
})

api/common/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ type FlagStorage struct {
3737
Cache []string
3838
DirMode os.FileMode
3939
FileMode os.FileMode
40-
Uid uint32
41-
Gid uint32
40+
UID uint32
41+
GID uint32
4242

4343
// Common Backend Config
4444
UseContentType bool

api/common/logger.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,18 @@ type RetryHTTPLogger struct {
144144
*LogHandle
145145
}
146146

147-
const DEBUG_TAG = "[DEBUG]"
148-
const ERR_TAG = "[ERR]"
147+
const (
148+
debugTag = "[DEBUG]"
149+
errTag = "[ERR]"
150+
)
149151

150152
func (logger RetryHTTPLogger) Printf(format string, args ...interface{}) {
151153
// unfortunately logrus.ParseLevel uses "error" instead of "err"
152154
// so we have to map this ourselves
153-
if strings.HasPrefix(format, DEBUG_TAG) {
154-
logger.LogHandle.Debugf(format[len(DEBUG_TAG)+1:], args...)
155-
} else if strings.HasPrefix(format, ERR_TAG) {
156-
logger.LogHandle.Errorf(format[len(ERR_TAG)+1:], args...)
155+
if strings.HasPrefix(format, debugTag) {
156+
logger.LogHandle.Debugf(format[len(debugTag)+1:], args...)
157+
} else if strings.HasPrefix(format, errTag) {
158+
logger.LogHandle.Errorf(format[len(errTag)+1:], args...)
157159
} else {
158160
logger.LogHandle.Infof(format, args...)
159161
}

internal/aws_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *AwsTest) SetUpSuite(t *C) {
3939
}
4040

4141
func (s *AwsTest) TestRegionDetection(t *C) {
42-
s.s3.bucket = "goofys-eu-west-1.voyvodov.xyz"
42+
s.s3.bucket = "goofys-eu-west-1.StatCan.xyz"
4343

4444
err, isAws := s.s3.detectBucketLocationByHEAD()
4545
t.Assert(err, IsNil)

0 commit comments

Comments
 (0)