Skip to content

Commit

Permalink
Merge branch 'master' into github-workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
stikkireddy committed Apr 23, 2020
2 parents 1a19d61 + 880e800 commit 0020d9d
Show file tree
Hide file tree
Showing 27 changed files with 89 additions and 164 deletions.
10 changes: 5 additions & 5 deletions Makefile
@@ -1,6 +1,6 @@
default: build

test: lint
test:
@echo "==> Running tests..."
@gotestsum --raw-command go test -v -json -short -coverprofile=coverage.out ./...

Expand All @@ -18,13 +18,13 @@ coverage-int: int

int-build: int build

build: test fmt
build: lint test fmt
@echo "==> Building source code with go build..."
@go build -mod vendor -v -o terraform-provider-databricks

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

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

.PHONY: build fmt python-setup docs vendor terraform-local build fmt coverage test
.PHONY: build fmt python-setup docs vendor terraform-local build fmt coverage test lint
3 changes: 1 addition & 2 deletions client/service/client.go
Expand Up @@ -62,7 +62,6 @@ type DBApiClientConfig struct {
InsecureSkipVerify bool
TimeoutSeconds int
client http.Client
cloudProvider CloudServiceProvider
}

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

if headers != nil && len(headers) > 0 {
if len(headers) > 0 {
for k, v := range headers {
requestHeaders[k] = v
}
Expand Down
27 changes: 14 additions & 13 deletions client/service/commands.go
Expand Up @@ -112,19 +112,20 @@ func (a CommandsAPI) waitForCommandFinished(commandID, contextID, clusterID stri
}
}

func (a CommandsAPI) deleteCommand(commandID, contextID, clusterID string) error {
contextDeleteRequest := struct {
CommandID string `json:"commandId,omitempty" url:"commandId,omitempty"`
ContextID string `json:"contextId,omitempty" url:"contextId,omitempty"`
ClusterID string `json:"clusterId,omitempty" url:"clusterId,omitempty"`
}{
CommandID: commandID,
ContextID: contextID,
ClusterID: clusterID,
}
_, err := a.Client.performQuery(http.MethodPost, "/commands/cancel", "1.2", nil, contextDeleteRequest, nil)
return err
}
// Commented till this will be used
//func (a CommandsAPI) deleteCommand(commandID, contextID, clusterID string) error {
// contextDeleteRequest := struct {
// CommandID string `json:"commandId,omitempty" url:"commandId,omitempty"`
// ContextID string `json:"contextId,omitempty" url:"contextId,omitempty"`
// ClusterID string `json:"clusterId,omitempty" url:"clusterId,omitempty"`
// }{
// CommandID: commandID,
// ContextID: contextID,
// ClusterID: clusterID,
// }
// _, err := a.Client.performQuery(http.MethodPost, "/commands/cancel", "1.2", nil, contextDeleteRequest, nil)
// return err
//}

func (a CommandsAPI) deleteContext(contextID, clusterID string) error {
contextDeleteRequest := struct {
Expand Down
12 changes: 6 additions & 6 deletions client/service/dbfs.go
Expand Up @@ -43,7 +43,7 @@ func (a DBFSAPI) Read(path string) (string, error) {
fetchLoop := true
offSet := int64(0)
length := int64(1e6)
for fetchLoop == true {
for fetchLoop {
bytesRead, bytes, err := a.read(path, offSet, length)
if err != nil {
return "", err
Expand Down Expand Up @@ -71,7 +71,7 @@ func (a DBFSAPI) Copy(src string, tgt string, client *DBApiClient, overwrite boo
fetchLoop := true
offSet := int64(0)
length := int64(1e6)
for fetchLoop == true {
for fetchLoop {
var api DBFSAPI
if client == nil {
api = a
Expand Down Expand Up @@ -176,7 +176,7 @@ func (a DBFSAPI) Status(path string) (model.FileInfo, error) {

// List returns a list of files in DBFS and the recursive flag lets you recursively list files
func (a DBFSAPI) List(path string, recursive bool) ([]model.FileInfo, error) {
if recursive == true {
if recursive {
var paths []model.FileInfo
err := a.recursiveAddPaths(path, &paths)
if err != nil {
Expand All @@ -193,9 +193,9 @@ func (a DBFSAPI) recursiveAddPaths(path string, pathList *[]model.FileInfo) erro
return err
}
for _, v := range fileInfoList {
if v.IsDir == false {
if !v.IsDir {
*pathList = append(*pathList, v)
} else if v.IsDir == true {
} else if v.IsDir {
err := a.recursiveAddPaths(v.Path, pathList)
if err != nil {
return err
Expand Down Expand Up @@ -287,7 +287,7 @@ func split(buf []byte, lim int) [][]byte {
chunks = append(chunks, chunk)
}
if len(buf) > 0 {
chunks = append(chunks, buf[:len(buf)])
chunks = append(chunks, buf[:])
}
return chunks
}
4 changes: 1 addition & 3 deletions client/service/groups.go
Expand Up @@ -159,9 +159,7 @@ func (a GroupsAPI) getInheritedAndNonInheritedRoles(group model.Group, groups []
inheritedRolesKeys := []string{}
inheritedRolesMap := map[string]model.RoleListItem{}
for _, group := range groups {
for _, role := range group.Roles {
inheritedRoles = append(inheritedRoles, role)
}
inheritedRoles = append(inheritedRoles, group.Roles...)
}
for _, role := range inheritedRoles {
inheritedRolesKeys = append(inheritedRolesKeys, role.Value)
Expand Down
12 changes: 6 additions & 6 deletions client/service/groups_test.go
Expand Up @@ -33,10 +33,10 @@ func TestScimGroupAPI_Create(t *testing.T) {
},
args: args{
Schemas: []model.URN{model.GroupSchema},
Entitlements: []model.ValueListItem{{"test-entitlement"}},
Entitlements: []model.ValueListItem{{Value:"test-entitlement"}},
DisplayName: "test group",
Roles: []model.ValueListItem{{"test-role"}},
Members: []model.ValueListItem{{"test-member"}},
Roles: []model.ValueListItem{{Value:"test-role"}},
Members: []model.ValueListItem{{Value:"test-member"}},
},
wantErr: false,
},
Expand All @@ -47,10 +47,10 @@ func TestScimGroupAPI_Create(t *testing.T) {
responseStatus: http.StatusBadRequest,
args: args{
Schemas: []model.URN{model.GroupSchema},
Entitlements: []model.ValueListItem{{"test-entitlement"}},
Entitlements: []model.ValueListItem{{Value:"test-entitlement"}},
DisplayName: "test group",
Roles: []model.ValueListItem{{"test-role"}},
Members: []model.ValueListItem{{"test-member"}},
Roles: []model.ValueListItem{{Value:"test-role"}},
Members: []model.ValueListItem{{Value:"test-member"}},
},
wantErr: true,
},
Expand Down
2 changes: 1 addition & 1 deletion client/service/notebooks.go
Expand Up @@ -79,7 +79,7 @@ func (a NotebooksAPI) Mkdirs(path string) error {
// List will list all objects in a path on the workspace and with the recursive flag it will recursively list
// all the objects
func (a NotebooksAPI) List(path string, recursive bool) ([]model.NotebookInfo, error) {
if recursive == true {
if recursive {
var paths []model.NotebookInfo
err := a.recursiveAddPaths(path, &paths)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions client/service/tokens_integration_test.go
Expand Up @@ -28,6 +28,7 @@ func TestCreateToken(t *testing.T) {
assert.NoError(t, err, err)

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

}
4 changes: 1 addition & 3 deletions client/service/users.go
Expand Up @@ -188,9 +188,7 @@ func (a UsersAPI) getInheritedAndNonInheritedRoles(user model.User, groups []mod
inheritedRolesKeys := []string{}
inheritedRolesMap := map[string]model.RoleListItem{}
for _, group := range groups {
for _, role := range group.Roles {
inheritedRoles = append(inheritedRoles, role)
}
inheritedRoles = append(inheritedRoles, group.Roles...)
}
for _, role := range inheritedRoles {
inheritedRolesKeys = append(inheritedRolesKeys, role.Value)
Expand Down
22 changes: 11 additions & 11 deletions client/service/users_test.go
Expand Up @@ -37,9 +37,9 @@ func TestScimUserAPI_Create(t *testing.T) {
args: args{
Schemas: []model.URN{model.UserSchema},
UserName: "test.user@databricks.com",
Entitlements: []model.EntitlementsListItem{{"test-entitlement"}},
Entitlements: []model.EntitlementsListItem{{Value:"test-entitlement"}},
DisplayName: "test user",
Roles: []model.RoleListItem{{"test-role"}},
Roles: []model.RoleListItem{{Value:"test-role"}},
},
wantErr: false,
},
Expand All @@ -51,9 +51,9 @@ func TestScimUserAPI_Create(t *testing.T) {
args: args{
Schemas: []model.URN{model.UserSchema},
UserName: "test.user@databricks.com",
Entitlements: []model.EntitlementsListItem{{"test-entitlement"}},
Entitlements: []model.EntitlementsListItem{{Value:"test-entitlement"}},
DisplayName: "test user",
Roles: []model.RoleListItem{{"test-role"}},
Roles: []model.RoleListItem{{Value:"test-role"}},
},
wantErr: true,
},
Expand Down Expand Up @@ -99,9 +99,9 @@ func TestScimUserAPI_Update(t *testing.T) {
&args{
Schemas: []model.URN{model.UserSchema},
UserName: "test.user@databricks.com",
Entitlements: []model.EntitlementsListItem{{"test-entitlement"}},
Entitlements: []model.EntitlementsListItem{{Value:"test-entitlement"}},
DisplayName: "test user",
Roles: []model.RoleListItem{{"test-role"}},
Roles: []model.RoleListItem{{Value:"test-role"}},
},
},
wantErr: false,
Expand All @@ -118,9 +118,9 @@ func TestScimUserAPI_Update(t *testing.T) {
&args{
Schemas: []model.URN{model.UserSchema},
UserName: "test.user@databricks.com",
Entitlements: []model.EntitlementsListItem{{"test-entitlement"}},
Entitlements: []model.EntitlementsListItem{{Value:"test-entitlement"}},
DisplayName: "test user",
Roles: []model.RoleListItem{{"test-role"}},
Roles: []model.RoleListItem{{Value:"test-role"}},
},
},
wantErr: true,
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestScimUserAPI_Delete(t *testing.T) {
func TestScimUserAPI_SetUserAsAdmin(t *testing.T) {
type args struct {
UserID string `json:"user_id,omitempty"`
AdminGroupID string `json:"user_id,omitempty"`
AdminGroupID string `json:"admin_group_id,omitempty"`
}
tests := []struct {
name string
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestScimUserAPI_SetUserAsAdmin(t *testing.T) {
func TestScimUserAPI_VerifyUserAsAdmin(t *testing.T) {
type args struct {
UserID string `json:"user_id,omitempty"`
AdminGroupID string `json:"user_id,omitempty"`
AdminGroupID string `json:"admin_group_id,omitempty"`
}
tests := []struct {
name string
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestScimUserAPI_VerifyUserAsAdmin(t *testing.T) {
func TestScimUserAPI_RemoveUserAsAdmin(t *testing.T) {
type args struct {
UserID string `json:"user_id,omitempty"`
AdminGroupID string `json:"user_id,omitempty"`
AdminGroupID string `json:"admin_group_id,omitempty"`
}
tests := []struct {
name string
Expand Down
6 changes: 6 additions & 0 deletions databricks/data_source_databricks_dbfs_file.go
Expand Up @@ -59,6 +59,9 @@ func dataSourceDBFSFileRead(d *schema.ResourceData, m interface{}) error {
return err
}
err = d.Set("content", content)
if err != nil {
return err
}
} else if fileInfo.FileSize > 4e6 {
err = d.Set("content", "File Size is too Large!")
}
Expand All @@ -68,6 +71,9 @@ func dataSourceDBFSFileRead(d *schema.ResourceData, m interface{}) error {
return err
}
err = d.Set("content", content)
if err != nil {
return err
}
}

return err
Expand Down
8 changes: 4 additions & 4 deletions databricks/provider.go
Expand Up @@ -91,12 +91,12 @@ func Provider(version string) terraform.ResourceProvider {
}

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

Expand Down
3 changes: 3 additions & 0 deletions databricks/resource_databricks_azure_adls_gen1_mount.go
Expand Up @@ -162,6 +162,9 @@ func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error {
return err
}
storageResourceName, dir, err := ProcessAzureAdlsGen1Uri(url)
if err != nil {
return err
}
err = d.Set("storage_resource_name", storageResourceName)
if err != nil {
return err
Expand Down
3 changes: 3 additions & 0 deletions databricks/resource_databricks_azure_adls_gen2_mount.go
Expand Up @@ -155,6 +155,9 @@ func resourceAzureAdlsGen2Read(d *schema.ResourceData, m interface{}) error {
return err
}
container, storageAcc, dir, err := ProcessAzureWasbAbfssUris(url)
if err != nil {
return err
}
err = d.Set("container_name", container)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions databricks/resource_databricks_azure_blob_mount.go
Expand Up @@ -89,6 +89,9 @@ func resourceAzureBlobMountCreate(d *schema.ResourceData, m interface{}) error {
tokenSecretScope, tokenSecretKey)

err = blobMount.Create(client, clusterID)
if err != nil {
return err
}

d.SetId(mountName)

Expand Down Expand Up @@ -143,6 +146,9 @@ func resourceAzureBlobMountRead(d *schema.ResourceData, m interface{}) error {
return err
}
container, storageAcc, dir, err := ProcessAzureWasbAbfssUris(url)
if err != nil {
return err
}
err = d.Set("container_name", container)
if err != nil {
return err
Expand Down

0 comments on commit 0020d9d

Please sign in to comment.