Skip to content

Commit 93c319e

Browse files
committed
refactoed based of golangci-lint
1 parent 858aba7 commit 93c319e

27 files changed

+87
-162
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ build: test fmt
2323
@go build -mod vendor -v -o terraform-provider-databricks
2424

2525
lint:
26-
@echo "==> Linting source code with golint..."
27-
@golint -set_exit_status ./databricks/... ./client/...
26+
@echo "==> Linting source code with golangci-lint..."
27+
@golangci-lint run --skip-dirs-use-default
2828

2929
fmt: lint
3030
@echo "==> Formatting source code with gofmt..."
@@ -83,4 +83,4 @@ internal-docs-sync:
8383
@echo "==> Uploading Website..."
8484
@azcopy login --service-principal --application-id $(AZCOPY_SPA_CLIENT_ID) --tenant-id=$(AZCOPY_SPA_TENANT_ID) && azcopy sync './website/public' '$(AZCOPY_STORAGE_ACCT)' --recursive
8585

86-
.PHONY: build fmt python-setup docs vendor terraform-local build fmt coverage test
86+
.PHONY: build fmt python-setup docs vendor terraform-local build fmt coverage test lint

client/service/client.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ type DBApiClientConfig struct {
6262
InsecureSkipVerify bool
6363
TimeoutSeconds int
6464
client http.Client
65-
cloudProvider CloudServiceProvider
6665
}
6766

6867
// Setup initializes the client
@@ -190,7 +189,7 @@ func PerformQuery(config *DBApiClientConfig, method, path string, apiVersion str
190189
}
191190
requestHeaders := config.getDefaultHeaders()
192191

193-
if headers != nil && len(headers) > 0 {
192+
if len(headers) > 0 {
194193
for k, v := range headers {
195194
requestHeaders[k] = v
196195
}

client/service/commands.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,20 @@ func (a CommandsAPI) waitForCommandFinished(commandID, contextID, clusterID stri
112112
}
113113
}
114114

115-
func (a CommandsAPI) deleteCommand(commandID, contextID, clusterID string) error {
116-
contextDeleteRequest := struct {
117-
CommandID string `json:"commandId,omitempty" url:"commandId,omitempty"`
118-
ContextID string `json:"contextId,omitempty" url:"contextId,omitempty"`
119-
ClusterID string `json:"clusterId,omitempty" url:"clusterId,omitempty"`
120-
}{
121-
CommandID: commandID,
122-
ContextID: contextID,
123-
ClusterID: clusterID,
124-
}
125-
_, err := a.Client.performQuery(http.MethodPost, "/commands/cancel", "1.2", nil, contextDeleteRequest, nil)
126-
return err
127-
}
115+
// Commented till this will be used
116+
//func (a CommandsAPI) deleteCommand(commandID, contextID, clusterID string) error {
117+
// contextDeleteRequest := struct {
118+
// CommandID string `json:"commandId,omitempty" url:"commandId,omitempty"`
119+
// ContextID string `json:"contextId,omitempty" url:"contextId,omitempty"`
120+
// ClusterID string `json:"clusterId,omitempty" url:"clusterId,omitempty"`
121+
// }{
122+
// CommandID: commandID,
123+
// ContextID: contextID,
124+
// ClusterID: clusterID,
125+
// }
126+
// _, err := a.Client.performQuery(http.MethodPost, "/commands/cancel", "1.2", nil, contextDeleteRequest, nil)
127+
// return err
128+
//}
128129

129130
func (a CommandsAPI) deleteContext(contextID, clusterID string) error {
130131
contextDeleteRequest := struct {

client/service/dbfs.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (a DBFSAPI) Read(path string) (string, error) {
4343
fetchLoop := true
4444
offSet := int64(0)
4545
length := int64(1e6)
46-
for fetchLoop == true {
46+
for fetchLoop {
4747
bytesRead, bytes, err := a.read(path, offSet, length)
4848
if err != nil {
4949
return "", err
@@ -71,7 +71,7 @@ func (a DBFSAPI) Copy(src string, tgt string, client *DBApiClient, overwrite boo
7171
fetchLoop := true
7272
offSet := int64(0)
7373
length := int64(1e6)
74-
for fetchLoop == true {
74+
for fetchLoop {
7575
var api DBFSAPI
7676
if client == nil {
7777
api = a
@@ -176,7 +176,7 @@ func (a DBFSAPI) Status(path string) (model.FileInfo, error) {
176176

177177
// List returns a list of files in DBFS and the recursive flag lets you recursively list files
178178
func (a DBFSAPI) List(path string, recursive bool) ([]model.FileInfo, error) {
179-
if recursive == true {
179+
if recursive {
180180
var paths []model.FileInfo
181181
err := a.recursiveAddPaths(path, &paths)
182182
if err != nil {
@@ -193,9 +193,9 @@ func (a DBFSAPI) recursiveAddPaths(path string, pathList *[]model.FileInfo) erro
193193
return err
194194
}
195195
for _, v := range fileInfoList {
196-
if v.IsDir == false {
196+
if !v.IsDir {
197197
*pathList = append(*pathList, v)
198-
} else if v.IsDir == true {
198+
} else if v.IsDir {
199199
err := a.recursiveAddPaths(v.Path, pathList)
200200
if err != nil {
201201
return err
@@ -287,7 +287,7 @@ func split(buf []byte, lim int) [][]byte {
287287
chunks = append(chunks, chunk)
288288
}
289289
if len(buf) > 0 {
290-
chunks = append(chunks, buf[:len(buf)])
290+
chunks = append(chunks, buf[:])
291291
}
292292
return chunks
293293
}

client/service/groups.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ func (a GroupsAPI) getInheritedAndNonInheritedRoles(group model.Group, groups []
159159
inheritedRolesKeys := []string{}
160160
inheritedRolesMap := map[string]model.RoleListItem{}
161161
for _, group := range groups {
162-
for _, role := range group.Roles {
163-
inheritedRoles = append(inheritedRoles, role)
164-
}
162+
inheritedRoles = append(inheritedRoles, group.Roles...)
165163
}
166164
for _, role := range inheritedRoles {
167165
inheritedRolesKeys = append(inheritedRolesKeys, role.Value)

client/service/groups_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ func TestScimGroupAPI_Create(t *testing.T) {
3333
},
3434
args: args{
3535
Schemas: []model.URN{model.GroupSchema},
36-
Entitlements: []model.ValueListItem{{"test-entitlement"}},
36+
Entitlements: []model.ValueListItem{{Value:"test-entitlement"}},
3737
DisplayName: "test group",
38-
Roles: []model.ValueListItem{{"test-role"}},
39-
Members: []model.ValueListItem{{"test-member"}},
38+
Roles: []model.ValueListItem{{Value:"test-role"}},
39+
Members: []model.ValueListItem{{Value:"test-member"}},
4040
},
4141
wantErr: false,
4242
},
@@ -47,10 +47,10 @@ func TestScimGroupAPI_Create(t *testing.T) {
4747
responseStatus: http.StatusBadRequest,
4848
args: args{
4949
Schemas: []model.URN{model.GroupSchema},
50-
Entitlements: []model.ValueListItem{{"test-entitlement"}},
50+
Entitlements: []model.ValueListItem{{Value:"test-entitlement"}},
5151
DisplayName: "test group",
52-
Roles: []model.ValueListItem{{"test-role"}},
53-
Members: []model.ValueListItem{{"test-member"}},
52+
Roles: []model.ValueListItem{{Value:"test-role"}},
53+
Members: []model.ValueListItem{{Value:"test-member"}},
5454
},
5555
wantErr: true,
5656
},

client/service/notebooks.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (a NotebooksAPI) Mkdirs(path string) error {
7979
// List will list all objects in a path on the workspace and with the recursive flag it will recursively list
8080
// all the objects
8181
func (a NotebooksAPI) List(path string, recursive bool) ([]model.NotebookInfo, error) {
82-
if recursive == true {
82+
if recursive {
8383
var paths []model.NotebookInfo
8484
err := a.recursiveAddPaths(path, &paths)
8585
if err != nil {

client/service/tokens_integration_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestCreateToken(t *testing.T) {
2828
assert.NoError(t, err, err)
2929

3030
tokenList, err := client.Tokens().List()
31+
assert.NoError(t, err, err)
3132
assert.True(t, len(tokenList) > 0, "Token list is empty")
3233

3334
}

client/service/users.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ func (a UsersAPI) getInheritedAndNonInheritedRoles(user model.User, groups []mod
188188
inheritedRolesKeys := []string{}
189189
inheritedRolesMap := map[string]model.RoleListItem{}
190190
for _, group := range groups {
191-
for _, role := range group.Roles {
192-
inheritedRoles = append(inheritedRoles, role)
193-
}
191+
inheritedRoles = append(inheritedRoles, group.Roles...)
194192
}
195193
for _, role := range inheritedRoles {
196194
inheritedRolesKeys = append(inheritedRolesKeys, role.Value)

client/service/users_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func TestScimUserAPI_Create(t *testing.T) {
3737
args: args{
3838
Schemas: []model.URN{model.UserSchema},
3939
UserName: "[email protected]",
40-
Entitlements: []model.EntitlementsListItem{{"test-entitlement"}},
40+
Entitlements: []model.EntitlementsListItem{{Value:"test-entitlement"}},
4141
DisplayName: "test user",
42-
Roles: []model.RoleListItem{{"test-role"}},
42+
Roles: []model.RoleListItem{{Value:"test-role"}},
4343
},
4444
wantErr: false,
4545
},
@@ -51,9 +51,9 @@ func TestScimUserAPI_Create(t *testing.T) {
5151
args: args{
5252
Schemas: []model.URN{model.UserSchema},
5353
UserName: "[email protected]",
54-
Entitlements: []model.EntitlementsListItem{{"test-entitlement"}},
54+
Entitlements: []model.EntitlementsListItem{{Value:"test-entitlement"}},
5555
DisplayName: "test user",
56-
Roles: []model.RoleListItem{{"test-role"}},
56+
Roles: []model.RoleListItem{{Value:"test-role"}},
5757
},
5858
wantErr: true,
5959
},
@@ -99,9 +99,9 @@ func TestScimUserAPI_Update(t *testing.T) {
9999
&args{
100100
Schemas: []model.URN{model.UserSchema},
101101
UserName: "[email protected]",
102-
Entitlements: []model.EntitlementsListItem{{"test-entitlement"}},
102+
Entitlements: []model.EntitlementsListItem{{Value:"test-entitlement"}},
103103
DisplayName: "test user",
104-
Roles: []model.RoleListItem{{"test-role"}},
104+
Roles: []model.RoleListItem{{Value:"test-role"}},
105105
},
106106
},
107107
wantErr: false,
@@ -118,9 +118,9 @@ func TestScimUserAPI_Update(t *testing.T) {
118118
&args{
119119
Schemas: []model.URN{model.UserSchema},
120120
UserName: "[email protected]",
121-
Entitlements: []model.EntitlementsListItem{{"test-entitlement"}},
121+
Entitlements: []model.EntitlementsListItem{{Value:"test-entitlement"}},
122122
DisplayName: "test user",
123-
Roles: []model.RoleListItem{{"test-role"}},
123+
Roles: []model.RoleListItem{{Value:"test-role"}},
124124
},
125125
},
126126
wantErr: true,
@@ -184,7 +184,7 @@ func TestScimUserAPI_Delete(t *testing.T) {
184184
func TestScimUserAPI_SetUserAsAdmin(t *testing.T) {
185185
type args struct {
186186
UserID string `json:"user_id,omitempty"`
187-
AdminGroupID string `json:"user_id,omitempty"`
187+
AdminGroupID string `json:"admin_group_id,omitempty"`
188188
}
189189
tests := []struct {
190190
name string
@@ -242,7 +242,7 @@ func TestScimUserAPI_SetUserAsAdmin(t *testing.T) {
242242
func TestScimUserAPI_VerifyUserAsAdmin(t *testing.T) {
243243
type args struct {
244244
UserID string `json:"user_id,omitempty"`
245-
AdminGroupID string `json:"user_id,omitempty"`
245+
AdminGroupID string `json:"admin_group_id,omitempty"`
246246
}
247247
tests := []struct {
248248
name string
@@ -354,7 +354,7 @@ func TestScimUserAPI_VerifyUserAsAdmin(t *testing.T) {
354354
func TestScimUserAPI_RemoveUserAsAdmin(t *testing.T) {
355355
type args struct {
356356
UserID string `json:"user_id,omitempty"`
357-
AdminGroupID string `json:"user_id,omitempty"`
357+
AdminGroupID string `json:"admin_group_id,omitempty"`
358358
}
359359
tests := []struct {
360360
name string

databricks/data_source_databricks_dbfs_file.go

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func dataSourceDBFSFileRead(d *schema.ResourceData, m interface{}) error {
5959
return err
6060
}
6161
err = d.Set("content", content)
62+
if err != nil {
63+
return err
64+
}
6265
} else if fileInfo.FileSize > 4e6 {
6366
err = d.Set("content", "File Size is too Large!")
6467
}
@@ -68,6 +71,9 @@ func dataSourceDBFSFileRead(d *schema.ResourceData, m interface{}) error {
6871
return err
6972
}
7073
err = d.Set("content", content)
74+
if err != nil {
75+
return err
76+
}
7177
}
7278

7379
return err

databricks/provider.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ func Provider(version string) terraform.ResourceProvider {
9191
}
9292

9393
provider.ConfigureFunc = func(d *schema.ResourceData) (interface{}, error) {
94-
terraformVersion := provider.TerraformVersion
95-
if terraformVersion == "" {
94+
//terraformVersion := provider.TerraformVersion
95+
//if terraformVersion == "" {
9696
// Terraform 0.12 introduced this field to the protocol
9797
// We can therefore assume that if it's missing it's 0.10 or 0.11
98-
terraformVersion = "0.11+compatible"
99-
}
98+
//terraformVersion = "0.11+compatible"
99+
//}
100100
return providerConfigure(d, version)
101101
}
102102

databricks/resource_databricks_azure_adls_gen1_mount.go

+3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error {
162162
return err
163163
}
164164
storageResourceName, dir, err := ProcessAzureAdlsGen1Uri(url)
165+
if err != nil {
166+
return err
167+
}
165168
err = d.Set("storage_resource_name", storageResourceName)
166169
if err != nil {
167170
return err

databricks/resource_databricks_azure_adls_gen2_mount.go

+3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ func resourceAzureAdlsGen2Read(d *schema.ResourceData, m interface{}) error {
155155
return err
156156
}
157157
container, storageAcc, dir, err := ProcessAzureWasbAbfssUris(url)
158+
if err != nil {
159+
return err
160+
}
158161
err = d.Set("container_name", container)
159162
if err != nil {
160163
return err

databricks/resource_databricks_azure_blob_mount.go

+6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func resourceAzureBlobMountCreate(d *schema.ResourceData, m interface{}) error {
8989
tokenSecretScope, tokenSecretKey)
9090

9191
err = blobMount.Create(client, clusterID)
92+
if err != nil {
93+
return err
94+
}
9295

9396
d.SetId(mountName)
9497

@@ -143,6 +146,9 @@ func resourceAzureBlobMountRead(d *schema.ResourceData, m interface{}) error {
143146
return err
144147
}
145148
container, storageAcc, dir, err := ProcessAzureWasbAbfssUris(url)
149+
if err != nil {
150+
return err
151+
}
146152
err = d.Set("container_name", container)
147153
if err != nil {
148154
return err

0 commit comments

Comments
 (0)