From 0bbf3e4af93b8aaba68824079d4ca444b9e675ac Mon Sep 17 00:00:00 2001 From: Sriharsha Tikkireddy Date: Mon, 20 Apr 2020 10:41:51 -0400 Subject: [PATCH 1/5] Fixed & refactored linting issues in client/model package --- client/model/cluster.go | 131 ++++++++++-------- client/model/command.go | 10 +- client/model/dbfs.go | 1 + client/model/group.go | 12 ++ client/model/instance_pool.go | 12 +- client/model/instance_profile.go | 1 + client/model/job.go | 30 ++-- client/model/library.go | 5 + client/model/notebook.go | 15 +- client/model/scim.go | 8 ++ client/model/secret.go | 23 +-- client/model/token.go | 4 +- client/model/user.go | 8 ++ client/service/clusters_test.go | 4 +- .../instance_pools_integration_test.go | 16 +-- client/service/instance_pools_test.go | 12 +- client/service/jobs_integration_test.go | 4 +- client/service/jobs_test.go | 10 +- client/service/notebooks_test.go | 10 +- client/service/secret_acls.go | 12 +- client/service/secret_acls_test.go | 18 +-- .../secrets_scopes_acls_integration_test.go | 4 +- databricks/azure_ws_init_test.go | 4 +- databricks/data_source_databricks_notebook.go | 4 +- databricks/resource_databricks_cluster.go | 14 +- .../resource_databricks_instance_pool.go | 10 +- databricks/resource_databricks_job.go | 22 +-- databricks/resource_databricks_notebook.go | 4 +- databricks/resource_databricks_secret_acl.go | 2 +- .../resource_databricks_secret_acl_test.go | 8 +- 30 files changed, 244 insertions(+), 174 deletions(-) diff --git a/client/model/cluster.go b/client/model/cluster.go index beca46830..ba3636e7e 100644 --- a/client/model/cluster.go +++ b/client/model/cluster.go @@ -1,82 +1,84 @@ package model -import "errors" - +// AutoScale is a struct the describes auto scaling for clusters type AutoScale struct { MinWorkers int32 `json:"min_workers,omitempty"` MaxWorkers int32 `json:"max_workers,omitempty"` } +// AwsAvailability is a type for describing AWS availability on cluster nodes type AwsAvailability string const ( + // AwsAvailabilitySpot is spot instance type for clusters AwsAvailabilitySpot = "SPOT" + // AwsAvailabilityOnDemand is OnDemand instance type for clusters AwsAvailabilityOnDemand = "ON_DEMAND" + // AwsAvailabilitySpotWithFallback is Spot instance type for clusters with option + // to fallback into on-demand if instance cannot be acquired AwsAvailabilitySpotWithFallback = "SPOT_WITH_FALLBACK" ) -func GetAwsAvailability(val string) (AwsAvailability, error) { - switch val { - case "SPOT": - return AwsAvailabilitySpot, nil - case "ON_DEMAND": - return AwsAvailabilityOnDemand, nil - case "SPOT_WITH_FALLBACK": - return AwsAvailabilitySpotWithFallback, nil - } - return "", errors.New("No Match!") -} - +// AzureDiskVolumeType is disk type on azure vms type AzureDiskVolumeType string const ( + // AzureDiskVolumeTypeStandard is for standard local redundant storage AzureDiskVolumeTypeStandard = "STANDARD_LRS" + // AzureDiskVolumeTypePremium is for premium local redundant storage AzureDiskVolumeTypePremium = "PREMIUM_LRS" ) -func GetAzureDiskVolumeType(val string) (AzureDiskVolumeType, error) { - switch val { - case "STANDARD_LRS": - return AzureDiskVolumeTypeStandard, nil - case "PREMIUM_LRS": - return AzureDiskVolumeTypePremium, nil - } - return "", errors.New("No Match!") -} - +// EbsVolumeType is disk type on aws vms type EbsVolumeType string const ( + // EbsVolumeTypeGeneralPurposeSsd is general purpose ssd (starts at 32 gb) EbsVolumeTypeGeneralPurposeSsd = "GENERAL_PURPOSE_SSD" + // EbsVolumeTypeThroughputOptimizedHdd is throughput optimized hdd (starts at 500 gb) EbsVolumeTypeThroughputOptimizedHdd = "THROUGHPUT_OPTIMIZED_HDD" ) -func GetEbsVolumeType(val string) (EbsVolumeType, error) { - switch val { - case "GENERAL_PURPOSE_SSD": - return EbsVolumeTypeGeneralPurposeSsd, nil - case "THROUGHPUT_OPTIMIZED_HDD": - return EbsVolumeTypeThroughputOptimizedHdd, nil - } - return "", errors.New("No Match!") -} +// ClusterState is for describing possible cluster states type ClusterState string const ( + // ClusterStatePending is for PENDING state ClusterStatePending = "PENDING" + + // ClusterStateRunning is for RUNNING state ClusterStateRunning = "RUNNING" + + // ClusterStateRestarting is for RESTARTING state ClusterStateRestarting = "RESTARTING" + + // ClusterStateResizing is for RESIZING state ClusterStateResizing = "RESIZING" + + // ClusterStateTerminating is for TERMINATING state ClusterStateTerminating = "TERMINATING" + + // ClusterStateTerminated is for TERMINATED state ClusterStateTerminated = "TERMINATED" + + // ClusterStateError is for ERROR state ClusterStateError = "ERROR" + + // ClusterStateUnknown is for UNKNOWN state ClusterStateUnknown = "UNKNOWN" ) +// ClusterStateNonRunnable is a list of states in which the cluster cannot go back into running by itself +// without user intervention var ClusterStateNonRunnable = []ClusterState{ClusterStateTerminating, ClusterStateTerminated, ClusterStateError, ClusterStateUnknown} + +// ClusterStateNonTerminating is a list of states in which the cluster cannot go back into terminated by itself +//// without user intervention var ClusterStateNonTerminating = []ClusterState{ClusterStatePending, ClusterStateRunning, ClusterStateRestarting, ClusterStateResizing, ClusterStateUnknown} +// ContainsClusterState given a set of cluster states and a search state it will return true if the state is in the +// given set func ContainsClusterState(clusterStates []ClusterState, searchState ClusterState) bool { for _, state := range clusterStates { if state == searchState { @@ -86,11 +88,13 @@ func ContainsClusterState(clusterStates []ClusterState, searchState ClusterState return false } +// ZonesInfo encapsulates the zone information from the zones api call type ZonesInfo struct { Zones []string `json:"zones,omitempty"` DefaultZone string `json:"default_zone,omitempty"` } +// AwsAttributes encapsulates the aws attributes for aws based clusters type AwsAttributes struct { FirstOnDemand int32 `json:"first_on_demand,omitempty"` Availability AwsAvailability `json:"availability,omitempty"` @@ -102,10 +106,12 @@ type AwsAttributes struct { EbsVolumeSize int32 `json:"ebs_volume_size,omitempty"` } +// DbfsStorageInfo contains the destination string for DBFS type DbfsStorageInfo struct { Destination string `json:"destination,omitempty"` } +// S3StorageInfo contains the struct for when storing files in S3 type S3StorageInfo struct { Destination string `json:"destination,omitempty"` Region string `json:"region,omitempty"` @@ -116,15 +122,18 @@ type S3StorageInfo struct { CannedACL string `json:"canned_acl,omitempty"` } +// StorageInfo contains the struct for either DBFS or S3 storage depending on which one is relevant. type StorageInfo struct { Dbfs *DbfsStorageInfo `json:"dbfs,omitempty"` S3 *S3StorageInfo `json:"s3,omitempty"` } +// SparkNodeAwsAttributes is the struct that determines if the node is a spot instance or not type SparkNodeAwsAttributes struct { IsSpot bool `json:"is_spot,omitempty"` } +// SparkNode encapsulates all the attributes of a node that is part of a databricks cluster type SparkNode struct { PrivateIP string `json:"private_ip,omitempty"` PublicDNS string `json:"public_dns,omitempty"` @@ -135,22 +144,26 @@ type SparkNode struct { HostPrivateIP string `json:"host_private_ip,omitempty"` } +// TerminationReason encapsulates the termination code and potential parameters type TerminationReason struct { Code string `json:"code,omitempty"` Parameters map[string]string `json:"parameters,omitempty"` } +// LogSyncStatus encapsulates when the cluster logs were last delivered. type LogSyncStatus struct { LastAttempted int64 `json:"last_attempted,omitempty"` LastException string `json:"last_exception,omitempty"` } +// ClusterCloudProviderNodeInfo encapsulates the existing quota available from the cloud service provider. type ClusterCloudProviderNodeInfo struct { Status []string `json:"status,omitempty"` AvailableCoreQuota float32 `json:"available_core_quota,omitempty"` TotalCoreQuota float32 `json:"total_core_quota,omitempty"` } +// NodeType encapsulates information about a give node when using the list-node-types api type NodeType struct { NodeTypeID string `json:"node_type_id,omitempty"` MemoryMb int32 `json:"memory_mb,omitempty"` @@ -161,25 +174,28 @@ type NodeType struct { NodeInfo *ClusterCloudProviderNodeInfo `json:"node_info,omitempty"` } +// DockerBasicAuth contains the auth information when fetching containers type DockerBasicAuth struct { Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` } +// DockerImage contains the image url and the auth for DCS type DockerImage struct { - Url string `json:"url,omitempty"` + URL string `json:"url,omitempty"` BasicAuth *DockerBasicAuth `json:"basic_auth,omitempty"` } +// Cluster contains the information when trying to submit api calls or editing a cluster type Cluster struct { - ClusterId string `json:"cluster_id,omitempty"` - NumWorkers int32 `json:"num_workers,omitempty"` - Autoscale *AutoScale `json:"autoscale,omitempty"` - ClusterName string `json:"cluster_name,omitempty"` - SparkVersion string `json:"spark_version,omitempty"` - SparkConf map[string]string `json:"spark_conf,omitempty"` - AwsAttributes *AwsAttributes `json:"aws_attributes,omitempty"` - NodeTypeID string `json:"node_type_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty"` + NumWorkers int32 `json:"num_workers,omitempty"` + Autoscale *AutoScale `json:"autoscale,omitempty"` + ClusterName string `json:"cluster_name,omitempty"` + SparkVersion string `json:"spark_version,omitempty"` + SparkConf map[string]string `json:"spark_conf,omitempty"` + AwsAttributes *AwsAttributes `json:"aws_attributes,omitempty"` + NodeTypeID string `json:"node_type_id,omitempty"` DriverNodeTypeID string `json:"driver_node_type_id,omitempty"` SSHPublicKeys []string `json:"ssh_public_keys,omitempty"` CustomTags map[string]string `json:"custom_tags,omitempty"` @@ -189,10 +205,11 @@ type Cluster struct { SparkEnvVars map[string]string `json:"spark_env_vars,omitempty"` AutoterminationMinutes int32 `json:"autotermination_minutes,omitempty"` EnableElasticDisk bool `json:"enable_elastic_disk,omitempty"` - InstancePoolId string `json:"instance_pool_id,omitempty"` + InstancePoolID string `json:"instance_pool_id,omitempty"` IdempotencyToken string `json:"idempotency_token,omitempty"` } +// ClusterInfo contains the information when getting cluster info from the get request. type ClusterInfo struct { NumWorkers int32 `json:"num_workers,omitempty"` AutoScale *AutoScale `json:"autoscale,omitempty"` @@ -208,20 +225,20 @@ type ClusterInfo struct { AwsAttributes *AwsAttributes `json:"aws_attributes,omitempty"` NodeTypeID string `json:"node_type_id,omitempty"` DriverNodeTypeID string `json:"driver_node_type_id,omitempty"` - SSHPublicKeys []string `json:"ssh_public_keys,omitempty"` - CustomTags map[string]string `json:"custom_tags,omitempty"` - ClusterLogConf *StorageInfo `json:"cluster_log_conf,omitempty"` - InitScripts []StorageInfo `json:"init_scripts,omitempty"` - SparkEnvVars map[string]string `json:"spark_env_vars,omitempty"` - AutoterminationMinutes int32 `json:"autotermination_minutes,omitempty"` - EnableElasticDisk bool `json:"enable_elastic_disk,omitempty"` - InstancePoolId string `json:"instance_pool_id,omitempty"` - ClusterSource AwsAvailability `json:"cluster_source,omitempty"` - DockerImage *DockerImage `json:"docker_image,omitempty"` - State ClusterState `json:"state,omitempty"` - StateMessage string `json:"state_message,omitempty"` - StartTime int64 `json:"start_time,omitempty"` - TerminateTime int64 `json:"terminate_time,omitempty"` + SSHPublicKeys []string `json:"ssh_public_keys,omitempty"` + CustomTags map[string]string `json:"custom_tags,omitempty"` + ClusterLogConf *StorageInfo `json:"cluster_log_conf,omitempty"` + InitScripts []StorageInfo `json:"init_scripts,omitempty"` + SparkEnvVars map[string]string `json:"spark_env_vars,omitempty"` + AutoterminationMinutes int32 `json:"autotermination_minutes,omitempty"` + EnableElasticDisk bool `json:"enable_elastic_disk,omitempty"` + InstancePoolID string `json:"instance_pool_id,omitempty"` + ClusterSource AwsAvailability `json:"cluster_source,omitempty"` + DockerImage *DockerImage `json:"docker_image,omitempty"` + State ClusterState `json:"state,omitempty"` + StateMessage string `json:"state_message,omitempty"` + StartTime int64 `json:"start_time,omitempty"` + TerminateTime int64 `json:"terminate_time,omitempty"` LastStateLossTime int64 `json:"last_state_loss_time,omitempty"` LastActivityTime int64 `json:"last_activity_time,omitempty"` ClusterMemoryMb int64 `json:"cluster_memory_mb,omitempty"` diff --git a/client/model/command.go b/client/model/command.go index c990b14a0..5420c32cd 100644 --- a/client/model/command.go +++ b/client/model/command.go @@ -1,5 +1,6 @@ package model +// CommandResults is the out put when the command finishes in API 1.2 type CommandResults struct { ResultType string `json:"resultType,omitempty"` Summary string `json:"summary,omitempty"` @@ -7,17 +8,12 @@ type CommandResults struct { Data interface{} `json:"data,omitempty"` Schema interface{} `json:"schema,omitempty"` Truncated bool `json:"truncated,omitempty"` - IsJsonSchema bool `json:"isJsonSchema,omitempty"` + IsJSONSchema bool `json:"isJsonSchema,omitempty"` } +// Command is the struct that contains what the 1.2 api returns for the commands api type Command struct { ID string `json:"id,omitempty"` Status string `json:"status,omitempty"` Results *CommandResults `json:"results,omitempty"` } - -type ExecutionContext struct { - ContextId string `json:"contextId,omitempty"` - ClusterId string `json:"clusterId,omitempty"` - Language Language `json:"language,omitempty"` -} diff --git a/client/model/dbfs.go b/client/model/dbfs.go index fb69a0e9c..36ac984e4 100644 --- a/client/model/dbfs.go +++ b/client/model/dbfs.go @@ -1,5 +1,6 @@ package model +// FileInfo contains information when listing files or fetching files from DBFS api type FileInfo struct { Path string `json:"path,omitempty"` IsDir bool `json:"is_dir,omitempty"` diff --git a/client/model/group.go b/client/model/group.go index 2ff303604..0b087fc17 100644 --- a/client/model/group.go +++ b/client/model/group.go @@ -1,23 +1,33 @@ package model +// GroupMember contains information of a member in a scim group type GroupMember struct { Display string `json:"display,omitempty"` Value string `json:"value,omitempty"` Ref string `json:"$ref,omitempty"` } +// ValueListItem is a struct that contains a field Value. +// This is for the scim api. type ValueListItem struct { Value string `json:"value,omitempty"` } +// GroupPathType describes the possible paths in the SCIM RFC for patch operations type GroupPathType string const ( + // GroupMembersPath is the members path for SCIM patch operation. GroupMembersPath GroupPathType = "members" + + // GroupRolesPath is the roles path for SCIM patch operation. GroupRolesPath GroupPathType = "roles" + + // GroupEntitlementsPath is the entitlements path for SCIM patch operation. GroupEntitlementsPath GroupPathType = "entitlements" ) +// Group contains information about the SCIM group type Group struct { ID string `json:"id,omitempty"` Schemas []URN `json:"schemas,omitempty"` @@ -30,6 +40,7 @@ type Group struct { InheritedRoles []RoleListItem `json:"inherited_roles,omitempty"` } +// GroupList contains a list of groups fetched from a list api call from SCIM api type GroupList struct { TotalResults int32 `json:"totalResults,omitempty"` StartIndex int32 `json:"startIndex,omitempty"` @@ -38,6 +49,7 @@ type GroupList struct { Resources []Group `json:"resources,omitempty"` } +// GroupPatchRequest contains a request structure to make a patch op against SCIM api type GroupPatchRequest struct { Schemas []URN `json:"schemas,omitempty"` Operations []GroupPatchOperations `json:"Operations,omitempty"` diff --git a/client/model/instance_pool.go b/client/model/instance_pool.go index 191c4d0f0..6b3cf916f 100644 --- a/client/model/instance_pool.go +++ b/client/model/instance_pool.go @@ -1,28 +1,32 @@ package model +// InstancePoolAwsAttributes contains aws attributes for AWS Databricks deployments for instance pools type InstancePoolAwsAttributes struct { Availability AwsAvailability `json:"availability,omitempty"` ZoneID string `json:"zone_id,omitempty"` SpotBidPricePercent int32 `json:"spot_bid_price_percent,omitempty"` } +// InstancePoolDiskType contains disk type information for each of the different cloud service providers type InstancePoolDiskType struct { AzureDiskVolumeType string `json:"azure_disk_volume_type,omitempty"` EbsVolumeType string `json:"ebs_volume_type,omitempty"` } +// InstancePoolDiskSpec contains disk size, type and count information for the pool type InstancePoolDiskSpec struct { DiskType *InstancePoolDiskType `json:"disk_type,omitempty"` DiskCount int32 `json:"disk_count,omitempty"` DiskSize int32 `json:"disk_size,omitempty"` } +// InstancePool describes the instance pool object on Databricks type InstancePool struct { InstancePoolName string `json:"instance_pool_name,omitempty"` MinIdleInstances int32 `json:"min_idle_instances,omitempty"` MaxCapacity int32 `json:"max_capacity,omitempty"` AwsAttributes *InstancePoolAwsAttributes `json:"aws_attributes,omitempty"` - NodeTypeId string `json:"node_type_id,omitempty"` + NodeTypeID string `json:"node_type_id,omitempty"` CustomTags map[string]string `json:"custom_tags,omitempty"` IdleInstanceAutoTerminationMinutes int32 `json:"idle_instance_autotermination_minutes,omitempty"` EnableElasticDisk bool `json:"enable_elastic_disk,omitempty"` @@ -30,6 +34,7 @@ type InstancePool struct { PreloadedSparkVersions []string `json:"preloaded_spark_versions,omitempty"` } +// InstancePoolStats contains the stats on a given pool type InstancePoolStats struct { UsedCount int32 `json:"used_count,omitempty"` IdleCount int32 `json:"idle_count,omitempty"` @@ -37,13 +42,14 @@ type InstancePoolStats struct { PendingIdleCount int32 `json:"pending_idle_count,omitempty"` } +// InstancePoolInfo encapsulates a get response from the GET api for instance pools on Databricks type InstancePoolInfo struct { - InstancePoolId string `json:"instance_pool_id,omitempty"` + InstancePoolID string `json:"instance_pool_id,omitempty"` InstancePoolName string `json:"instance_pool_name,omitempty"` MinIdleInstances int32 `json:"min_idle_instances,omitempty"` MaxCapacity int32 `json:"max_capacity,omitempty"` AwsAttributes *InstancePoolAwsAttributes `json:"aws_attributes,omitempty"` - NodeTypeId string `json:"node_type_id,omitempty"` + NodeTypeID string `json:"node_type_id,omitempty"` DefaultTags map[string]string `json:"default_tags,omitempty"` CustomTags map[string]string `json:"custom_tags,omitempty"` IdleInstanceAutoTerminationMinutes int32 `json:"idle_instance_autotermination_minutes,omitempty"` diff --git a/client/model/instance_profile.go b/client/model/instance_profile.go index c17807d91..b4d91d03c 100644 --- a/client/model/instance_profile.go +++ b/client/model/instance_profile.go @@ -1,5 +1,6 @@ package model +// InstanceProfileInfo contains the ARN for aws instance profiles type InstanceProfileInfo struct { InstanceProfileArn string `json:"instance_profile_arn,omitempty"` } diff --git a/client/model/job.go b/client/model/job.go index 755c40087..f9140dab9 100644 --- a/client/model/job.go +++ b/client/model/job.go @@ -1,27 +1,30 @@ package model -//go:generate easytags $GOFILE - +// NotebookTask contains the information for notebook jobs type NotebookTask struct { NotebookPath string `json:"notebook_path,omitempty"` BaseParameters map[string]string `json:"base_parameters,omitempty"` } +// SparkPythonTask contains the information for python jobs type SparkPythonTask struct { PythonFile string `json:"python_file,omitempty"` Parameters []string `json:"parameters,omitempty"` } +// SparkJarTask contains the information for jar jobs type SparkJarTask struct { - JarUri string `json:"jar_uri,omitempty"` + JarURI string `json:"jar_uri,omitempty"` MainClassName string `json:"main_class_name,omitempty"` Parameters []string `json:"parameters,omitempty"` } +// SparkSubmitTask contains the information for spark submit jobs type SparkSubmitTask struct { Parameters []string `json:"parameters,omitempty"` } +// JobEmailNotifications contains the information for email notifications after job completion type JobEmailNotifications struct { OnStart []string `json:"on_start,omitempty"` OnSuccess []string `json:"on_success,omitempty"` @@ -29,19 +32,21 @@ type JobEmailNotifications struct { NoAlertForSkippedRuns bool `json:"no_alert_for_skipped_runs,omitempty"` } +// CronSchedule contains the information for the quartz cron expression type CronSchedule struct { QuartzCronExpression string `json:"quartz_cron_expression,omitempty"` - TimezoneId string `json:"timezone_id,omitempty"` + TimezoneID string `json:"timezone_id,omitempty"` } +// JobSettings contains the information for configuring a job on databricks type JobSettings struct { - ExistingClusterId string `json:"existing_cluster_id,omitempty"` - NewCluster *Cluster `json:"new_cluster,omitempty"` - NotebookTask *NotebookTask `json:"notebook_task,omitempty"` - SparkJarTask *SparkJarTask `json:"spark_jar_task,omitempty"` - SparkPythonTask *SparkPythonTask `json:"spark_python_task,omitempty"` - SparkSubmitTask *SparkSubmitTask `json:"spark_submit_task,omitempty"` - Name string `json:"name,omitempty"` + ExistingClusterID string `json:"existing_cluster_id,omitempty"` + NewCluster *Cluster `json:"new_cluster,omitempty"` + NotebookTask *NotebookTask `json:"notebook_task,omitempty"` + SparkJarTask *SparkJarTask `json:"spark_jar_task,omitempty"` + SparkPythonTask *SparkPythonTask `json:"spark_python_task,omitempty"` + SparkSubmitTask *SparkSubmitTask `json:"spark_submit_task,omitempty"` + Name string `json:"name,omitempty"` Libraries []Library `json:"libraries,omitempty"` EmailNotifications *JobEmailNotifications `json:"email_notifications,omitempty"` TimeoutSeconds int32 `json:"timeout_seconds,omitempty"` @@ -52,8 +57,9 @@ type JobSettings struct { MaxConcurrentRuns int32 `json:"max_concurrent_runs,omitempty"` } +// Job contains the information when using a GET request from the Databricks Jobs api type Job struct { - JobId int64 `json:"job_id,omitempty"` + JobID int64 `json:"job_id,omitempty"` CreatorUserName string `json:"creator_user_name,omitempty"` Settings *JobSettings `json:"settings,omitempty"` CreatedTime int64 `json:"created_time,omitempty"` diff --git a/client/model/library.go b/client/model/library.go index b3e458be0..4151f611b 100644 --- a/client/model/library.go +++ b/client/model/library.go @@ -1,21 +1,25 @@ package model +// PyPi is a python library hosted on PYPI type PyPi struct { Package string `json:"package,omitempty"` Repo string `json:"repo,omitempty"` } +// Maven is a jar library hosted on Maven type Maven struct { Coordinates string `json:"coordinates,omitempty"` Repo string `json:"repo,omitempty"` Exclusions []string `json:"exclusions,omitempty"` } +// Cran is a R library hosted on Maven type Cran struct { Package string `json:"package,omitempty"` Repo string `json:"repo,omitempty"` } +// Library is a construct that contains information of the location of the library and how to download it type Library struct { Jar string `json:"jar,omitempty"` Egg string `json:"egg,omitempty"` @@ -25,6 +29,7 @@ type Library struct { Cran *Cran `json:"cran,omitempty"` } +// LibraryStatus is the status on a given cluster when using the libraries status api type LibraryStatus struct { Library *Library `json:"library,omitempty"` Status string `json:"status,omitempty"` diff --git a/client/model/notebook.go b/client/model/notebook.go index 158d86431..f6ac24d81 100644 --- a/client/model/notebook.go +++ b/client/model/notebook.go @@ -1,18 +1,23 @@ package model -//go:generate easytags $GOFILE - +// Language is a custom type for langauge types in Databricks notebooks type Language string + +// ObjectType is a custom type for object types in Databricks workspaces type ObjectType string + +// ExportFormat is a custom type for formats in which you can export Databricks workspace components type ExportFormat string +// Different types of export formats available on Databricks const ( Source ExportFormat = "SOURCE" - Html ExportFormat = "HTML" + HTML ExportFormat = "HTML" Jupyter ExportFormat = "JUPYTER" DBC ExportFormat = "DBC" ) +// Different types of langauge formats available on Databricks const ( Scala Language = "SCALA" Python Language = "PYTHON" @@ -20,14 +25,16 @@ const ( R Language = "R" ) +// Different types of export formats available on Databricks const ( Notebook ObjectType = "NOTEBOOK" Directory ObjectType = "DIRECTORY" LibraryObject ObjectType = "LIBRARY" ) +// NotebookInfo contains information when doing a get request or list request on the workspace api type NotebookInfo struct { - ObjectId int64 `json:"object_id,omitempty"` + ObjectID int64 `json:"object_id,omitempty"` ObjectType ObjectType `json:"object_type,omitempty"` Path string `json:"path,omitempty"` Language Language `json:"language,omitempty"` diff --git a/client/model/scim.go b/client/model/scim.go index 3bbb9f9ef..6e8a131f5 100644 --- a/client/model/scim.go +++ b/client/model/scim.go @@ -1,7 +1,9 @@ package model +// URN is a custom type for the SCIM spec for the schema type URN string +// Possible schema URNs for the Databricks SCIM api const ( UserSchema URN = "urn:ietf:params:scim:schemas:core:2.0:User" WorkspaceUserSchema URN = "urn:ietf:params:scim:schemas:extension:workspace:2.0:User" @@ -9,28 +11,34 @@ const ( GroupSchema URN = "urn:ietf:params:scim:schemas:core:2.0:Group" ) +// MembersValue is a list of value items for the members path type MembersValue struct { Members []ValueListItem `json:"members,omitempty"` } +// RolesValue is a list of value items for the roles path type RolesValue struct { Roles []ValueListItem `json:"roles,omitempty"` } +// ValueList is a generic list of value items for any path type ValueList struct { Value []ValueListItem `json:"value,omitempty"` } +// GroupsValue is a list of value items for the groups path type GroupsValue struct { Groups []ValueListItem `json:"groups,omitempty"` } +// GroupPatchOperations is a list of path operations for add or removing group attributes type GroupPatchOperations struct { Op string `json:"op,omitempty"` Path GroupPathType `json:"path,omitempty"` Value []ValueListItem `json:"value,omitempty"` } +// UserPatchOperations is a list of path operations for add or removing user attributes type UserPatchOperations struct { Op string `json:"op,omitempty"` Path string `json:"path,omitempty"` diff --git a/client/model/secret.go b/client/model/secret.go index b4207005a..e56bd5f39 100644 --- a/client/model/secret.go +++ b/client/model/secret.go @@ -1,34 +1,37 @@ package model +// ScopeBackendType is a custom type for the backend type for secret scopes type ScopeBackendType string +// List of constants of ScopeBackendType const ( ScopeBackendTypeDatabricks ScopeBackendType = "DATABRICKS" ) +// SecretScope is a struct that encapsulates the secret scope type SecretScope struct { Name string `json:"name,omitempty"` BackendType ScopeBackendType `json:"backend_type,omitempty"` } +// SecretMetadata is a struct that encapsulates the metadata for a secret object in a scope type SecretMetadata struct { Key string `json:"key,omitempty"` LastUpdatedTimestamp int64 `json:"last_updated_timestamp,omitempty"` } -type AclPermission string +// ACLPermission is a custom type for acl permissions +type ACLPermission string +// List of possible ACL Permissions on Databricks const ( - AclPermissionRead AclPermission = "READ" - AclPermissionWrite AclPermission = "WRITE" - AclPermissionManage AclPermission = "MANAGE" + ACLPermissionRead ACLPermission = "READ" + ACLPermissionWrite ACLPermission = "WRITE" + ACLPermissionManage ACLPermission = "MANAGE" ) -func ValidSecretAclPermissions() []AclPermission { - return []AclPermission{AclPermissionManage, AclPermissionRead, AclPermissionWrite} -} - -type AclItem struct { +// ACLItem is a struct that contains information about a secret scope acl +type ACLItem struct { Principal string `json:"principal,omitempty"` - Permission AclPermission `json:"permission,omitempty"` + Permission ACLPermission `json:"permission,omitempty"` } diff --git a/client/model/token.go b/client/model/token.go index 6c7cde04f..72e7ade35 100644 --- a/client/model/token.go +++ b/client/model/token.go @@ -1,12 +1,12 @@ package model -//go:generate easytags $GOFILE - +// TokenResponse is a struct that contains information about token that is created from the create tokens api type TokenResponse struct { TokenValue string `json:"token_value,omitempty"` TokenInfo *TokenInfo `json:"token_info,omitempty"` } +// TokenInfo is a struct that contains metadata about a given token type TokenInfo struct { TokenID string `json:"token_id,omitempty"` CreationTime int64 `json:"creation_time,omitempty"` diff --git a/client/model/user.go b/client/model/user.go index 5960ea1fd..eef2d54f2 100644 --- a/client/model/user.go +++ b/client/model/user.go @@ -1,30 +1,37 @@ package model +// Entitlement is a custom type that contains a set of entitlements for a user/group type Entitlement string +// List of possible entitlement constants on Databricks const ( AllowClusterCreateEntitlement Entitlement = "allow-cluster-create" AllowInstancePoolCreateEntitlement Entitlement = "allow-instance-pool-create" ) +// GroupsListItem is a struct that contains a value of group id type GroupsListItem struct { Value string `json:"value,omitempty"` } +// EntitlementsListItem is a struct that contains a value of entitlement type EntitlementsListItem struct { Value Entitlement `json:"value,omitempty"` } +// RoleListItem is a struct that contains a value of role type RoleListItem struct { Value string `json:"value,omitempty"` } +// Email is a struct that contains information about a user's email type Email struct { Type interface{} `json:"type,omitempty"` Value string `json:"value,omitempty"` Primary interface{} `json:"primary,omitempty"` } +// User is a struct that contains all the information about a SCIM user type User struct { ID string `json:"id,omitempty"` Emails []Email `json:"emails,omitempty"` @@ -40,6 +47,7 @@ type User struct { InheritedRoles []RoleListItem `json:"inherited_roles,omitempty"` } +// UserPatchRequest is a struct that contains all the information for a PATCH request to the SCIM users api type UserPatchRequest struct { Schemas []URN `json:"schemas,omitempty"` Operations []UserPatchOperations `json:"Operations,omitempty"` diff --git a/client/service/clusters_test.go b/client/service/clusters_test.go index 2af4dfdc2..9f299fc39 100644 --- a/client/service/clusters_test.go +++ b/client/service/clusters_test.go @@ -25,7 +25,7 @@ func TestClustersAPI_Create(t *testing.T) { }`, responseStatus: http.StatusOK, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: model.ClusterInfo{ClusterID: "my-cluster"}, wantErr: false, @@ -35,7 +35,7 @@ func TestClustersAPI_Create(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: model.ClusterInfo{}, wantErr: true, diff --git a/client/service/instance_pools_integration_test.go b/client/service/instance_pools_integration_test.go index f5e48bdaf..9c09c0b05 100644 --- a/client/service/instance_pools_integration_test.go +++ b/client/service/instance_pools_integration_test.go @@ -23,7 +23,7 @@ func TestInstancePools(t *testing.T) { DiskCount: 1, DiskSize: 32, }, - NodeTypeId: GetCloudInstanceType(client), + NodeTypeID: GetCloudInstanceType(client), IdleInstanceAutoTerminationMinutes: 20, PreloadedSparkVersions: []string{ "6.3.x-scala2.11", @@ -33,21 +33,21 @@ func TestInstancePools(t *testing.T) { assert.NoError(t, err, err) defer func() { - err := client.InstancePools().Delete(poolInfo.InstancePoolId) + err := client.InstancePools().Delete(poolInfo.InstancePoolID) assert.NoError(t, err, err) }() - poolReadInfo, err := client.InstancePools().Read(poolInfo.InstancePoolId) + poolReadInfo, err := client.InstancePools().Read(poolInfo.InstancePoolID) assert.NoError(t, err, err) - assert.Equal(t, poolInfo.InstancePoolId, poolReadInfo.InstancePoolId) + assert.Equal(t, poolInfo.InstancePoolID, poolReadInfo.InstancePoolID) assert.Equal(t, pool.InstancePoolName, poolReadInfo.InstancePoolName) assert.Equal(t, pool.MinIdleInstances, poolReadInfo.MinIdleInstances) assert.Equal(t, pool.MaxCapacity, poolReadInfo.MaxCapacity) - assert.Equal(t, pool.NodeTypeId, poolReadInfo.NodeTypeId) + assert.Equal(t, pool.NodeTypeID, poolReadInfo.NodeTypeID) assert.Equal(t, pool.IdleInstanceAutoTerminationMinutes, poolReadInfo.IdleInstanceAutoTerminationMinutes) err = client.InstancePools().Update(model.InstancePoolInfo{ - InstancePoolId: poolReadInfo.InstancePoolId, + InstancePoolID: poolReadInfo.InstancePoolID, InstancePoolName: "my_instance_pool", MinIdleInstances: 0, MaxCapacity: 20, @@ -58,7 +58,7 @@ func TestInstancePools(t *testing.T) { DiskCount: 1, DiskSize: 32, }, - NodeTypeId: GetCloudInstanceType(client), + NodeTypeID: GetCloudInstanceType(client), IdleInstanceAutoTerminationMinutes: 20, PreloadedSparkVersions: []string{ "6.3.x-scala2.11", @@ -66,7 +66,7 @@ func TestInstancePools(t *testing.T) { }) assert.NoError(t, err, err) - poolReadInfo, err = client.InstancePools().Read(poolInfo.InstancePoolId) + poolReadInfo, err = client.InstancePools().Read(poolInfo.InstancePoolID) assert.NoError(t, err, err) assert.Equal(t, poolReadInfo.MaxCapacity, int32(20)) diff --git a/client/service/instance_pools_test.go b/client/service/instance_pools_test.go index eb1d26808..5b434462b 100644 --- a/client/service/instance_pools_test.go +++ b/client/service/instance_pools_test.go @@ -29,7 +29,7 @@ func TestInstancePoolsAPI_Create(t *testing.T) { InstancePoolName: "", MinIdleInstances: 0, MaxCapacity: 10, - NodeTypeId: "Standard_DS3_v2", + NodeTypeID: "Standard_DS3_v2", IdleInstanceAutoTerminationMinutes: 60, EnableElasticDisk: false, DiskSpec: &model.InstancePoolDiskSpec{ @@ -42,7 +42,7 @@ func TestInstancePoolsAPI_Create(t *testing.T) { }, }, want: model.InstancePoolInfo{ - InstancePoolId: "0101-120000-brick1-pool-ABCD1234", + InstancePoolID: "0101-120000-brick1-pool-ABCD1234", }, wantErr: false, }, @@ -101,10 +101,10 @@ func TestInstancePoolsAPI_Update(t *testing.T) { response: "", args: args{ InstancePoolInfo: &model.InstancePoolInfo{ - InstancePoolId: "0101-120000-brick1-pool-ABCD1234", + InstancePoolID: "0101-120000-brick1-pool-ABCD1234", MinIdleInstances: 0, MaxCapacity: 10, - NodeTypeId: "Standard_DS3_v2", + NodeTypeID: "Standard_DS3_v2", IdleInstanceAutoTerminationMinutes: 60, EnableElasticDisk: false, DiskSpec: &model.InstancePoolDiskSpec{ @@ -182,7 +182,7 @@ func TestInstancePoolsAPI_Read(t *testing.T) { InstancePoolId: "101-120000-brick1-pool-ABCD1234", }, want: model.InstancePoolInfo{ - InstancePoolId: "101-120000-brick1-pool-ABCD1234", + InstancePoolID: "101-120000-brick1-pool-ABCD1234", InstancePoolName: "mypool", MinIdleInstances: 0, AwsAttributes: &model.InstancePoolAwsAttributes{ @@ -190,7 +190,7 @@ func TestInstancePoolsAPI_Read(t *testing.T) { ZoneID: "us-west-2a", SpotBidPricePercent: 100, }, - NodeTypeId: "c4.2xlarge", + NodeTypeID: "c4.2xlarge", IdleInstanceAutoTerminationMinutes: 60, EnableElasticDisk: false, DiskSpec: &model.InstancePoolDiskSpec{ diff --git a/client/service/jobs_integration_test.go b/client/service/jobs_integration_test.go index 573bbd9df..a50f96886 100644 --- a/client/service/jobs_integration_test.go +++ b/client/service/jobs_integration_test.go @@ -43,14 +43,14 @@ func TestJobsCreate(t *testing.T) { MaxRetries: 1, Schedule: &model.CronSchedule{ QuartzCronExpression: "0 15 22 ? * *", - TimezoneId: "America/Los_Angeles", + TimezoneID: "America/Los_Angeles", }, MaxConcurrentRuns: 1, } job, err := client.Jobs().Create(jobSettings) assert.NoError(t, err, err) - id := job.JobId + id := job.JobID defer func() { err := client.Jobs().Delete(id) assert.NoError(t, err, err) diff --git a/client/service/jobs_test.go b/client/service/jobs_test.go index 2cb85799e..52ca07f82 100644 --- a/client/service/jobs_test.go +++ b/client/service/jobs_test.go @@ -24,10 +24,10 @@ func TestJobsAPI_Create(t *testing.T) { }`, responseStatus: http.StatusOK, args: args{ - ExistingClusterId: "my-cluster-id", + ExistingClusterID: "my-cluster-id", }, want: model.Job{ - JobId: 1, + JobID: 1, }, wantErr: false, }, @@ -36,7 +36,7 @@ func TestJobsAPI_Create(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ExistingClusterId: "my-cluster-id", + ExistingClusterID: "my-cluster-id", }, want: model.Job{}, wantErr: true, @@ -202,7 +202,7 @@ func TestJobsAPI_Read(t *testing.T) { }, wantUri: "/api/2.0/jobs/get?job_id=1", want: model.Job{ - JobId: 1, + JobID: 1, Settings: &model.JobSettings{ NewCluster: &model.Cluster{ NumWorkers: 10, @@ -235,7 +235,7 @@ func TestJobsAPI_Read(t *testing.T) { MaxRetries: 1, Schedule: &model.CronSchedule{ QuartzCronExpression: "0 15 22 ? * *", - TimezoneId: "America/Los_Angeles", + TimezoneID: "America/Los_Angeles", }, }, CreatedTime: 1457570074236, diff --git a/client/service/notebooks_test.go b/client/service/notebooks_test.go index ba498ceaa..591d40e66 100644 --- a/client/service/notebooks_test.go +++ b/client/service/notebooks_test.go @@ -147,12 +147,12 @@ func TestNotebooksAPI_ListNonRecursive(t *testing.T) { wantUri: "/api/2.0/workspace/list?path=%2Ftest%2Fpath", want: []model.NotebookInfo{ { - ObjectId: 123, + ObjectID: 123, ObjectType: model.Directory, Path: "/Users/user@example.com/project", }, { - ObjectId: 456, + ObjectID: 456, ObjectType: model.Notebook, Language: model.Python, Path: "/Users/user@example.com/PythonExampleNotebook", @@ -223,13 +223,13 @@ func TestNotebooksAPI_ListRecursive(t *testing.T) { wantUri: []string{"/api/2.0/workspace/list?path=%2Ftest%2Fpath", "/api/2.0/workspace/list?path=%2FUsers%2Fuser%40example.com%2Fproject"}, want: []model.NotebookInfo{ { - ObjectId: 457, + ObjectID: 457, ObjectType: model.Notebook, Language: model.Python, Path: "/Users/user@example.com/Notebook2", }, { - ObjectId: 456, + ObjectID: 456, ObjectType: model.Notebook, Language: model.Python, Path: "/Users/user@example.com/PythonExampleNotebook", @@ -303,7 +303,7 @@ func TestNotebooksAPI_Read(t *testing.T) { }, responseStatus: http.StatusOK, want: model.NotebookInfo{ - ObjectId: 789, + ObjectID: 789, ObjectType: model.Notebook, Path: "/Users/user@example.com/project/ScalaExampleNotebook", Language: model.Scala, diff --git a/client/service/secret_acls.go b/client/service/secret_acls.go index 6cae5e4f1..49d8fe4e1 100644 --- a/client/service/secret_acls.go +++ b/client/service/secret_acls.go @@ -12,11 +12,11 @@ type SecretAclsAPI struct { } // Create creates or overwrites the ACL associated with the given principal (user or group) on the specified scope point -func (a SecretAclsAPI) Create(scope string, principal string, permission model.AclPermission) error { +func (a SecretAclsAPI) Create(scope string, principal string, permission model.ACLPermission) error { data := struct { Scope string `json:"scope,omitempty"` Principal string `json:"principal,omitempty"` - Permission model.AclPermission `json:"permission,omitempty"` + Permission model.ACLPermission `json:"permission,omitempty"` }{ scope, principal, @@ -40,8 +40,8 @@ func (a SecretAclsAPI) Delete(scope string, principal string) error { } // Read describe the details about the given ACL, such as the group and permission -func (a SecretAclsAPI) Read(scope string, principal string) (model.AclItem, error) { - var aclItem model.AclItem +func (a SecretAclsAPI) Read(scope string, principal string) (model.ACLItem, error) { + var aclItem model.ACLItem data := struct { Scope string `json:"scope,omitempty" url:"scope,omitempty"` @@ -60,9 +60,9 @@ func (a SecretAclsAPI) Read(scope string, principal string) (model.AclItem, erro } // List lists the ACLs set on the given scope -func (a SecretAclsAPI) List(scope string) ([]model.AclItem, error) { +func (a SecretAclsAPI) List(scope string) ([]model.ACLItem, error) { var aclItem struct { - Items []model.AclItem `json:"items,omitempty"` + Items []model.ACLItem `json:"items,omitempty"` } data := struct { diff --git a/client/service/secret_acls_test.go b/client/service/secret_acls_test.go index 76e5d8e2f..3a1c7c74e 100644 --- a/client/service/secret_acls_test.go +++ b/client/service/secret_acls_test.go @@ -12,7 +12,7 @@ func TestSecretAclsAPI_Create(t *testing.T) { type args struct { Scope string `json:"scope"` Principal string `json:"principal"` - Permission model.AclPermission `json:"permission"` + Permission model.ACLPermission `json:"permission"` } tests := []struct { name string @@ -26,7 +26,7 @@ func TestSecretAclsAPI_Create(t *testing.T) { args: args{ Scope: "my-scope", Principal: "my-principal", - Permission: model.AclPermissionManage, + Permission: model.ACLPermissionManage, }, wantErr: false, }, @@ -80,7 +80,7 @@ func TestSecretAclsAPI_List(t *testing.T) { name string response string args args - want []model.AclItem + want []model.ACLItem wantErr bool }{ { @@ -99,14 +99,14 @@ func TestSecretAclsAPI_List(t *testing.T) { args: args{ Scope: "my-scope", }, - want: []model.AclItem{ + want: []model.ACLItem{ { Principal: "admins", - Permission: model.AclPermissionManage, + Permission: model.ACLPermissionManage, }, { Principal: "data-scientists", - Permission: model.AclPermissionRead, + Permission: model.ACLPermissionRead, }, }, wantErr: false, @@ -131,7 +131,7 @@ func TestSecretAclsAPI_Read(t *testing.T) { name string response string args args - want model.AclItem + want model.ACLItem wantErr bool }{ { @@ -144,9 +144,9 @@ func TestSecretAclsAPI_Read(t *testing.T) { Scope: "my-scope", Principal: "my-principal", }, - want: model.AclItem{ + want: model.ACLItem{ Principal: "data-scientists", - Permission: model.AclPermissionRead, + Permission: model.ACLPermissionRead, }, wantErr: false, }, diff --git a/client/service/secrets_scopes_acls_integration_test.go b/client/service/secrets_scopes_acls_integration_test.go index 989bc49c3..8bec5bb57 100644 --- a/client/service/secrets_scopes_acls_integration_test.go +++ b/client/service/secrets_scopes_acls_integration_test.go @@ -47,7 +47,7 @@ func TestSecretsScopesAclsIntegration(t *testing.T) { assert.NoError(t, err, err) assert.Equal(t, testKey, secret.Key, "Secret lookup does not yield same key") - err = client.SecretAcls().Create(testScope, testPrincipal, model.AclPermissionManage) + err = client.SecretAcls().Create(testScope, testPrincipal, model.ACLPermissionManage) assert.NoError(t, err, err) secretAcls, err := client.SecretAcls().List(testScope) @@ -57,7 +57,7 @@ func TestSecretsScopesAclsIntegration(t *testing.T) { secretAcl, err := client.SecretAcls().Read(testScope, testPrincipal) assert.NoError(t, err, err) assert.Equal(t, testPrincipal, secretAcl.Principal, "Secret lookup does not yield same key") - assert.Equal(t, model.AclPermissionManage, secretAcl.Permission, "Secret lookup does not yield same key") + assert.Equal(t, model.ACLPermissionManage, secretAcl.Permission, "Secret lookup does not yield same key") err = client.Secrets().Delete(testScope, testKey) assert.NoError(t, err, err) diff --git a/databricks/azure_ws_init_test.go b/databricks/azure_ws_init_test.go index 50a0150f4..9ebcd2713 100644 --- a/databricks/azure_ws_init_test.go +++ b/databricks/azure_ws_init_test.go @@ -47,14 +47,14 @@ func TestAzureAuthCreateApiToken(t *testing.T) { InstancePoolName: "my_instance_pool", MinIdleInstances: 0, MaxCapacity: 10, - NodeTypeId: "Standard_DS3_v2", + NodeTypeID: "Standard_DS3_v2", IdleInstanceAutoTerminationMinutes: 20, PreloadedSparkVersions: []string{ "6.3.x-scala2.11", }, }) defer func() { - err := api.InstancePools().Delete(instancePoolInfo.InstancePoolId) + err := api.InstancePools().Delete(instancePoolInfo.InstancePoolID) assert.NoError(t, err, err) }() diff --git a/databricks/data_source_databricks_notebook.go b/databricks/data_source_databricks_notebook.go index 167f624b4..848333d82 100644 --- a/databricks/data_source_databricks_notebook.go +++ b/databricks/data_source_databricks_notebook.go @@ -24,7 +24,7 @@ func dataSourceNotebook() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{ string(model.DBC), string(model.Source), - string(model.Html), + string(model.HTML), }, false), }, "content": &schema.Schema{ @@ -75,7 +75,7 @@ func dataSourceNotebookRead(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - err = d.Set("object_id", int(notebookInfo.ObjectId)) + err = d.Set("object_id", int(notebookInfo.ObjectID)) if err != nil { return err } diff --git a/databricks/resource_databricks_cluster.go b/databricks/resource_databricks_cluster.go index fc4fd9b89..7811694af 100644 --- a/databricks/resource_databricks_cluster.go +++ b/databricks/resource_databricks_cluster.go @@ -710,7 +710,7 @@ func resourceClusterRead(d *schema.ResourceData, m interface{}) error { if clusterInfo.DockerImage != nil { dockerImage := map[string]string{} - dockerImage["url"] = clusterInfo.DockerImage.Url + dockerImage["url"] = clusterInfo.DockerImage.URL if clusterInfo.DockerImage.BasicAuth != nil { dockerImage["username"] = clusterInfo.DockerImage.BasicAuth.Username dockerImage["password"] = clusterInfo.DockerImage.BasicAuth.Password @@ -745,7 +745,7 @@ func resourceClusterRead(d *schema.ResourceData, m interface{}) error { } if _, ok := d.GetOk("instance_pool_id"); ok { - err := d.Set("instance_pool_id", clusterInfo.InstancePoolId) + err := d.Set("instance_pool_id", clusterInfo.InstancePoolID) if err != nil { return err } @@ -949,7 +949,7 @@ func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error { if model.ContainsClusterState([]model.ClusterState{model.ClusterState(model.ClusterStateTerminated)}, clusterState) { cluster := parseSchemaToCluster(d, "") - cluster.ClusterId = id + cluster.ClusterID = id err := client.Clusters().Edit(cluster) if err != nil { return err @@ -986,7 +986,7 @@ func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error { return resourceClusterRead(d, m) } else if model.ContainsClusterState([]model.ClusterState{model.ClusterState(model.ClusterStateRunning)}, clusterState) { cluster := parseSchemaToCluster(d, "") - cluster.ClusterId = id + cluster.ClusterID = id if len(installs) > 0 { err = client.Libraries().Create(id, installs) @@ -1020,7 +1020,7 @@ func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error { return err } cluster := parseSchemaToCluster(d, "") - cluster.ClusterId = id + cluster.ClusterID = id if len(installs) > 0 { err = client.Libraries().Create(id, installs) @@ -1239,7 +1239,7 @@ func parseSchemaToCluster(d *schema.ResourceData, schemaAttPrefix string) model. if dockerImageSet, ok := d.GetOk(schemaAttPrefix + "docker_image"); ok { dockerImageConf := getMapFromOneItemSet(dockerImageSet) if url, ok := dockerImageConf["url"]; ok { - dockerImageData.Url = url.(string) + dockerImageData.URL = url.(string) } dockerAuthData := model.DockerBasicAuth{} username, userOk := dockerImageConf["username"] @@ -1269,7 +1269,7 @@ func parseSchemaToCluster(d *schema.ResourceData, schemaAttPrefix string) model. //Deal with instance pool id if instancePoolID, ok := d.GetOk(schemaAttPrefix + "instance_pool_id"); ok { - cluster.InstancePoolId = instancePoolID.(string) + cluster.InstancePoolID = instancePoolID.(string) } //Deal with idempotency token diff --git a/databricks/resource_databricks_instance_pool.go b/databricks/resource_databricks_instance_pool.go index 709f7871a..cac26a0fb 100644 --- a/databricks/resource_databricks_instance_pool.go +++ b/databricks/resource_databricks_instance_pool.go @@ -174,7 +174,7 @@ func resourceInstancePoolCreate(d *schema.ResourceData, m interface{}) error { } if nodeTypeId, ok := d.GetOk("node_type_id"); ok { - instancePool.NodeTypeId = nodeTypeId.(string) + instancePool.NodeTypeID = nodeTypeId.(string) } if customTags, ok := d.GetOk("custom_tags"); ok { @@ -221,7 +221,7 @@ func resourceInstancePoolCreate(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - d.SetId(instancePoolInfo.InstancePoolId) + d.SetId(instancePoolInfo.InstancePoolID) return resourceInstancePoolRead(d, m) } @@ -270,7 +270,7 @@ func resourceInstancePoolRead(d *schema.ResourceData, m interface{}) error { } } - err = d.Set("node_type_id", instancePoolInfo.NodeTypeId) + err = d.Set("node_type_id", instancePoolInfo.NodeTypeID) if err != nil { return err } @@ -328,8 +328,8 @@ func resourceInstancePoolUpdate(d *schema.ResourceData, m interface{}) error { instancePoolInfo.MinIdleInstances = int32(d.Get("min_idle_instances").(int)) instancePoolInfo.MaxCapacity = int32(d.Get("max_capacity").(int)) instancePoolInfo.IdleInstanceAutoTerminationMinutes = int32(d.Get("idle_instance_autotermination_minutes").(int)) - instancePoolInfo.InstancePoolId = id - instancePoolInfo.NodeTypeId = d.Get("node_type_id").(string) + instancePoolInfo.InstancePoolID = id + instancePoolInfo.NodeTypeID = d.Get("node_type_id").(string) err := client.InstancePools().Update(instancePoolInfo) if err != nil { diff --git a/databricks/resource_databricks_job.go b/databricks/resource_databricks_job.go index 6f315208d..bd0f81416 100644 --- a/databricks/resource_databricks_job.go +++ b/databricks/resource_databricks_job.go @@ -454,8 +454,8 @@ func resourceJobCreate(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - log.Println(job.JobId) - d.SetId(strconv.Itoa(int(job.JobId))) + log.Println(job.JobID) + d.SetId(strconv.Itoa(int(job.JobID))) return resourceJobRead(d, m) } @@ -478,7 +478,7 @@ func resourceJobRead(d *schema.ResourceData, m interface{}) error { } if _, ok := d.GetOk("existing_cluster_id"); ok { - err := d.Set("existing_cluster_id", job.Settings.ExistingClusterId) + err := d.Set("existing_cluster_id", job.Settings.ExistingClusterID) if err != nil { return err } @@ -564,7 +564,7 @@ func resourceJobRead(d *schema.ResourceData, m interface{}) error { newClusterSettings["init_scripts"] = listOfInitScripts dockerImage := map[string]string{} - dockerImage["url"] = job.Settings.NewCluster.DockerImage.Url + dockerImage["url"] = job.Settings.NewCluster.DockerImage.URL if job.Settings.NewCluster.DockerImage.BasicAuth != nil { dockerImage["username"] = job.Settings.NewCluster.DockerImage.BasicAuth.Username dockerImage["password"] = job.Settings.NewCluster.DockerImage.BasicAuth.Password @@ -578,7 +578,7 @@ func resourceJobRead(d *schema.ResourceData, m interface{}) error { newClusterSettings["enable_elastic_disk"] = job.Settings.NewCluster.EnableElasticDisk - newClusterSettings["instance_pool_id"] = job.Settings.NewCluster.InstancePoolId + newClusterSettings["instance_pool_id"] = job.Settings.NewCluster.InstancePoolID } libraries := job.Settings.Libraries @@ -686,7 +686,7 @@ func resourceJobRead(d *schema.ResourceData, m interface{}) error { } if job.Settings.SparkJarTask != nil { - err = d.Set("jar_uri", job.Settings.SparkJarTask.JarUri) + err = d.Set("jar_uri", job.Settings.SparkJarTask.JarURI) if err != nil { return err } @@ -801,7 +801,7 @@ func resourceJobRead(d *schema.ResourceData, m interface{}) error { sched := map[string]string{} sched["quartz_cron_expression"] = job.Settings.Schedule.QuartzCronExpression - sched["timezone_id"] = job.Settings.Schedule.TimezoneId + sched["timezone_id"] = job.Settings.Schedule.TimezoneID schedSet := []map[string]string{sched} err = d.Set("schedule", schedSet) @@ -820,7 +820,7 @@ func resourceJobRead(d *schema.ResourceData, m interface{}) error { return err } - err = d.Set("job_id", job.JobId) + err = d.Set("job_id", job.JobID) if err != nil { return err } @@ -870,7 +870,7 @@ func parseSchemaToJobSettings(d *schema.ResourceData) model.JobSettings { var jobSettings model.JobSettings if existingClusterId, ok := d.GetOk("existing_cluster_id"); ok { - jobSettings.ExistingClusterId = existingClusterId.(string) + jobSettings.ExistingClusterID = existingClusterId.(string) } cluster := parseSchemaToCluster(d, "new_cluster.0.") @@ -946,7 +946,7 @@ func parseSchemaToJobSettings(d *schema.ResourceData) model.JobSettings { scheduleMap := getMapFromOneItemSet(schedule) jobSettings.Schedule = &model.CronSchedule{ QuartzCronExpression: scheduleMap["quartz_cron_expression"].(string), - TimezoneId: scheduleMap["timezone_id"].(string), + TimezoneID: scheduleMap["timezone_id"].(string), } } @@ -972,7 +972,7 @@ func parseSchemaToNotebookTask(d *schema.ResourceData) *model.NotebookTask { func parseSchemaToSparkJarTask(d *schema.ResourceData) *model.SparkJarTask { var sparkJarTask model.SparkJarTask if uri, ok := d.GetOk("jar_uri"); ok { - sparkJarTask.JarUri = uri.(string) + sparkJarTask.JarURI = uri.(string) } if cName, ok := d.GetOk("jar_main_class_name"); ok { sparkJarTask.MainClassName = cName.(string) diff --git a/databricks/resource_databricks_notebook.go b/databricks/resource_databricks_notebook.go index 6d2a98569..94d69f8ed 100644 --- a/databricks/resource_databricks_notebook.go +++ b/databricks/resource_databricks_notebook.go @@ -76,7 +76,7 @@ func resourceNotebook() *schema.Resource { ValidateFunc: validation.StringInSlice([]string{ string(model.DBC), string(model.Source), - string(model.Html), + string(model.HTML), }, false), }, "object_type": &schema.Schema{ @@ -166,7 +166,7 @@ func resourceNotebookRead(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - err = d.Set("object_id", int(notebookInfo.ObjectId)) + err = d.Set("object_id", int(notebookInfo.ObjectID)) if err != nil { return err } diff --git a/databricks/resource_databricks_secret_acl.go b/databricks/resource_databricks_secret_acl.go index 1abedcd2b..4a7530d4d 100644 --- a/databricks/resource_databricks_secret_acl.go +++ b/databricks/resource_databricks_secret_acl.go @@ -49,7 +49,7 @@ func resourceSecretAclCreate(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) scopeName := d.Get("scope").(string) principal := d.Get("principal").(string) - permission := model.AclPermission(d.Get("permission").(string)) + permission := model.ACLPermission(d.Get("permission").(string)) err := client.SecretAcls().Create(scopeName, principal, permission) if err != nil { return err diff --git a/databricks/resource_databricks_secret_acl_test.go b/databricks/resource_databricks_secret_acl_test.go index 5e43d2511..991c41158 100644 --- a/databricks/resource_databricks_secret_acl_test.go +++ b/databricks/resource_databricks_secret_acl_test.go @@ -13,7 +13,7 @@ import ( func TestAccSecretAclResource(t *testing.T) { //var secretScope model.Secre - var secretAcl model.AclItem + var secretAcl model.ACLItem // generate a random name for each tokenInfo test run, to avoid // collisions from multiple concurrent tests. // the acctest package includes many helpers such as RandStringFromCharSet @@ -66,16 +66,16 @@ func testSecretAclPreCheck(t *testing.T) { return } -func testSecretAclValues(t *testing.T, acl *model.AclItem, permission, principal string) resource.TestCheckFunc { +func testSecretAclValues(t *testing.T, acl *model.ACLItem, permission, principal string) resource.TestCheckFunc { return func(s *terraform.State) error { - assert.True(t, acl.Permission == model.AclPermissionRead) + assert.True(t, acl.Permission == model.ACLPermissionRead) assert.True(t, acl.Principal == principal) return nil } } // testAccCheckTokenResourceExists queries the API and retrieves the matching Widget. -func testSecretAclResourceExists(n string, aclItem *model.AclItem, t *testing.T) resource.TestCheckFunc { +func testSecretAclResourceExists(n string, aclItem *model.ACLItem, t *testing.T) resource.TestCheckFunc { return func(s *terraform.State) error { // find the corresponding state object rs, ok := s.RootModule().Resources[n] From 67dca86867070751aecc36aac93a75ff29a461cd Mon Sep 17 00:00:00 2001 From: Sriharsha Tikkireddy Date: Mon, 20 Apr 2020 11:45:01 -0400 Subject: [PATCH 2/5] Fixed & refactored linting issues in client/service package --- client/service/apis.go | 14 ++ client/service/client.go | 24 ++- client/service/clusters.go | 8 +- client/service/clusters_test.go | 136 ++++++++--------- client/service/commands.go | 107 ++++++------- client/service/commands_integration_test.go | 18 +-- client/service/commands_test.go | 144 +++++++++--------- client/service/dbfs.go | 14 +- client/service/dbfs_test.go | 54 +++---- client/service/groups.go | 8 +- client/service/groups_test.go | 24 +-- client/service/instance_pools.go | 15 +- client/service/instance_pools_test.go | 12 +- client/service/instance_profiles.go | 10 +- client/service/instance_profiles_test.go | 18 +-- client/service/jobs.go | 24 +-- client/service/jobs_test.go | 32 ++-- client/service/libraries.go | 25 +-- client/service/libraries_integration_test.go | 10 +- client/service/libraries_test.go | 32 ++-- client/service/main_test.go | 9 +- client/service/mask_utils.go | 7 +- client/service/notebooks.go | 12 +- client/service/notebooks_test.go | 30 ++-- client/service/secret_acls.go | 2 +- client/service/secret_scopes.go | 10 +- client/service/secrets.go | 10 +- .../secrets_scopes_acls_integration_test.go | 6 +- client/service/tokens.go | 6 +- client/service/tokens_test.go | 34 ++--- client/service/users.go | 43 +++--- client/service/users_integration_test.go | 10 +- client/service/users_test.go | 126 +++++++-------- 33 files changed, 552 insertions(+), 482 deletions(-) diff --git a/client/service/apis.go b/client/service/apis.go index dea68e311..fd67e6ddb 100644 --- a/client/service/apis.go +++ b/client/service/apis.go @@ -4,6 +4,7 @@ var scimHeaders = map[string]string{ "Content-Type": "application/scim+json", } +// DBApiClient is the client struct that contains clients for all the services available on Databricks type DBApiClient struct { config *DBApiClientConfig } @@ -20,54 +21,67 @@ func (c DBApiClient) Clusters() ClustersAPI { return ClustersAPI{Client: c} } +// Secrets returns an instance of SecretsAPI func (c DBApiClient) Secrets() SecretsAPI { return SecretsAPI{Client: c} } +// SecretScopes returns an instance of SecretScopesAPI func (c DBApiClient) SecretScopes() SecretScopesAPI { return SecretScopesAPI{Client: c} } +// SecretAcls returns an instance of SecretAclsAPI func (c DBApiClient) SecretAcls() SecretAclsAPI { return SecretAclsAPI{Client: c} } +// Tokens returns an instance of TokensAPI func (c *DBApiClient) Tokens() TokensAPI { return TokensAPI{Client: c} } +// Users returns an instance of UsersAPI func (c DBApiClient) Users() UsersAPI { return UsersAPI{Client: c} } +// Groups returns an instance of GroupsAPI func (c DBApiClient) Groups() GroupsAPI { return GroupsAPI{Client: c} } +// Notebooks returns an instance of NotebooksAPI func (c DBApiClient) Notebooks() NotebooksAPI { return NotebooksAPI{Client: c} } +// Jobs returns an instance of JobsAPI func (c DBApiClient) Jobs() JobsAPI { return JobsAPI{Client: c} } +// DBFS returns an instance of DBFSAPI func (c DBApiClient) DBFS() DBFSAPI { return DBFSAPI{Client: c} } +// Libraries returns an instance of LibrariesAPI func (c DBApiClient) Libraries() LibrariesAPI { return LibrariesAPI{Client: c} } +// InstancePools returns an instance of InstancePoolsAPI func (c DBApiClient) InstancePools() InstancePoolsAPI { return InstancePoolsAPI{Client: c} } +// InstanceProfiles returns an instance of InstanceProfilesAPI func (c DBApiClient) InstanceProfiles() InstanceProfilesAPI { return InstanceProfilesAPI{Client: c} } +// Commands returns an instance of CommandsAPI func (c DBApiClient) Commands() CommandsAPI { return CommandsAPI{Client: c} } diff --git a/client/service/client.go b/client/service/client.go index c7c9fcc43..3f826675f 100644 --- a/client/service/client.go +++ b/client/service/client.go @@ -14,13 +14,16 @@ import ( "time" ) +// CloudServiceProvider is a custom type for different types of cloud service providers type CloudServiceProvider string +// List of CloudServiceProviders Databricks is available on const ( AWS CloudServiceProvider = "AmazonWebServices" Azure CloudServiceProvider = "Azure" ) +// DBApiErrorBody is a struct for a custom api error for all the services on databrickss. type DBApiErrorBody struct { ErrorCode string `json:"error_code,omitempty"` Message string `json:"message,omitempty"` @@ -29,18 +32,22 @@ type DBApiErrorBody struct { ScimStatus string `json:"status,omitempty"` } +// DBApiError is a generic struct for an api error on databricks type DBApiError struct { ErrorBody *DBApiErrorBody StatusCode int Err error } +// Error is a interface implementation of the error interface. func (r DBApiError) Error() string { return fmt.Sprintf("status %d: err %v", r.StatusCode, r.Err) } +// AuthType is a custom type for a type of authentication allowed on Databricks type AuthType string +// List of AuthTypes supported by this go sdk. const ( BasicAuth AuthType = "BASIC" ) @@ -131,19 +138,18 @@ func (c DBApiClientConfig) getRequestURI(path string, apiVersion string) (string func onlyNBytes(j string, numBytes int64) string { if len([]byte(j)) > int(numBytes) { return string([]byte(j)[:numBytes]) - } else { - return j } + return j } func auditNonGetPayload(method string, uri string, object interface{}, mask *SecretsMask) { logStmt := struct { Method string - Uri string + URI string Payload interface{} }{ Method: method, - Uri: uri, + URI: uri, Payload: object, } jsonStr, _ := json.Marshal(Mask(logStmt)) @@ -157,10 +163,10 @@ func auditNonGetPayload(method string, uri string, object interface{}, mask *Sec func auditGetPayload(uri string, mask *SecretsMask) { logStmt := struct { Method string - Uri string + URI string }{ Method: "GET", - Uri: uri, + URI: uri, } jsonStr, _ := json.Marshal(Mask(logStmt)) if mask != nil { @@ -170,7 +176,9 @@ func auditGetPayload(uri string, mask *SecretsMask) { } } -func PerformQuery(config *DBApiClientConfig, method, path string, apiVersion string, headers map[string]string, marshalJson bool, useRawPath bool, data interface{}, secretsMask *SecretsMask) (body []byte, err error) { +// PerformQuery is a generic function that accepts a config, method, path, apiversion, headers, +// and some flags to perform query against the Databricks api +func PerformQuery(config *DBApiClientConfig, method, path string, apiVersion string, headers map[string]string, marshalJSON bool, useRawPath bool, data interface{}, secretsMask *SecretsMask) (body []byte, err error) { var requestURL string if useRawPath { requestURL = path @@ -199,7 +207,7 @@ func PerformQuery(config *DBApiClientConfig, method, path string, apiVersion str auditGetPayload(requestURL, secretsMask) } else { - if marshalJson { + if marshalJSON { bodyBytes, err := json.Marshal(data) if err != nil { return nil, err diff --git a/client/service/clusters.go b/client/service/clusters.go index c62c3fe35..53baf405f 100644 --- a/client/service/clusters.go +++ b/client/service/clusters.go @@ -9,6 +9,7 @@ import ( "time" ) +// ClustersAPI is a struct that contains the Databricks api client to perform queries type ClustersAPI struct { Client DBApiClient } @@ -26,12 +27,13 @@ func (a ClustersAPI) Create(cluster model.Cluster) (model.ClusterInfo, error) { return clusterInfo, err } -// Update edits the configuration of a cluster to match the provided attributes and size +// Edit edits the configuration of a cluster to match the provided attributes and size func (a ClustersAPI) Edit(clusterInfo model.Cluster) error { _, err := a.Client.performQuery(http.MethodPost, "/clusters/edit", "2.0", nil, clusterInfo, nil) return err } +// ListZones returns the zones info sent by the cloud service provider func (a ClustersAPI) ListZones() (model.ZonesInfo, error) { var zonesInfo model.ZonesInfo resp, err := a.Client.performQuery(http.MethodGet, "/clusters/list-zones", "2.0", nil, nil, nil) @@ -64,6 +66,7 @@ func (a ClustersAPI) Restart(clusterID string) error { return err } +// WaitForClusterRunning will block main thread and wait till cluster is in a RUNNING state func (a ClustersAPI) WaitForClusterRunning(clusterID string, sleepDurationSeconds time.Duration, timeoutDurationMinutes time.Duration) error { errChan := make(chan error, 1) go func() { @@ -93,6 +96,7 @@ func (a ClustersAPI) WaitForClusterRunning(clusterID string, sleepDurationSecond } } +// WaitForClusterTerminated will block main thread and wait till cluster is in a TERMINATED state func (a ClustersAPI) WaitForClusterTerminated(clusterID string, sleepDurationSeconds time.Duration, timeoutDurationMinutes time.Duration) error { errChan := make(chan error, 1) go func() { @@ -149,7 +153,7 @@ func (a ClustersAPI) PermanentDelete(clusterID string) error { return err } -// Read retrieves the information for a cluster given its identifier +// Get retrieves the information for a cluster given its identifier func (a ClustersAPI) Get(clusterID string) (model.ClusterInfo, error) { var clusterInfo model.ClusterInfo diff --git a/client/service/clusters_test.go b/client/service/clusters_test.go index 9f299fc39..7b85266af 100644 --- a/client/service/clusters_test.go +++ b/client/service/clusters_test.go @@ -53,14 +53,14 @@ func TestClustersAPI_Create(t *testing.T) { func TestClustersAPI_Get(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` } tests := []struct { name string response string responseStatus int args args - wantUri string + wantURI string want interface{} wantErr bool }{ @@ -135,9 +135,9 @@ func TestClustersAPI_Get(t *testing.T) { }`, responseStatus: http.StatusOK, args: args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", }, - wantUri: "/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: "/api/2.0/clusters/get?cluster_id=11203-my-cluster", want: model.ClusterInfo{ AutoScale: &model.AutoScale{ MinWorkers: 2, @@ -208,9 +208,9 @@ func TestClustersAPI_Get(t *testing.T) { response: ``, responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", }, - wantUri: "/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: "/api/2.0/clusters/get?cluster_id=11203-my-cluster", want: model.ClusterInfo{}, wantErr: true, }, @@ -218,8 +218,8 @@ func TestClustersAPI_Get(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return client.Clusters().Get(tt.args.ClusterId) + AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return client.Clusters().Get(tt.args.ClusterID) }) }) } @@ -231,7 +231,7 @@ func TestClustersAPI_List(t *testing.T) { name string response string responseStatus int - wantUri string + wantURI string want interface{} wantErr bool }{ @@ -260,7 +260,7 @@ func TestClustersAPI_List(t *testing.T) { ] }`, responseStatus: http.StatusOK, - wantUri: "/api/2.0/clusters/list?", + wantURI: "/api/2.0/clusters/list?", want: []model.ClusterInfo{ { ClusterName: "autoscaling-cluster", @@ -287,14 +287,14 @@ func TestClustersAPI_List(t *testing.T) { name: "List failure test", response: ``, responseStatus: http.StatusBadRequest, - wantUri: "/api/2.0/clusters/list?", + wantURI: "/api/2.0/clusters/list?", want: []model.ClusterInfo{}, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertRequestWithMockServer(t, nil, http.MethodGet, tt.wantUri, nil, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, nil, http.MethodGet, tt.wantURI, nil, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.Clusters().List() }) }) @@ -307,7 +307,7 @@ func TestClustersAPI_ListZones(t *testing.T) { name string response string responseStatus int - wantUri string + wantURI string want interface{} wantErr bool }{ @@ -322,7 +322,7 @@ func TestClustersAPI_ListZones(t *testing.T) { "default_zone": "us-west-2b" }`, responseStatus: http.StatusOK, - wantUri: "/api/2.0/clusters/list-zones?", + wantURI: "/api/2.0/clusters/list-zones?", want: model.ZonesInfo{ Zones: []string{"us-west-2b", @@ -336,14 +336,14 @@ func TestClustersAPI_ListZones(t *testing.T) { name: "ListZones failure test", response: ``, responseStatus: http.StatusBadRequest, - wantUri: "/api/2.0/clusters/list-zones?", + wantURI: "/api/2.0/clusters/list-zones?", want: model.ZonesInfo{}, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertRequestWithMockServer(t, nil, http.MethodGet, tt.wantUri, nil, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, nil, http.MethodGet, tt.wantURI, nil, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.Clusters().ListZones() }) }) @@ -356,7 +356,7 @@ func TestClustersAPI_ListNodeTypes(t *testing.T) { name string response string responseStatus int - wantUri string + wantURI string want interface{} wantErr bool }{ @@ -409,7 +409,7 @@ func TestClustersAPI_ListNodeTypes(t *testing.T) { ] }`, responseStatus: http.StatusOK, - wantUri: "/api/2.0/clusters/list-node-types?", + wantURI: "/api/2.0/clusters/list-node-types?", want: []model.NodeType{ { NodeTypeID: "r3.xlarge", @@ -434,14 +434,14 @@ func TestClustersAPI_ListNodeTypes(t *testing.T) { name: "ListNodeTypes failure test", response: ``, responseStatus: http.StatusBadRequest, - wantUri: "/api/2.0/clusters/list-node-types?", + wantURI: "/api/2.0/clusters/list-node-types?", want: []model.NodeType{}, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertRequestWithMockServer(t, nil, http.MethodGet, tt.wantUri, nil, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, nil, http.MethodGet, tt.wantURI, nil, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.Clusters().ListNodeTypes() }) }) @@ -450,7 +450,7 @@ func TestClustersAPI_ListNodeTypes(t *testing.T) { func TestClustersAPI_WaitForClusterRunning(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id"` + ClusterID string `json:"cluster_id"` SleepDurationSeconds time.Duration `json:"sleep_duration_seconds"` TimeoutDurationMinutes time.Duration `json:"timeout_duration_minutes"` } @@ -460,7 +460,7 @@ func TestClustersAPI_WaitForClusterRunning(t *testing.T) { responseStatus []int requestMethod []string args []interface{} - wantUri []string + wantURI []string want []model.NotebookInfo wantErr bool }{ @@ -483,12 +483,12 @@ func TestClustersAPI_WaitForClusterRunning(t *testing.T) { requestMethod: []string{http.MethodGet, http.MethodGet, http.MethodGet}, args: []interface{}{ &args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", SleepDurationSeconds: 0, TimeoutDurationMinutes: 1, }, }, - wantUri: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster"}, want: nil, @@ -513,12 +513,12 @@ func TestClustersAPI_WaitForClusterRunning(t *testing.T) { requestMethod: []string{http.MethodGet, http.MethodGet, http.MethodGet}, args: []interface{}{ &args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", SleepDurationSeconds: 0, TimeoutDurationMinutes: 1, }, }, - wantUri: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster"}, want: nil, @@ -543,12 +543,12 @@ func TestClustersAPI_WaitForClusterRunning(t *testing.T) { requestMethod: []string{http.MethodGet, http.MethodGet, http.MethodGet}, args: []interface{}{ &args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", SleepDurationSeconds: 0, TimeoutDurationMinutes: 1, }, }, - wantUri: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster"}, want: nil, @@ -573,12 +573,12 @@ func TestClustersAPI_WaitForClusterRunning(t *testing.T) { requestMethod: []string{http.MethodGet, http.MethodGet, http.MethodGet}, args: []interface{}{ &args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", SleepDurationSeconds: 1, TimeoutDurationMinutes: 0, }, }, - wantUri: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster"}, want: nil, @@ -587,8 +587,8 @@ func TestClustersAPI_WaitForClusterRunning(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantUri, []interface{}{&args{}}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Clusters().WaitForClusterRunning(tt.args[0].(*args).ClusterId, tt.args[0].(*args).SleepDurationSeconds, tt.args[0].(*args).TimeoutDurationMinutes) + AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantURI, []interface{}{&args{}}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return nil, client.Clusters().WaitForClusterRunning(tt.args[0].(*args).ClusterID, tt.args[0].(*args).SleepDurationSeconds, tt.args[0].(*args).TimeoutDurationMinutes) }) }) } @@ -596,7 +596,7 @@ func TestClustersAPI_WaitForClusterRunning(t *testing.T) { func TestClustersAPI_WaitForClusterTerminated(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id"` + ClusterID string `json:"cluster_id"` SleepDurationSeconds time.Duration `json:"sleep_duration_seconds"` TimeoutDurationMinutes time.Duration `json:"timeout_duration_minutes"` } @@ -606,7 +606,7 @@ func TestClustersAPI_WaitForClusterTerminated(t *testing.T) { responseStatus []int requestMethod []string args []interface{} - wantUri []string + wantURI []string want []model.NotebookInfo wantErr bool }{ @@ -629,12 +629,12 @@ func TestClustersAPI_WaitForClusterTerminated(t *testing.T) { requestMethod: []string{http.MethodGet, http.MethodGet, http.MethodGet}, args: []interface{}{ &args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", SleepDurationSeconds: 0, TimeoutDurationMinutes: 1, }, }, - wantUri: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster"}, want: nil, @@ -659,12 +659,12 @@ func TestClustersAPI_WaitForClusterTerminated(t *testing.T) { requestMethod: []string{http.MethodGet, http.MethodGet, http.MethodGet}, args: []interface{}{ &args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", SleepDurationSeconds: 0, TimeoutDurationMinutes: 1, }, }, - wantUri: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster"}, want: nil, @@ -689,12 +689,12 @@ func TestClustersAPI_WaitForClusterTerminated(t *testing.T) { requestMethod: []string{http.MethodGet, http.MethodGet, http.MethodGet}, args: []interface{}{ &args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", SleepDurationSeconds: 0, TimeoutDurationMinutes: 1, }, }, - wantUri: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster"}, want: nil, @@ -719,12 +719,12 @@ func TestClustersAPI_WaitForClusterTerminated(t *testing.T) { requestMethod: []string{http.MethodGet, http.MethodGet, http.MethodGet}, args: []interface{}{ &args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", SleepDurationSeconds: 1, TimeoutDurationMinutes: 0, }, }, - wantUri: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", + wantURI: []string{"/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster", "/api/2.0/clusters/get?cluster_id=11203-my-cluster"}, want: nil, @@ -733,8 +733,8 @@ func TestClustersAPI_WaitForClusterTerminated(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantUri, []interface{}{&args{}}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Clusters().WaitForClusterTerminated(tt.args[0].(*args).ClusterId, tt.args[0].(*args).SleepDurationSeconds, tt.args[0].(*args).TimeoutDurationMinutes) + AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantURI, []interface{}{&args{}}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return nil, client.Clusters().WaitForClusterTerminated(tt.args[0].(*args).ClusterID, tt.args[0].(*args).SleepDurationSeconds, tt.args[0].(*args).TimeoutDurationMinutes) }) }) } @@ -786,7 +786,7 @@ func TestClustersAPI_Edit(t *testing.T) { func TestClustersAPI_Start(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty"` } tests := []struct { @@ -802,7 +802,7 @@ func TestClustersAPI_Start(t *testing.T) { response: ``, responseStatus: http.StatusOK, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: false, @@ -812,7 +812,7 @@ func TestClustersAPI_Start(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: true, @@ -822,7 +822,7 @@ func TestClustersAPI_Start(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/clusters/start", &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Clusters().Start(tt.args.ClusterId) + return nil, client.Clusters().Start(tt.args.ClusterID) }) }) } @@ -830,7 +830,7 @@ func TestClustersAPI_Start(t *testing.T) { func TestClustersAPI_Restart(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty"` } tests := []struct { @@ -846,7 +846,7 @@ func TestClustersAPI_Restart(t *testing.T) { response: ``, responseStatus: http.StatusOK, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: false, @@ -856,7 +856,7 @@ func TestClustersAPI_Restart(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: true, @@ -866,7 +866,7 @@ func TestClustersAPI_Restart(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/clusters/restart", &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Clusters().Restart(tt.args.ClusterId) + return nil, client.Clusters().Restart(tt.args.ClusterID) }) }) } @@ -874,7 +874,7 @@ func TestClustersAPI_Restart(t *testing.T) { func TestClustersAPI_Pin(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty"` } tests := []struct { @@ -890,7 +890,7 @@ func TestClustersAPI_Pin(t *testing.T) { response: ``, responseStatus: http.StatusOK, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: false, @@ -900,7 +900,7 @@ func TestClustersAPI_Pin(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: true, @@ -910,7 +910,7 @@ func TestClustersAPI_Pin(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/clusters/pin", &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Clusters().Pin(tt.args.ClusterId) + return nil, client.Clusters().Pin(tt.args.ClusterID) }) }) } @@ -918,7 +918,7 @@ func TestClustersAPI_Pin(t *testing.T) { func TestClustersAPI_Unpin(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty"` } tests := []struct { @@ -934,7 +934,7 @@ func TestClustersAPI_Unpin(t *testing.T) { response: ``, responseStatus: http.StatusOK, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: false, @@ -944,7 +944,7 @@ func TestClustersAPI_Unpin(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: true, @@ -954,7 +954,7 @@ func TestClustersAPI_Unpin(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/clusters/unpin", &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Clusters().Unpin(tt.args.ClusterId) + return nil, client.Clusters().Unpin(tt.args.ClusterID) }) }) } @@ -962,7 +962,7 @@ func TestClustersAPI_Unpin(t *testing.T) { func TestClustersAPI_Delete(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty"` } tests := []struct { @@ -978,7 +978,7 @@ func TestClustersAPI_Delete(t *testing.T) { response: ``, responseStatus: http.StatusOK, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: false, @@ -988,7 +988,7 @@ func TestClustersAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: true, @@ -998,7 +998,7 @@ func TestClustersAPI_Delete(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/clusters/delete", &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Clusters().Delete(tt.args.ClusterId) + return nil, client.Clusters().Delete(tt.args.ClusterID) }) }) } @@ -1006,7 +1006,7 @@ func TestClustersAPI_Delete(t *testing.T) { func TestClustersAPI_PermanentDelete(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty"` } tests := []struct { @@ -1022,7 +1022,7 @@ func TestClustersAPI_PermanentDelete(t *testing.T) { response: ``, responseStatus: http.StatusOK, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: false, @@ -1032,7 +1032,7 @@ func TestClustersAPI_PermanentDelete(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, want: nil, wantErr: true, @@ -1042,7 +1042,7 @@ func TestClustersAPI_PermanentDelete(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/clusters/permanent-delete", &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Clusters().PermanentDelete(tt.args.ClusterId) + return nil, client.Clusters().PermanentDelete(tt.args.ClusterID) }) }) } diff --git a/client/service/commands.go b/client/service/commands.go index 92daf4ca5..c22b61c0d 100644 --- a/client/service/commands.go +++ b/client/service/commands.go @@ -10,70 +10,71 @@ import ( "time" ) -// TokensAPI exposes the Secrets API +// CommandsAPI exposes the Context & Commands API type CommandsAPI struct { Client DBApiClient } -func (a CommandsAPI) Execute(clusterId, langauge, commandStr string) (model.Command, error) { +// Execute creates a spark context and executes a command and then closes context +func (a CommandsAPI) Execute(clusterID, langauge, commandStr string) (model.Command, error) { var resp model.Command - context, err := a.createContext(langauge, clusterId) + context, err := a.createContext(langauge, clusterID) if err != nil { return resp, err } - err = a.waitForContextReady(context, clusterId, 1, 10) + err = a.waitForContextReady(context, clusterID, 1, 10) if err != nil { return resp, err } - commandId, err := a.createCommand(context, clusterId, langauge, commandStr) + commandID, err := a.createCommand(context, clusterID, langauge, commandStr) if err != nil { return resp, err } - err = a.waitForCommandFinished(commandId, context, clusterId, 5, 10) + err = a.waitForCommandFinished(commandID, context, clusterID, 5, 10) if err != nil { return resp, err } - command, err := a.getCommand(commandId, context, clusterId) + command, err := a.getCommand(commandID, context, clusterID) if err != nil { return resp, err } - err = a.deleteContext(context, clusterId) + err = a.deleteContext(context, clusterID) return command, err } -func (a CommandsAPI) createCommand(contextId, clusterId, language, commandStr string) (string, error) { +func (a CommandsAPI) createCommand(contextID, clusterID, language, commandStr string) (string, error) { var command struct { - Id string `json:"id,omitempty"` + ID string `json:"id,omitempty"` } commandRequest := struct { Language string `json:"language,omitempty"` - ClusterId string `json:"clusterId,omitempty"` - ContextId string `json:"contextId,omitempty"` + ClusterID string `json:"clusterId,omitempty"` + ContextID string `json:"contextId,omitempty"` Command string `json:"command,omitempty"` }{ Language: language, - ClusterId: clusterId, - ContextId: contextId, + ClusterID: clusterID, + ContextID: contextID, Command: commandStr, } resp, err := a.Client.performQuery(http.MethodPost, "/commands/execute", "1.2", nil, commandRequest, nil) if err != nil { - return command.Id, err + return command.ID, err } err = json.Unmarshal(resp, &command) - return command.Id, err + return command.ID, err } -func (a CommandsAPI) getCommand(commandId, contextId, clusterId string) (model.Command, error) { +func (a CommandsAPI) getCommand(commandID, contextID, clusterID string) (model.Command, error) { var commandResp model.Command contextGetRequest := 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 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, + CommandID: commandID, + ContextID: contextID, + ClusterID: clusterID, } resp, err := a.Client.performQuery(http.MethodGet, "/commands/status", "1.2", nil, contextGetRequest, nil) if err != nil { @@ -83,11 +84,11 @@ func (a CommandsAPI) getCommand(commandId, contextId, clusterId string) (model.C return commandResp, err } -func (a CommandsAPI) waitForCommandFinished(commandId, contextId, clusterID string, sleepDurationSeconds time.Duration, timeoutDurationMinutes time.Duration) error { +func (a CommandsAPI) waitForCommandFinished(commandID, contextID, clusterID string, sleepDurationSeconds time.Duration, timeoutDurationMinutes time.Duration) error { errChan := make(chan error, 1) go func() { for { - commandInfo, err := a.getCommand(commandId, contextId, clusterID) + commandInfo, err := a.getCommand(commandID, contextID, clusterID) if err != nil { errChan <- err return @@ -96,7 +97,7 @@ func (a CommandsAPI) waitForCommandFinished(commandId, contextId, clusterID stri errChan <- nil return } else if commandInfo.Status == "Cancelling" || commandInfo.Status == "Cancelled" || commandInfo.Status == "Error" { - errChan <- errors.New(fmt.Sprintf("Context is in a failure state: %s.", commandInfo.Status)) + errChan <- fmt.Errorf("context is in a failure state: %s", commandInfo.Status) return } log.Println(fmt.Sprintf("Waiting for command to finish, current state is: %s.", commandInfo.Status)) @@ -111,37 +112,37 @@ func (a CommandsAPI) waitForCommandFinished(commandId, contextId, clusterID stri } } -func (a CommandsAPI) deleteCommand(commandId, contextId, clusterId string) error { +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 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, + 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 { +func (a CommandsAPI) deleteContext(contextID, clusterID string) error { contextDeleteRequest := struct { - ContextId string `json:"contextId,omitempty" url:"contextId,omitempty"` - ClusterId string `json:"clusterId,omitempty" url:"clusterId,omitempty"` + ContextID string `json:"contextId,omitempty" url:"contextId,omitempty"` + ClusterID string `json:"clusterId,omitempty" url:"clusterId,omitempty"` }{ - ContextId: contextId, - ClusterId: clusterId, + ContextID: contextID, + ClusterID: clusterID, } _, err := a.Client.performQuery(http.MethodPost, "/contexts/destroy", "1.2", nil, contextDeleteRequest, nil) return err } -func (a CommandsAPI) waitForContextReady(contextId, clusterID string, sleepDurationSeconds time.Duration, timeoutDurationMinutes time.Duration) error { +func (a CommandsAPI) waitForContextReady(contextID, clusterID string, sleepDurationSeconds time.Duration, timeoutDurationMinutes time.Duration) error { errChan := make(chan error, 1) go func() { for { - status, err := a.getContext(contextId, clusterID) + status, err := a.getContext(contextID, clusterID) if err != nil { errChan <- err return @@ -150,7 +151,7 @@ func (a CommandsAPI) waitForContextReady(contextId, clusterID string, sleepDurat errChan <- nil return } else if status == "Error" { - errChan <- errors.New("Context is in a errored state.") + errChan <- errors.New("context is in a errored state") return } log.Println("Waiting for context to go to running, current state is pending.") @@ -165,17 +166,17 @@ func (a CommandsAPI) waitForContextReady(contextId, clusterID string, sleepDurat } } -func (a CommandsAPI) getContext(contextId, clusterId string) (string, error) { +func (a CommandsAPI) getContext(contextID, clusterID string) (string, error) { var contextStatus struct { - Id string `json:"id,omitempty"` + ID string `json:"id,omitempty"` Status string `json:"status,omitempty"` } contextGetRequest := struct { - ContextId string `json:"contextId,omitempty" url:"contextId,omitempty"` - ClusterId string `json:"clusterId,omitempty" url:"clusterId,omitempty"` + ContextID string `json:"contextId,omitempty" url:"contextId,omitempty"` + ClusterID string `json:"clusterId,omitempty" url:"clusterId,omitempty"` }{ - ContextId: contextId, - ClusterId: clusterId, + ContextID: contextID, + ClusterID: clusterID, } resp, err := a.Client.performQuery(http.MethodGet, "/contexts/status", "1.2", nil, contextGetRequest, nil) if err != nil { @@ -185,22 +186,22 @@ func (a CommandsAPI) getContext(contextId, clusterId string) (string, error) { return contextStatus.Status, err } -func (a CommandsAPI) createContext(language, clusterId string) (string, error) { +func (a CommandsAPI) createContext(language, clusterID string) (string, error) { var context struct { - Id string `json:"id,omitempty"` + ID string `json:"id,omitempty"` } contextRequest := struct { Language string `json:"language,omitempty"` - ClusterId string `json:"clusterId,omitempty"` + ClusterID string `json:"clusterId,omitempty"` }{ Language: language, - ClusterId: clusterId, + ClusterID: clusterID, } resp, err := a.Client.performQuery(http.MethodPost, "/contexts/create", "1.2", nil, contextRequest, nil) if err != nil { - return context.Id, err + return context.ID, err } err = json.Unmarshal(resp, &context) - return context.Id, err + return context.ID, err } diff --git a/client/service/commands_integration_test.go b/client/service/commands_integration_test.go index 63b0e756b..de6b70fff 100644 --- a/client/service/commands_integration_test.go +++ b/client/service/commands_integration_test.go @@ -38,35 +38,35 @@ func TestContext(t *testing.T) { assert.NoError(t, err, err) }() - clusterId := clusterInfo.ClusterID + clusterID := clusterInfo.ClusterID - err = client.Clusters().WaitForClusterRunning(clusterId, 10, 20) + err = client.Clusters().WaitForClusterRunning(clusterID, 10, 20) assert.NoError(t, err, err) - context, err := client.Commands().createContext("python", clusterId) + context, err := client.Commands().createContext("python", clusterID) assert.NoError(t, err, err) t.Log(context) - err = client.Commands().waitForContextReady(context, clusterId, 1, 1) + err = client.Commands().waitForContextReady(context, clusterID, 1, 1) assert.NoError(t, err, err) - status, err := client.Commands().getContext(context, clusterId) + status, err := client.Commands().getContext(context, clusterID) assert.NoError(t, err, err) assert.True(t, status == "Running") t.Log(status) - commandId, err := client.Commands().createCommand(context, clusterId, "python", "print('hello world')") + commandID, err := client.Commands().createCommand(context, clusterID, "python", "print('hello world')") assert.NoError(t, err, err) - err = client.Commands().waitForCommandFinished(commandId, context, clusterId, 5, 20) + err = client.Commands().waitForCommandFinished(commandID, context, clusterID, 5, 20) assert.NoError(t, err, err) - resp, err := client.Commands().getCommand(commandId, context, clusterId) + resp, err := client.Commands().getCommand(commandID, context, clusterID) assert.NoError(t, err, err) assert.NotNil(t, resp.Results.Data) // Testing the public api Execute - command, err := client.Commands().Execute(clusterId, "python", "print('hello world')") + command, err := client.Commands().Execute(clusterID, "python", "print('hello world')") assert.NoError(t, err, err) assert.NotNil(t, command.Results.Data) } diff --git a/client/service/commands_test.go b/client/service/commands_test.go index 25446f680..df9ca22e9 100644 --- a/client/service/commands_test.go +++ b/client/service/commands_test.go @@ -9,21 +9,21 @@ import ( func TestCommandsAPI_Execute(t *testing.T) { type context struct { Language string `json:"language,omitempty"` - ClusterId string `json:"clusterId,omitempty"` + ClusterID string `json:"clusterId,omitempty"` } type command struct { Language string `json:"language,omitempty"` - ClusterId string `json:"clusterId,omitempty"` - ContextId string `json:"contextId,omitempty"` + ClusterID string `json:"clusterId,omitempty"` + ContextID string `json:"contextId,omitempty"` Command string `json:"command,omitempty"` } type contextDelete struct { - ContextId string `json:"contextId,omitempty" url:"contextId,omitempty"` - ClusterId string `json:"clusterId,omitempty" url:"clusterId,omitempty"` + ContextID string `json:"contextId,omitempty" url:"contextId,omitempty"` + ClusterID string `json:"clusterId,omitempty" url:"clusterId,omitempty"` } type params struct { - ClusterId string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` Language string `json:"language,omitempty" url:"language,omitempty"` CommandStr string `json:"command_str,omitempty" url:"command_str,omitempty"` } @@ -35,14 +35,14 @@ func TestCommandsAPI_Execute(t *testing.T) { requestMethod []string postStructExpect []interface{} args []interface{} - wantUri []string + wantURI []string want interface{} wantErr bool }{ { name: "Execute test", params: params{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Language: "python", CommandStr: `print("hello world")`, }, @@ -74,20 +74,20 @@ func TestCommandsAPI_Execute(t *testing.T) { args: []interface{}{ &context{ Language: "python", - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, nil, &command{ Language: "python", - ClusterId: "my-cluster-id", - ContextId: "my-context-id", + ClusterID: "my-cluster-id", + ContextID: "my-context-id", Command: `print("hello world")`, }, nil, nil, &contextDelete{ - ContextId: "my-context-id", - ClusterId: "my-cluster-id", + ContextID: "my-context-id", + ClusterID: "my-cluster-id", }, }, postStructExpect: []interface{}{ @@ -98,7 +98,7 @@ func TestCommandsAPI_Execute(t *testing.T) { nil, &contextDelete{}, }, - wantUri: []string{"/api/1.2/contexts/create", + wantURI: []string{"/api/1.2/contexts/create", "/api/1.2/contexts/status?clusterId=my-cluster-id&contextId=my-context-id", "/api/1.2/commands/execute", "/api/1.2/commands/status?clusterId=my-cluster-id&commandId=my-command-id&contextId=my-context-id", @@ -116,7 +116,7 @@ func TestCommandsAPI_Execute(t *testing.T) { { name: "Execute context failure test", params: params{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Language: "python", CommandStr: `print("hello world")`, }, @@ -148,20 +148,20 @@ func TestCommandsAPI_Execute(t *testing.T) { args: []interface{}{ &context{ Language: "python", - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, nil, &command{ Language: "python", - ClusterId: "my-cluster-id", - ContextId: "my-context-id", + ClusterID: "my-cluster-id", + ContextID: "my-context-id", Command: `print("hello world")`, }, nil, nil, &contextDelete{ - ContextId: "my-context-id", - ClusterId: "my-cluster-id", + ContextID: "my-context-id", + ClusterID: "my-cluster-id", }, }, postStructExpect: []interface{}{ @@ -172,7 +172,7 @@ func TestCommandsAPI_Execute(t *testing.T) { nil, &contextDelete{}, }, - wantUri: []string{"/api/1.2/contexts/create", + wantURI: []string{"/api/1.2/contexts/create", "/api/1.2/contexts/status?clusterId=my-cluster-id&contextId=my-context-id", "/api/1.2/commands/execute", "/api/1.2/commands/status?clusterId=my-cluster-id&commandId=my-command-id&contextId=my-context-id", @@ -184,7 +184,7 @@ func TestCommandsAPI_Execute(t *testing.T) { { name: "Execute context status failure test", params: params{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Language: "python", CommandStr: `print("hello world")`, }, @@ -216,20 +216,20 @@ func TestCommandsAPI_Execute(t *testing.T) { args: []interface{}{ &context{ Language: "python", - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, nil, &command{ Language: "python", - ClusterId: "my-cluster-id", - ContextId: "my-context-id", + ClusterID: "my-cluster-id", + ContextID: "my-context-id", Command: `print("hello world")`, }, nil, nil, &contextDelete{ - ContextId: "my-context-id", - ClusterId: "my-cluster-id", + ContextID: "my-context-id", + ClusterID: "my-cluster-id", }, }, postStructExpect: []interface{}{ @@ -240,7 +240,7 @@ func TestCommandsAPI_Execute(t *testing.T) { nil, &contextDelete{}, }, - wantUri: []string{"/api/1.2/contexts/create", + wantURI: []string{"/api/1.2/contexts/create", "/api/1.2/contexts/status?clusterId=my-cluster-id&contextId=my-context-id", "/api/1.2/commands/execute", "/api/1.2/commands/status?clusterId=my-cluster-id&commandId=my-command-id&contextId=my-context-id", @@ -252,7 +252,7 @@ func TestCommandsAPI_Execute(t *testing.T) { { name: "Execute command create failure test", params: params{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Language: "python", CommandStr: `print("hello world")`, }, @@ -284,20 +284,20 @@ func TestCommandsAPI_Execute(t *testing.T) { args: []interface{}{ &context{ Language: "python", - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, nil, &command{ Language: "python", - ClusterId: "my-cluster-id", - ContextId: "my-context-id", + ClusterID: "my-cluster-id", + ContextID: "my-context-id", Command: `print("hello world")`, }, nil, nil, &contextDelete{ - ContextId: "my-context-id", - ClusterId: "my-cluster-id", + ContextID: "my-context-id", + ClusterID: "my-cluster-id", }, }, postStructExpect: []interface{}{ @@ -308,7 +308,7 @@ func TestCommandsAPI_Execute(t *testing.T) { nil, &contextDelete{}, }, - wantUri: []string{"/api/1.2/contexts/create", + wantURI: []string{"/api/1.2/contexts/create", "/api/1.2/contexts/status?clusterId=my-cluster-id&contextId=my-context-id", "/api/1.2/commands/execute", "/api/1.2/commands/status?clusterId=my-cluster-id&commandId=my-command-id&contextId=my-context-id", @@ -320,7 +320,7 @@ func TestCommandsAPI_Execute(t *testing.T) { { name: "Execute command status failure test", params: params{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Language: "python", CommandStr: `print("hello world")`, }, @@ -352,20 +352,20 @@ func TestCommandsAPI_Execute(t *testing.T) { args: []interface{}{ &context{ Language: "python", - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, nil, &command{ Language: "python", - ClusterId: "my-cluster-id", - ContextId: "my-context-id", + ClusterID: "my-cluster-id", + ContextID: "my-context-id", Command: `print("hello world")`, }, nil, nil, &contextDelete{ - ContextId: "my-context-id", - ClusterId: "my-cluster-id", + ContextID: "my-context-id", + ClusterID: "my-cluster-id", }, }, postStructExpect: []interface{}{ @@ -376,7 +376,7 @@ func TestCommandsAPI_Execute(t *testing.T) { nil, &contextDelete{}, }, - wantUri: []string{"/api/1.2/contexts/create", + wantURI: []string{"/api/1.2/contexts/create", "/api/1.2/contexts/status?clusterId=my-cluster-id&contextId=my-context-id", "/api/1.2/commands/execute", "/api/1.2/commands/status?clusterId=my-cluster-id&commandId=my-command-id&contextId=my-context-id", @@ -388,7 +388,7 @@ func TestCommandsAPI_Execute(t *testing.T) { { name: "Execute command results fetch failure test", params: params{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Language: "python", CommandStr: `print("hello world")`, }, @@ -420,20 +420,20 @@ func TestCommandsAPI_Execute(t *testing.T) { args: []interface{}{ &context{ Language: "python", - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, nil, &command{ Language: "python", - ClusterId: "my-cluster-id", - ContextId: "my-context-id", + ClusterID: "my-cluster-id", + ContextID: "my-context-id", Command: `print("hello world")`, }, nil, nil, &contextDelete{ - ContextId: "my-context-id", - ClusterId: "my-cluster-id", + ContextID: "my-context-id", + ClusterID: "my-cluster-id", }, }, postStructExpect: []interface{}{ @@ -444,7 +444,7 @@ func TestCommandsAPI_Execute(t *testing.T) { nil, &contextDelete{}, }, - wantUri: []string{"/api/1.2/contexts/create", + wantURI: []string{"/api/1.2/contexts/create", "/api/1.2/contexts/status?clusterId=my-cluster-id&contextId=my-context-id", "/api/1.2/commands/execute", "/api/1.2/commands/status?clusterId=my-cluster-id&commandId=my-command-id&contextId=my-context-id", @@ -456,7 +456,7 @@ func TestCommandsAPI_Execute(t *testing.T) { { name: "Execute context close failure test", params: params{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Language: "python", CommandStr: `print("hello world")`, }, @@ -488,20 +488,20 @@ func TestCommandsAPI_Execute(t *testing.T) { args: []interface{}{ &context{ Language: "python", - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, nil, &command{ Language: "python", - ClusterId: "my-cluster-id", - ContextId: "my-context-id", + ClusterID: "my-cluster-id", + ContextID: "my-context-id", Command: `print("hello world")`, }, nil, nil, &contextDelete{ - ContextId: "my-context-id", - ClusterId: "my-cluster-id", + ContextID: "my-context-id", + ClusterID: "my-cluster-id", }, }, postStructExpect: []interface{}{ @@ -512,7 +512,7 @@ func TestCommandsAPI_Execute(t *testing.T) { nil, &contextDelete{}, }, - wantUri: []string{"/api/1.2/contexts/create", + wantURI: []string{"/api/1.2/contexts/create", "/api/1.2/contexts/status?clusterId=my-cluster-id&contextId=my-context-id", "/api/1.2/commands/execute", "/api/1.2/commands/status?clusterId=my-cluster-id&commandId=my-command-id&contextId=my-context-id", @@ -530,7 +530,7 @@ func TestCommandsAPI_Execute(t *testing.T) { { name: "Execute context invalid state failure test", params: params{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Language: "python", CommandStr: `print("hello world")`, }, @@ -562,20 +562,20 @@ func TestCommandsAPI_Execute(t *testing.T) { args: []interface{}{ &context{ Language: "python", - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, nil, &command{ Language: "python", - ClusterId: "my-cluster-id", - ContextId: "my-context-id", + ClusterID: "my-cluster-id", + ContextID: "my-context-id", Command: `print("hello world")`, }, nil, nil, &contextDelete{ - ContextId: "my-context-id", - ClusterId: "my-cluster-id", + ContextID: "my-context-id", + ClusterID: "my-cluster-id", }, }, postStructExpect: []interface{}{ @@ -586,7 +586,7 @@ func TestCommandsAPI_Execute(t *testing.T) { nil, &contextDelete{}, }, - wantUri: []string{"/api/1.2/contexts/create", + wantURI: []string{"/api/1.2/contexts/create", "/api/1.2/contexts/status?clusterId=my-cluster-id&contextId=my-context-id", "/api/1.2/commands/execute", "/api/1.2/commands/status?clusterId=my-cluster-id&commandId=my-command-id&contextId=my-context-id", @@ -598,7 +598,7 @@ func TestCommandsAPI_Execute(t *testing.T) { { name: "Execute command invalid state failure test", params: params{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Language: "python", CommandStr: `print("hello world")`, }, @@ -630,20 +630,20 @@ func TestCommandsAPI_Execute(t *testing.T) { args: []interface{}{ &context{ Language: "python", - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", }, nil, &command{ Language: "python", - ClusterId: "my-cluster-id", - ContextId: "my-context-id", + ClusterID: "my-cluster-id", + ContextID: "my-context-id", Command: `print("hello world")`, }, nil, nil, &contextDelete{ - ContextId: "my-context-id", - ClusterId: "my-cluster-id", + ContextID: "my-context-id", + ClusterID: "my-cluster-id", }, }, postStructExpect: []interface{}{ @@ -654,7 +654,7 @@ func TestCommandsAPI_Execute(t *testing.T) { nil, &contextDelete{}, }, - wantUri: []string{"/api/1.2/contexts/create", + wantURI: []string{"/api/1.2/contexts/create", "/api/1.2/contexts/status?clusterId=my-cluster-id&contextId=my-context-id", "/api/1.2/commands/execute", "/api/1.2/commands/status?clusterId=my-cluster-id&commandId=my-command-id&contextId=my-context-id", @@ -666,8 +666,8 @@ func TestCommandsAPI_Execute(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantUri, tt.postStructExpect, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return client.Commands().Execute(tt.params.ClusterId, tt.params.Language, tt.params.CommandStr) + AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantURI, tt.postStructExpect, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return client.Commands().Execute(tt.params.ClusterID, tt.params.Language, tt.params.CommandStr) }) }) } diff --git a/client/service/dbfs.go b/client/service/dbfs.go index d5b9587a0..8c69b84ea 100644 --- a/client/service/dbfs.go +++ b/client/service/dbfs.go @@ -8,11 +8,12 @@ import ( "net/http" ) -// TokensAPI exposes the Secrets API +// DBFSAPI exposes the DBFS API type DBFSAPI struct { Client DBApiClient } +// Create creates a file in DBFS given data string in base64 func (a DBFSAPI) Create(path string, overwrite bool, data string) (err error) { byteArr, err := base64.StdEncoding.DecodeString(data) if err != nil { @@ -36,6 +37,7 @@ func (a DBFSAPI) Create(path string, overwrite bool, data string) (err error) { return err } +// Read returns the contents of a file in DBFS as a base64 encoded string func (a DBFSAPI) Read(path string) (string, error) { var bytesFetched []byte fetchLoop := true @@ -57,6 +59,7 @@ func (a DBFSAPI) Read(path string) (string, error) { return resp, nil } +// Copy copies a file given a source location and a target location and a provided client for source location func (a DBFSAPI) Copy(src string, tgt string, client *DBApiClient, overwrite bool) error { handle, err := a.createHandle(tgt, overwrite) if err != nil { @@ -95,6 +98,7 @@ func (a DBFSAPI) Copy(src string, tgt string, client *DBApiClient, overwrite boo return err } +// Move moves the file between DBFS locations via DBFS api func (a DBFSAPI) Move(src string, tgt string) error { moveRequest := struct { SourcePath string `json:"source_path,omitempty" url:"source_path,omitempty"` @@ -107,6 +111,7 @@ func (a DBFSAPI) Move(src string, tgt string) error { return err } +// Delete deletes a file in DBFS via API func (a DBFSAPI) Delete(path string, recursive bool) error { deleteRequest := struct { Path string `json:"path,omitempty" url:"path,omitempty"` @@ -120,6 +125,7 @@ func (a DBFSAPI) Delete(path string, recursive bool) error { return err } +// ReadString reads a "block" of data in DBFS given a offset and length as a base64 encoded string func (a DBFSAPI) ReadString(path string, offset, length int64) (int64, string, error) { var readBytes struct { BytesRead int64 `json:"bytes_read,omitempty" url:"bytes_read,omitempty"` @@ -152,6 +158,7 @@ func (a DBFSAPI) read(path string, offset, length int64) (int64, []byte, error) return bytesRead, dataBytes, err } +// Status returns the status of a file in DBFS func (a DBFSAPI) Status(path string) (model.FileInfo, error) { var fileInfo model.FileInfo statusRequest := struct { @@ -167,6 +174,7 @@ func (a DBFSAPI) Status(path string) (model.FileInfo, error) { return fileInfo, err } +// 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 { var paths []model.FileInfo @@ -175,9 +183,8 @@ func (a DBFSAPI) List(path string, recursive bool) ([]model.FileInfo, error) { return nil, err } return paths, err - } else { - return a.list(path) } + return a.list(path) } func (a DBFSAPI) recursiveAddPaths(path string, pathList *[]model.FileInfo) error { @@ -216,6 +223,7 @@ func (a DBFSAPI) list(path string) ([]model.FileInfo, error) { return dbfsList.Files, err } +// Mkdirs makes the directories in DBFS include the parent paths func (a DBFSAPI) Mkdirs(path string) error { mkDirsRequest := struct { Path string `json:"path,omitempty" url:"path,omitempty"` diff --git a/client/service/dbfs_test.go b/client/service/dbfs_test.go index 5f95b0a8d..fe601cc0f 100644 --- a/client/service/dbfs_test.go +++ b/client/service/dbfs_test.go @@ -38,7 +38,7 @@ func TestDBFSAPI_Create(t *testing.T) { requestMethod []string postStructExpect []interface{} args []interface{} - wantUri []string + wantURI []string want interface{} wantErr bool }{ @@ -74,7 +74,7 @@ func TestDBFSAPI_Create(t *testing.T) { &block{}, &close{}, }, - wantUri: []string{"/api/2.0/dbfs/create", "/api/2.0/dbfs/add-block", "/api/2.0/dbfs/close"}, + wantURI: []string{"/api/2.0/dbfs/create", "/api/2.0/dbfs/add-block", "/api/2.0/dbfs/close"}, want: nil, wantErr: false, }, @@ -92,7 +92,7 @@ func TestDBFSAPI_Create(t *testing.T) { requestMethod: []string{}, args: []interface{}{}, postStructExpect: []interface{}{}, - wantUri: []string{}, + wantURI: []string{}, want: nil, wantErr: true, }, @@ -119,7 +119,7 @@ func TestDBFSAPI_Create(t *testing.T) { postStructExpect: []interface{}{ &handle{}, }, - wantUri: []string{"/api/2.0/dbfs/create"}, + wantURI: []string{"/api/2.0/dbfs/create"}, want: nil, wantErr: true, }, @@ -151,7 +151,7 @@ func TestDBFSAPI_Create(t *testing.T) { &handle{}, &block{}, }, - wantUri: []string{"/api/2.0/dbfs/create", "/api/2.0/dbfs/add-block"}, + wantURI: []string{"/api/2.0/dbfs/create", "/api/2.0/dbfs/add-block"}, want: nil, wantErr: true, }, @@ -187,14 +187,14 @@ func TestDBFSAPI_Create(t *testing.T) { &block{}, &close{}, }, - wantUri: []string{"/api/2.0/dbfs/create", "/api/2.0/dbfs/add-block", "/api/2.0/dbfs/close"}, + wantURI: []string{"/api/2.0/dbfs/create", "/api/2.0/dbfs/add-block", "/api/2.0/dbfs/close"}, want: nil, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantUri, tt.postStructExpect, tt.response, tt.responseStatus, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantURI, tt.postStructExpect, tt.response, tt.responseStatus, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { return nil, client.DBFS().Create(tt.params.Path, tt.params.Overwrite, tt.params.Data) }) }) @@ -232,7 +232,7 @@ func TestDBFSAPI_Copy(t *testing.T) { requestMethod []string postStructExpect []interface{} args []interface{} - wantUri []string + wantURI []string want interface{} wantErr bool }{ @@ -277,14 +277,14 @@ func TestDBFSAPI_Copy(t *testing.T) { &addBlock{}, &closeHandle{}, }, - wantUri: []string{"/api/2.0/dbfs/create", "/api/2.0/dbfs/read?length=1000000&path=my-path", "/api/2.0/dbfs/add-block", "/api/2.0/dbfs/close"}, + wantURI: []string{"/api/2.0/dbfs/create", "/api/2.0/dbfs/read?length=1000000&path=my-path", "/api/2.0/dbfs/add-block", "/api/2.0/dbfs/close"}, want: nil, wantErr: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantUri, tt.postStructExpect, tt.response, tt.responseStatus, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantURI, tt.postStructExpect, tt.response, tt.responseStatus, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { return nil, client.DBFS().Copy(tt.params.Src, tt.params.Tgt, &client, tt.params.Overwrite) }) }) @@ -309,7 +309,7 @@ func TestDBFSAPI_Read(t *testing.T) { requestMethod []string postStructExpect []interface{} args []interface{} - wantUri []string + wantURI []string want interface{} wantErr bool }{ @@ -346,7 +346,7 @@ func TestDBFSAPI_Read(t *testing.T) { &read{}, &read{}, }, - wantUri: []string{"/api/2.0/dbfs/read?length=1000000&path=my-path", "/api/2.0/dbfs/read?length=1000000&offset=1000000&path=my-path"}, + wantURI: []string{"/api/2.0/dbfs/read?length=1000000&path=my-path", "/api/2.0/dbfs/read?length=1000000&offset=1000000&path=my-path"}, want: base64String, wantErr: false, }, @@ -383,14 +383,14 @@ func TestDBFSAPI_Read(t *testing.T) { &read{}, &read{}, }, - wantUri: []string{"/api/2.0/dbfs/read?length=1000000&path=my-path", "/api/2.0/dbfs/read?length=1000000&offset=1000000&path=my-path"}, + wantURI: []string{"/api/2.0/dbfs/read?length=1000000&path=my-path", "/api/2.0/dbfs/read?length=1000000&offset=1000000&path=my-path"}, want: "", wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantUri, tt.postStructExpect, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertMultipleRequestsWithMockServer(t, tt.args, tt.requestMethod, tt.wantURI, tt.postStructExpect, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.DBFS().Read(tt.params.Path) }) }) @@ -531,7 +531,7 @@ func TestDBFSAPI_Status(t *testing.T) { name string response string responseStatus int - requestUri string + requestURI string args args want interface{} wantErr bool @@ -543,7 +543,7 @@ func TestDBFSAPI_Status(t *testing.T) { "is_dir": false, "file_size": 261 }`, - requestUri: "/api/2.0/dbfs/get-status?path=mypath", + requestURI: "/api/2.0/dbfs/get-status?path=mypath", responseStatus: http.StatusOK, args: args{ Path: "mypath", @@ -558,7 +558,7 @@ func TestDBFSAPI_Status(t *testing.T) { { name: "Status failure test", response: "", - requestUri: "/api/2.0/dbfs/get-status?path=mypath", + requestURI: "/api/2.0/dbfs/get-status?path=mypath", responseStatus: http.StatusBadRequest, args: args{ Path: "mypath", @@ -570,7 +570,7 @@ func TestDBFSAPI_Status(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, &tt.args, http.MethodGet, tt.requestUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, &tt.args, http.MethodGet, tt.requestURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.DBFS().Status(tt.args.Path) }) }) @@ -587,7 +587,7 @@ func TestDBFSAPI_ListNonRecursive(t *testing.T) { response string responseStatus int args args - wantUri string + wantURI string want []model.FileInfo wantErr bool }{ @@ -613,7 +613,7 @@ func TestDBFSAPI_ListNonRecursive(t *testing.T) { Path: "/", Recursive: false, }, - wantUri: "/api/2.0/dbfs/list?path=%2F", + wantURI: "/api/2.0/dbfs/list?path=%2F", want: []model.FileInfo{ { Path: "/a.cpp", @@ -637,7 +637,7 @@ func TestDBFSAPI_ListNonRecursive(t *testing.T) { Path: "/", Recursive: false, }, - wantUri: "/api/2.0/dbfs/list?path=%2F", + wantURI: "/api/2.0/dbfs/list?path=%2F", want: nil, wantErr: true, }, @@ -645,7 +645,7 @@ func TestDBFSAPI_ListNonRecursive(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.DBFS().List(tt.args.Path, tt.args.Recursive) }) }) @@ -662,7 +662,7 @@ func TestDBFSAPI_ListRecursive(t *testing.T) { response []string responseStatus []int args []interface{} - wantUri []string + wantURI []string want []model.FileInfo wantErr bool }{ @@ -699,7 +699,7 @@ func TestDBFSAPI_ListRecursive(t *testing.T) { Recursive: true, }, }, - wantUri: []string{"/api/2.0/dbfs/list?path=%2F", "/api/2.0/dbfs/list?path=%2Ffoldera"}, + wantURI: []string{"/api/2.0/dbfs/list?path=%2F", "/api/2.0/dbfs/list?path=%2Ffoldera"}, want: []model.FileInfo{ { Path: "/a.cpp", @@ -738,7 +738,7 @@ func TestDBFSAPI_ListRecursive(t *testing.T) { Recursive: true, }, }, - wantUri: []string{"/api/2.0/dbfs/list?path=%2F", "/api/2.0/dbfs/list?path=%2Ffoldera"}, + wantURI: []string{"/api/2.0/dbfs/list?path=%2F", "/api/2.0/dbfs/list?path=%2Ffoldera"}, want: nil, wantErr: true, }, @@ -752,14 +752,14 @@ func TestDBFSAPI_ListRecursive(t *testing.T) { Recursive: true, }, }, - wantUri: []string{"/api/2.0/dbfs/list?path=%2F"}, + wantURI: []string{"/api/2.0/dbfs/list?path=%2F"}, want: nil, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertMultipleRequestsWithMockServer(t, tt.args, []string{http.MethodGet, http.MethodGet}, tt.wantUri, []interface{}{&args{}}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertMultipleRequestsWithMockServer(t, tt.args, []string{http.MethodGet, http.MethodGet}, tt.wantURI, []interface{}{&args{}}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.DBFS().List(tt.args[0].(*args).Path, tt.args[0].(*args).Recursive) }) }) diff --git a/client/service/groups.go b/client/service/groups.go index c78e8f6e7..30a22f7c4 100644 --- a/client/service/groups.go +++ b/client/service/groups.go @@ -14,6 +14,7 @@ type GroupsAPI struct { Client DBApiClient } +// Create creates a scim group in the Databricks workspace func (a GroupsAPI) Create(groupName string, members []string, roles []string, entitlements []string) (model.Group, error) { var group model.Group @@ -51,6 +52,7 @@ func (a GroupsAPI) Create(groupName string, members []string, roles []string, en return group, err } +// Read reads and returns a Group object via SCIM api func (a GroupsAPI) Read(groupID string) (model.Group, error) { var group model.Group groupPath := fmt.Sprintf("/preview/scim/v2/Groups/%v", groupID) @@ -81,7 +83,7 @@ func (a GroupsAPI) Read(groupID string) (model.Group, error) { return group, err } -// Not Crud Related +// GetAdminGroup returns the admin group in a given workspace by fetching with query "displayName+eq+admins" func (a GroupsAPI) GetAdminGroup() (model.Group, error) { var group model.Group var groups model.GroupList @@ -102,6 +104,7 @@ func (a GroupsAPI) GetAdminGroup() (model.Group, error) { return group, errors.New("Unable to identify the admin group! ") } +// Patch applys a patch request for a group given a path attribute func (a GroupsAPI) Patch(groupID string, addList []string, removeList []string, path model.GroupPathType) error { groupPath := fmt.Sprintf("/preview/scim/v2/Groups/%v", groupID) @@ -114,7 +117,7 @@ func (a GroupsAPI) Patch(groupID string, addList []string, removeList []string, } if addList == nil && removeList == nil { - return errors.New("Empty members list to add or to remove.") + return errors.New("empty members list to add or to remove") } if len(addList) > 0 { @@ -143,6 +146,7 @@ func (a GroupsAPI) Patch(groupID string, addList []string, removeList []string, return err } +// Delete deletes a group given a group id func (a GroupsAPI) Delete(groupID string) error { groupPath := fmt.Sprintf("/preview/scim/v2/Groups/%v", groupID) _, err := a.Client.performQuery(http.MethodDelete, groupPath, "2.0", scimHeaders, nil, nil) diff --git a/client/service/groups_test.go b/client/service/groups_test.go index fc0fe4c49..908cca27c 100644 --- a/client/service/groups_test.go +++ b/client/service/groups_test.go @@ -124,7 +124,7 @@ func TestScimGroupAPI_Patch(t *testing.T) { } response string args args - requestUri string + requestURI string responseStatus int want interface{} wantErr bool @@ -152,7 +152,7 @@ func TestScimGroupAPI_Patch(t *testing.T) { }, }, }, - requestUri: "/api/2.0/preview/scim/v2/Groups/my-group-id", + requestURI: "/api/2.0/preview/scim/v2/Groups/my-group-id", responseStatus: http.StatusOK, want: nil, wantErr: false, @@ -181,7 +181,7 @@ func TestScimGroupAPI_Patch(t *testing.T) { removeList []string path model.GroupPathType }{groupID: "my-group-id", addList: []string{"100"}, removeList: []string{"200"}, path: model.GroupMembersPath}, - requestUri: "/api/2.0/preview/scim/v2/Groups/my-group-id", + requestURI: "/api/2.0/preview/scim/v2/Groups/my-group-id", responseStatus: http.StatusBadRequest, wantErr: true, }, @@ -189,7 +189,7 @@ func TestScimGroupAPI_Patch(t *testing.T) { for _, tt := range tests { var input args t.Run(tt.name, func(t *testing.T) { - AssertRequestWithMockServer(t, &tt.args, http.MethodPatch, tt.requestUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, &tt.args, http.MethodPatch, tt.requestURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return nil, client.Groups().Patch(tt.params.groupID, tt.params.addList, tt.params.removeList, tt.params.path) }) }) @@ -198,13 +198,13 @@ func TestScimGroupAPI_Patch(t *testing.T) { func TestScimGroupAPI_Delete(t *testing.T) { type args struct { - GroupId string `json:"user_id,omitempty"` + GroupID string `json:"user_id,omitempty"` } tests := []struct { name string response string responseStatus int - requestUri string + requestURI string args args want interface{} wantErr bool @@ -214,9 +214,9 @@ func TestScimGroupAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusOK, args: args{ - GroupId: "10030", + GroupID: "10030", }, - requestUri: "/api/2.0/preview/scim/v2/Groups/10030", + requestURI: "/api/2.0/preview/scim/v2/Groups/10030", want: nil, wantErr: false, }, @@ -225,9 +225,9 @@ func TestScimGroupAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - GroupId: "10030", + GroupID: "10030", }, - requestUri: "/api/2.0/preview/scim/v2/Groups/10030", + requestURI: "/api/2.0/preview/scim/v2/Groups/10030", want: nil, wantErr: true, }, @@ -235,8 +235,8 @@ func TestScimGroupAPI_Delete(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, &tt.args, http.MethodDelete, tt.requestUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Groups().Delete(tt.args.GroupId) + AssertRequestWithMockServer(t, &tt.args, http.MethodDelete, tt.requestURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return nil, client.Groups().Delete(tt.args.GroupID) }) }) } diff --git a/client/service/instance_pools.go b/client/service/instance_pools.go index 508f7ce92..7210e1068 100644 --- a/client/service/instance_pools.go +++ b/client/service/instance_pools.go @@ -6,6 +6,7 @@ import ( "net/http" ) +// InstancePoolsAPI exposes the instance pools api type InstancePoolsAPI struct { Client DBApiClient } @@ -29,13 +30,13 @@ func (a InstancePoolsAPI) Update(instancePoolInfo model.InstancePoolInfo) error } // Read retrieves the information for a instance pool given its identifier -func (a InstancePoolsAPI) Read(instancePoolId string) (model.InstancePoolInfo, error) { +func (a InstancePoolsAPI) Read(instancePoolID string) (model.InstancePoolInfo, error) { var instancePoolInfo model.InstancePoolInfo data := struct { - InstancePoolId string `json:"instance_pool_id,omitempty" url:"instance_pool_id,omitempty"` + InstancePoolID string `json:"instance_pool_id,omitempty" url:"instance_pool_id,omitempty"` }{ - instancePoolId, + instancePoolID, } resp, err := a.Client.performQuery(http.MethodGet, "/instance-pools/get", "2.0", nil, data, nil) if err != nil { @@ -46,12 +47,12 @@ func (a InstancePoolsAPI) Read(instancePoolId string) (model.InstancePoolInfo, e return instancePoolInfo, err } -// Terminate terminates a instance pool given its ID -func (a InstancePoolsAPI) Delete(instancePoolId string) error { +// Delete terminates a instance pool given its ID +func (a InstancePoolsAPI) Delete(instancePoolID string) error { data := struct { - InstancePoolId string `json:"instance_pool_id,omitempty" url:"instance_pool_id,omitempty"` + InstancePoolID string `json:"instance_pool_id,omitempty" url:"instance_pool_id,omitempty"` }{ - instancePoolId, + instancePoolID, } _, err := a.Client.performQuery(http.MethodPost, "/instance-pools/delete", "2.0", nil, data, nil) return err diff --git a/client/service/instance_pools_test.go b/client/service/instance_pools_test.go index 5b434462b..53bc7719b 100644 --- a/client/service/instance_pools_test.go +++ b/client/service/instance_pools_test.go @@ -59,7 +59,7 @@ func TestInstancePoolsAPI_Create(t *testing.T) { func TestInstancePoolsAPI_Delete(t *testing.T) { type args struct { - InstancePoolId string `json:"instance_pool_id"` + InstancePoolID string `json:"instance_pool_id"` } tests := []struct { name string @@ -71,7 +71,7 @@ func TestInstancePoolsAPI_Delete(t *testing.T) { name: "Basic test", response: "", args: args{ - InstancePoolId: "0101-120000-brick1-pool-ABCD1234", + InstancePoolID: "0101-120000-brick1-pool-ABCD1234", }, wantErr: false, }, @@ -80,7 +80,7 @@ func TestInstancePoolsAPI_Delete(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/instance-pools/delete", &input, tt.response, http.StatusOK, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.InstancePools().Delete(tt.args.InstancePoolId) + return nil, client.InstancePools().Delete(tt.args.InstancePoolID) }) }) } @@ -131,7 +131,7 @@ func TestInstancePoolsAPI_Update(t *testing.T) { func TestInstancePoolsAPI_Read(t *testing.T) { type args struct { - InstancePoolId string `json:"instance_pool_id"` + InstancePoolID string `json:"instance_pool_id"` } tests := []struct { name string @@ -179,7 +179,7 @@ func TestInstancePoolsAPI_Read(t *testing.T) { "status": {} }`, args: args{ - InstancePoolId: "101-120000-brick1-pool-ABCD1234", + InstancePoolID: "101-120000-brick1-pool-ABCD1234", }, want: model.InstancePoolInfo{ InstancePoolID: "101-120000-brick1-pool-ABCD1234", @@ -223,7 +223,7 @@ func TestInstancePoolsAPI_Read(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input model.InstancePoolInfo AssertRequestWithMockServer(t, &tt.args, http.MethodGet, "/api/2.0/instance-pools/get?instance_pool_id=101-120000-brick1-pool-ABCD1234", &input, tt.response, http.StatusOK, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return client.InstancePools().Read(tt.args.InstancePoolId) + return client.InstancePools().Read(tt.args.InstancePoolID) }) }) } diff --git a/client/service/instance_profiles.go b/client/service/instance_profiles.go index bc68d385d..d2afaa71e 100644 --- a/client/service/instance_profiles.go +++ b/client/service/instance_profiles.go @@ -2,16 +2,17 @@ package service import ( "encoding/json" - "errors" "fmt" "github.com/databrickslabs/databricks-terraform/client/model" "net/http" ) +// InstanceProfilesAPI exposes the instance profiles api on the AWS deployment of Databricks type InstanceProfilesAPI struct { Client DBApiClient } +// Create creates an instance profile record on Databricks func (a InstanceProfilesAPI) Create(instanceProfileARN string, skipValidation bool) error { addInstanceProfileRequest := struct { InstanceProfileArn string `json:"instance_profile_arn,omitempty" url:"instance_profile_arn,omitempty"` @@ -24,6 +25,7 @@ func (a InstanceProfilesAPI) Create(instanceProfileARN string, skipValidation bo return err } +// Read returns the ARN back if it exists on the Databricks workspace func (a InstanceProfilesAPI) Read(instanceProfileARN string) (string, error) { var response string instanceProfiles, err := a.List() @@ -37,10 +39,11 @@ func (a InstanceProfilesAPI) Read(instanceProfileARN string) (string, error) { } } - return response, errors.New(fmt.Sprintf("Instance profile with name: %s not found in "+ - "list of instance profiles in the workspace!", instanceProfileARN)) + return response, fmt.Errorf("Instance profile with name: %s not found in "+ + "list of instance profiles in the workspace!", instanceProfileARN) } +// List lists all the instance profiles in the workspace func (a InstanceProfilesAPI) List() ([]model.InstanceProfileInfo, error) { var instanceProfilesArnList struct { @@ -55,6 +58,7 @@ func (a InstanceProfilesAPI) List() ([]model.InstanceProfileInfo, error) { return instanceProfilesArnList.InstanceProfiles, err } +// Delete deletes the instance profile given an instance profile arn func (a InstanceProfilesAPI) Delete(instanceProfileARN string) error { deleteInstanceProfileRequest := struct { InstanceProfileArn string `json:"instance_profile_arn,omitempty" url:"instance_profile_arn,omitempty"` diff --git a/client/service/instance_profiles_test.go b/client/service/instance_profiles_test.go index 8ee788a4c..fa98a4e45 100644 --- a/client/service/instance_profiles_test.go +++ b/client/service/instance_profiles_test.go @@ -98,7 +98,7 @@ func TestInstanceProfilesAPI_List(t *testing.T) { response string responseStatus int args args - wantUri string + wantURI string want []model.InstanceProfileInfo wantErr bool }{ @@ -111,7 +111,7 @@ func TestInstanceProfilesAPI_List(t *testing.T) { }`, responseStatus: http.StatusOK, args: args{}, - wantUri: "/api/2.0/instance-profiles/list?", + wantURI: "/api/2.0/instance-profiles/list?", want: []model.InstanceProfileInfo{ { InstanceProfileArn: "arn:aws:iam::123456789:instance-profile/datascience-role1", @@ -130,7 +130,7 @@ func TestInstanceProfilesAPI_List(t *testing.T) { response: ``, responseStatus: http.StatusBadRequest, args: args{}, - wantUri: "/api/2.0/instance-profiles/list?", + wantURI: "/api/2.0/instance-profiles/list?", want: nil, wantErr: true, }, @@ -138,7 +138,7 @@ func TestInstanceProfilesAPI_List(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.InstanceProfiles().List() }) }) @@ -154,7 +154,7 @@ func TestInstanceProfilesAPI_Read(t *testing.T) { response string responseStatus int args args - wantUri string + wantURI string want string wantErr bool }{ @@ -169,7 +169,7 @@ func TestInstanceProfilesAPI_Read(t *testing.T) { args: args{ InstanceProfileArn: "arn:aws:iam::123456789:instance-profile/datascience-role1", }, - wantUri: "/api/2.0/instance-profiles/list?", + wantURI: "/api/2.0/instance-profiles/list?", want: "arn:aws:iam::123456789:instance-profile/datascience-role1", wantErr: false, }, @@ -184,7 +184,7 @@ func TestInstanceProfilesAPI_Read(t *testing.T) { args: args{ InstanceProfileArn: "arn:aws:iam::123456789:instance-profile/datascience-role4", }, - wantUri: "/api/2.0/instance-profiles/list?", + wantURI: "/api/2.0/instance-profiles/list?", want: "", wantErr: true, }, @@ -195,7 +195,7 @@ func TestInstanceProfilesAPI_Read(t *testing.T) { args: args{ InstanceProfileArn: "arn:aws:iam::123456789:instance-profile/datascience-role1", }, - wantUri: "/api/2.0/instance-profiles/list?", + wantURI: "/api/2.0/instance-profiles/list?", want: "", wantErr: true, }, @@ -203,7 +203,7 @@ func TestInstanceProfilesAPI_Read(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.InstanceProfiles().Read(tt.args.InstanceProfileArn) }) }) diff --git a/client/service/jobs.go b/client/service/jobs.go index d7c9847b0..c4fef0936 100644 --- a/client/service/jobs.go +++ b/client/service/jobs.go @@ -6,11 +6,12 @@ import ( "net/http" ) -// TokensAPI exposes the Secrets API +// JobsAPI exposes the Jobs API type JobsAPI struct { Client DBApiClient } +// Create creates a job on the workspace given the job settings func (a JobsAPI) Create(jobSettings model.JobSettings) (model.Job, error) { var job model.Job resp, err := a.Client.performQuery(http.MethodPost, "/jobs/create", "2.0", nil, jobSettings, nil) @@ -22,19 +23,21 @@ func (a JobsAPI) Create(jobSettings model.JobSettings) (model.Job, error) { return job, err } -func (a JobsAPI) Update(jobId int64, jobSettings model.JobSettings) error { +// Update updates a job given the id and a new set of job settings +func (a JobsAPI) Update(jobID int64, jobSettings model.JobSettings) error { jobResetRequest := struct { - JobId int64 `json:"job_id,omitempty" url:"job_id,omitempty"` + JobID int64 `json:"job_id,omitempty" url:"job_id,omitempty"` NewSettings *model.JobSettings `json:"new_settings,omitempty" url:"new_settings,omitempty"` - }{JobId: jobId, NewSettings: &jobSettings} + }{JobID: jobID, NewSettings: &jobSettings} _, err := a.Client.performQuery(http.MethodPost, "/jobs/reset", "2.0", nil, jobResetRequest, nil) return err } -func (a JobsAPI) Read(jobId int64) (model.Job, error) { +// Read returns the job object with all the attributes +func (a JobsAPI) Read(jobID int64) (model.Job, error) { jobGetRequest := struct { - JobId int64 `json:"job_id,omitempty" url:"job_id,omitempty"` - }{JobId: jobId} + JobID int64 `json:"job_id,omitempty" url:"job_id,omitempty"` + }{JobID: jobID} var job model.Job @@ -48,10 +51,11 @@ func (a JobsAPI) Read(jobId int64) (model.Job, error) { return job, err } -func (a JobsAPI) Delete(jobId int64) error { +// Delete deletes the job given a job id +func (a JobsAPI) Delete(jobID int64) error { jobDeleteRequest := struct { - JobId int64 `json:"job_id,omitempty" url:"job_id,omitempty"` - }{JobId: jobId} + JobID int64 `json:"job_id,omitempty" url:"job_id,omitempty"` + }{JobID: jobID} _, err := a.Client.performQuery(http.MethodPost, "/jobs/delete", "2.0", nil, jobDeleteRequest, nil) diff --git a/client/service/jobs_test.go b/client/service/jobs_test.go index 52ca07f82..3de1e3d77 100644 --- a/client/service/jobs_test.go +++ b/client/service/jobs_test.go @@ -54,7 +54,7 @@ func TestJobsAPI_Create(t *testing.T) { func TestJobsAPI_Update(t *testing.T) { type args struct { - JobId int64 `json:"job_id,omitempty" url:"job_id,omitempty"` + JobID int64 `json:"job_id,omitempty" url:"job_id,omitempty"` NewSettings model.JobSettings `json:"new_settings,omitempty" url:"new_settings,omitempty"` } @@ -73,7 +73,7 @@ func TestJobsAPI_Update(t *testing.T) { }`, responseStatus: http.StatusOK, args: args{ - JobId: 1, + JobID: 1, NewSettings: model.JobSettings{}, }, want: nil, @@ -84,7 +84,7 @@ func TestJobsAPI_Update(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - JobId: 0, + JobID: 0, NewSettings: model.JobSettings{}, }, want: nil, @@ -95,7 +95,7 @@ func TestJobsAPI_Update(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/jobs/reset", &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Jobs().Update(tt.args.JobId, tt.args.NewSettings) + return nil, client.Jobs().Update(tt.args.JobID, tt.args.NewSettings) }) }) } @@ -103,7 +103,7 @@ func TestJobsAPI_Update(t *testing.T) { func TestJobsAPI_Delete(t *testing.T) { type args struct { - JobId int64 `json:"job_id,omitempty" url:"job_id,omitempty"` + JobID int64 `json:"job_id,omitempty" url:"job_id,omitempty"` } tests := []struct { @@ -118,7 +118,7 @@ func TestJobsAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusOK, args: args{ - JobId: 0, + JobID: 0, }, wantErr: false, }, @@ -127,7 +127,7 @@ func TestJobsAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - JobId: 0, + JobID: 0, }, wantErr: true, }, @@ -136,7 +136,7 @@ func TestJobsAPI_Delete(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/jobs/delete", &input, tt.response, tt.responseStatus, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Jobs().Delete(tt.args.JobId) + return nil, client.Jobs().Delete(tt.args.JobID) }) }) } @@ -144,14 +144,14 @@ func TestJobsAPI_Delete(t *testing.T) { func TestJobsAPI_Read(t *testing.T) { type args struct { - JobId int64 `json:"job_id,omitempty" url:"job_id,omitempty"` + JobID int64 `json:"job_id,omitempty" url:"job_id,omitempty"` } tests := []struct { name string response string responseStatus int args args - wantUri string + wantURI string want interface{} wantErr bool }{ @@ -198,9 +198,9 @@ func TestJobsAPI_Read(t *testing.T) { }`, responseStatus: http.StatusOK, args: args{ - JobId: 1, + JobID: 1, }, - wantUri: "/api/2.0/jobs/get?job_id=1", + wantURI: "/api/2.0/jobs/get?job_id=1", want: model.Job{ JobID: 1, Settings: &model.JobSettings{ @@ -247,9 +247,9 @@ func TestJobsAPI_Read(t *testing.T) { response: ``, responseStatus: http.StatusBadRequest, args: args{ - JobId: 1, + JobID: 1, }, - wantUri: "/api/2.0/jobs/get?job_id=1", + wantURI: "/api/2.0/jobs/get?job_id=1", want: model.Job{}, wantErr: true, }, @@ -257,8 +257,8 @@ func TestJobsAPI_Read(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return client.Jobs().Read(tt.args.JobId) + AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return client.Jobs().Read(tt.args.JobID) }) }) } diff --git a/client/service/libraries.go b/client/service/libraries.go index 2226fbe02..7c18e0fac 100644 --- a/client/service/libraries.go +++ b/client/service/libraries.go @@ -6,17 +6,18 @@ import ( "net/http" ) -// TokensAPI exposes the Secrets API +// LibrariesAPI exposes the Library API type LibrariesAPI struct { Client DBApiClient } -func (a LibrariesAPI) Create(clusterId string, libraries []model.Library) error { +// Create installs the list of libraries given a cluster id +func (a LibrariesAPI) Create(clusterID string, libraries []model.Library) error { var libraryInstallRequest = struct { - ClusterId string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` Libraries []model.Library `json:"libraries,omitempty" url:"libraries,omitempty"` }{ - ClusterId: clusterId, + ClusterID: clusterID, Libraries: libraries, } @@ -25,12 +26,13 @@ func (a LibrariesAPI) Create(clusterId string, libraries []model.Library) error return err } -func (a LibrariesAPI) Delete(clusterId string, libraries []model.Library) error { +// Delete deletes the list of given libraries from the cluster given the cluster id +func (a LibrariesAPI) Delete(clusterID string, libraries []model.Library) error { var libraryInstallRequest = struct { - ClusterId string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` Libraries []model.Library `json:"libraries,omitempty" url:"libraries,omitempty"` }{ - ClusterId: clusterId, + ClusterID: clusterID, Libraries: libraries, } @@ -39,15 +41,16 @@ func (a LibrariesAPI) Delete(clusterId string, libraries []model.Library) error return err } -func (a LibrariesAPI) List(clusterId string) ([]model.LibraryStatus, error) { +// List lists all the libraries given a cluster id +func (a LibrariesAPI) List(clusterID string) ([]model.LibraryStatus, error) { var libraryStatusListResp struct { - ClusterId string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` LibraryStatuses []model.LibraryStatus `json:"library_statuses,omitempty" url:"libraries,omitempty"` } var libraryInstallRequest = struct { - ClusterId string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` }{ - ClusterId: clusterId, + ClusterID: clusterID, } resp, err := a.Client.performQuery(http.MethodGet, "/libraries/cluster-status", "2.0", nil, libraryInstallRequest, nil) diff --git a/client/service/libraries_integration_test.go b/client/service/libraries_integration_test.go index 5f8b2c90e..bda701ccc 100644 --- a/client/service/libraries_integration_test.go +++ b/client/service/libraries_integration_test.go @@ -38,9 +38,9 @@ func TestLibraryCreate(t *testing.T) { assert.NoError(t, err, err) }() - clusterId := clusterInfo.ClusterID + clusterID := clusterInfo.ClusterID - err = client.Clusters().WaitForClusterRunning(clusterId, 10, 20) + err = client.Clusters().WaitForClusterRunning(clusterID, 10, 20) assert.NoError(t, err, err) libraries := []model.Library{ @@ -56,15 +56,15 @@ func TestLibraryCreate(t *testing.T) { }, } - err = client.Libraries().Create(clusterId, libraries) + err = client.Libraries().Create(clusterID, libraries) assert.NoError(t, err, err) defer func() { - err = client.Libraries().Delete(clusterId, libraries) + err = client.Libraries().Delete(clusterID, libraries) assert.NoError(t, err, err) }() - libraryStatusList, err := client.Libraries().List(clusterId) + libraryStatusList, err := client.Libraries().List(clusterID) assert.NoError(t, err, err) assert.Equal(t, len(libraryStatusList), len(libraries)) } diff --git a/client/service/libraries_test.go b/client/service/libraries_test.go index cfaab7dc1..c550115a3 100644 --- a/client/service/libraries_test.go +++ b/client/service/libraries_test.go @@ -8,7 +8,7 @@ import ( func TestLibrariesAPI_Create(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` Libraries []model.Library `json:"libraries,omitempty" url:"libraries,omitempty"` } @@ -24,7 +24,7 @@ func TestLibrariesAPI_Create(t *testing.T) { response: "", responseStatus: http.StatusOK, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Libraries: []model.Library{ { Whl: "dbfs:/my/dbfs/wheel.whl", @@ -38,7 +38,7 @@ func TestLibrariesAPI_Create(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Libraries: []model.Library{ { Whl: "dbfs:/my/dbfs/wheel.whl", @@ -52,7 +52,7 @@ func TestLibrariesAPI_Create(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/libraries/install", &input, tt.response, tt.responseStatus, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Libraries().Create(tt.args.ClusterId, tt.args.Libraries) + return nil, client.Libraries().Create(tt.args.ClusterID, tt.args.Libraries) }) }) } @@ -60,7 +60,7 @@ func TestLibrariesAPI_Create(t *testing.T) { func TestLibrariesAPI_Delete(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` Libraries []model.Library `json:"libraries,omitempty" url:"libraries,omitempty"` } @@ -76,7 +76,7 @@ func TestLibrariesAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusOK, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Libraries: []model.Library{ { Whl: "dbfs:/my/dbfs/wheel.whl", @@ -90,7 +90,7 @@ func TestLibrariesAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "my-cluster-id", + ClusterID: "my-cluster-id", Libraries: []model.Library{ { Whl: "dbfs:/my/dbfs/wheel.whl", @@ -104,7 +104,7 @@ func TestLibrariesAPI_Delete(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/libraries/uninstall", &input, tt.response, tt.responseStatus, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Libraries().Delete(tt.args.ClusterId, tt.args.Libraries) + return nil, client.Libraries().Delete(tt.args.ClusterID, tt.args.Libraries) }) }) } @@ -112,14 +112,14 @@ func TestLibrariesAPI_Delete(t *testing.T) { func TestLibrariesAPI_List(t *testing.T) { type args struct { - ClusterId string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty" url:"cluster_id,omitempty"` } tests := []struct { name string response string responseStatus int args args - wantUri string + wantURI string want []model.LibraryStatus wantErr bool }{ @@ -161,9 +161,9 @@ func TestLibrariesAPI_List(t *testing.T) { }`, responseStatus: http.StatusOK, args: args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", }, - wantUri: "/api/2.0/libraries/cluster-status?cluster_id=11203-my-cluster", + wantURI: "/api/2.0/libraries/cluster-status?cluster_id=11203-my-cluster", want: []model.LibraryStatus{ { Library: &model.Library{ @@ -202,9 +202,9 @@ func TestLibrariesAPI_List(t *testing.T) { response: ``, responseStatus: http.StatusBadRequest, args: args{ - ClusterId: "11203-my-cluster", + ClusterID: "11203-my-cluster", }, - wantUri: "/api/2.0/libraries/cluster-status?cluster_id=11203-my-cluster", + wantURI: "/api/2.0/libraries/cluster-status?cluster_id=11203-my-cluster", want: nil, wantErr: true, }, @@ -212,8 +212,8 @@ func TestLibrariesAPI_List(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return client.Libraries().List(tt.args.ClusterId) + AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return client.Libraries().List(tt.args.ClusterID) }) }) } diff --git a/client/service/main_test.go b/client/service/main_test.go index d913c3936..007e08ef6 100644 --- a/client/service/main_test.go +++ b/client/service/main_test.go @@ -24,7 +24,7 @@ func TestMain(m *testing.M) { os.Exit(code) } -func DeserializeJson(req *http.Request, m interface{}) error { +func DeserializeJSON(req *http.Request, m interface{}) error { dec := json.NewDecoder(req.Body) dec.DisallowUnknownFields() @@ -53,9 +53,8 @@ func GetIntegrationDBAPIClient() *DBApiClient { func GetCloudInstanceType(c *DBApiClient) string { if strings.Contains(c.config.Host, "azure") { return "Standard_DS3_v2" - } else { - return "m4.large" } + return "m4.large" } func AssertRequestWithMockServer(t *testing.T, rawPayloadArgs interface{}, requestMethod string, requestURI string, input interface{}, response string, responseStatus int, want interface{}, wantErr bool, apiCall func(client DBApiClient) (interface{}, error)) { @@ -64,7 +63,7 @@ func AssertRequestWithMockServer(t *testing.T, rawPayloadArgs interface{}, reque assert.Equal(t, requestMethod, req.Method) assert.Equal(t, requestURI, req.RequestURI) if requestMethod == http.MethodPost || requestMethod == http.MethodPatch || requestMethod == http.MethodPut { - err := DeserializeJson(req, &input) + err := DeserializeJSON(req, &input) assert.NoError(t, err, err) compare(t, rawPayloadArgs, input) } @@ -103,7 +102,7 @@ func AssertMultipleRequestsWithMockServer(t *testing.T, rawPayloadArgs interface assert.Equal(t, requestMethod[counter], req.Method) assert.Equal(t, requestURI[counter], req.RequestURI) if requestMethod[counter] == http.MethodPost || requestMethod[counter] == http.MethodPatch || requestMethod[counter] == http.MethodPut { - err := DeserializeJson(req, &(input.([]interface{})[counter])) + err := DeserializeJSON(req, &(input.([]interface{})[counter])) assert.NoError(t, err, err) compare(t, rawPayloadArgs.([]interface{})[counter], input.([]interface{})[counter]) } diff --git a/client/service/mask_utils.go b/client/service/mask_utils.go index 26ccbc0ff..381b3ae9a 100644 --- a/client/service/mask_utils.go +++ b/client/service/mask_utils.go @@ -6,6 +6,7 @@ import ( "strings" ) +// Mask is a func given a struct it will mask everything with "[REDACTED]" if there are mask struct tags added func Mask(obj interface{}) interface{} { // Wrap the original in a reflect.Value original := reflect.ValueOf(obj) @@ -55,7 +56,7 @@ func maskRecursive(copy, original reflect.Value, mask bool) { // If it is a struct we Mask each field case reflect.Struct: - for i := 0; i < original.NumField(); i += 1 { + for i := 0; i < original.NumField(); i++ { //log.Println() maskValue, maskInStruct := original.Type().Field(i).Tag.Lookup("mask") maskIsTrue, _ := strconv.ParseBool(maskValue) @@ -65,7 +66,7 @@ func maskRecursive(copy, original reflect.Value, mask bool) { // If it is a slice we create a new slice and Mask each element case reflect.Slice: copy.Set(reflect.MakeSlice(original.Type(), original.Len(), original.Cap())) - for i := 0; i < original.Len(); i += 1 { + for i := 0; i < original.Len(); i++ { maskRecursive(copy.Index(i), original.Index(i), false) } @@ -97,10 +98,12 @@ func maskRecursive(copy, original reflect.Value, mask bool) { } +// SecretsMask is a struct that contains a list of secret strings to be redacted type SecretsMask struct { Secrets []string } +// MaskString given a SecretsMask and a string value return the string value with the secrets redacted func (a SecretsMask) MaskString(str string) string { placeHolder := str for _, secret := range a.Secrets { diff --git a/client/service/notebooks.go b/client/service/notebooks.go index c38f5087f..474846cd0 100644 --- a/client/service/notebooks.go +++ b/client/service/notebooks.go @@ -6,11 +6,12 @@ import ( "net/http" ) -// TokensAPI exposes the Secrets API +// NotebooksAPI exposes the Notebooks API type NotebooksAPI struct { Client DBApiClient } +// Create creates a notebook given the content and path func (a NotebooksAPI) Create(path string, content string, language model.Language, format model.ExportFormat, overwrite bool) error { notebookCreateRequest := struct { Content string `json:"content,omitempty" mask:"true"` @@ -29,6 +30,7 @@ func (a NotebooksAPI) Create(path string, content string, language model.Languag return err } +// Read returns the notebook metadata and not the contents func (a NotebooksAPI) Read(path string) (model.NotebookInfo, error) { var notebookInfo model.NotebookInfo notebookGetStatusRequest := struct { @@ -44,6 +46,7 @@ func (a NotebooksAPI) Read(path string) (model.NotebookInfo, error) { return notebookInfo, err } +// Export returns the notebook content as a base64 string func (a NotebooksAPI) Export(path string, format model.ExportFormat) (string, error) { var notebookContent map[string]string notebookExportRequest := struct { @@ -61,6 +64,7 @@ func (a NotebooksAPI) Export(path string, format model.ExportFormat) (string, er return notebookContent["content"], err } +// Mkdirs will make folders in a workspace recursively given a path func (a NotebooksAPI) Mkdirs(path string) error { mkDirsRequest := struct { Path string `json:"path,omitempty" url:"path,omitempty"` @@ -72,6 +76,8 @@ func (a NotebooksAPI) Mkdirs(path string) error { return err } +// 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 { var paths []model.NotebookInfo @@ -80,9 +86,8 @@ func (a NotebooksAPI) List(path string, recursive bool) ([]model.NotebookInfo, e return nil, err } return paths, err - } else { - return a.list(path) } + return a.list(path) } func (a NotebooksAPI) recursiveAddPaths(path string, pathList *[]model.NotebookInfo) error { @@ -121,6 +126,7 @@ func (a NotebooksAPI) list(path string) ([]model.NotebookInfo, error) { return notebookList.Objects, err } +// Delete will delete folders given a path and recursive flag func (a NotebooksAPI) Delete(path string, recursive bool) error { notebookDelete := struct { Path string `json:"path,omitempty"` diff --git a/client/service/notebooks_test.go b/client/service/notebooks_test.go index 591d40e66..0a01bf152 100644 --- a/client/service/notebooks_test.go +++ b/client/service/notebooks_test.go @@ -117,7 +117,7 @@ func TestNotebooksAPI_ListNonRecursive(t *testing.T) { response string responseStatus int args args - wantUri string + wantURI string want []model.NotebookInfo wantErr bool }{ @@ -144,7 +144,7 @@ func TestNotebooksAPI_ListNonRecursive(t *testing.T) { Path: "/test/path", Recursive: false, }, - wantUri: "/api/2.0/workspace/list?path=%2Ftest%2Fpath", + wantURI: "/api/2.0/workspace/list?path=%2Ftest%2Fpath", want: []model.NotebookInfo{ { ObjectID: 123, @@ -164,7 +164,7 @@ func TestNotebooksAPI_ListNonRecursive(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.Notebooks().List(tt.args.Path, tt.args.Recursive) }) }) @@ -181,7 +181,7 @@ func TestNotebooksAPI_ListRecursive(t *testing.T) { response []string responseStatus []int args []interface{} - wantUri []string + wantURI []string want []model.NotebookInfo wantErr bool }{ @@ -220,7 +220,7 @@ func TestNotebooksAPI_ListRecursive(t *testing.T) { Recursive: true, }, }, - wantUri: []string{"/api/2.0/workspace/list?path=%2Ftest%2Fpath", "/api/2.0/workspace/list?path=%2FUsers%2Fuser%40example.com%2Fproject"}, + wantURI: []string{"/api/2.0/workspace/list?path=%2Ftest%2Fpath", "/api/2.0/workspace/list?path=%2FUsers%2Fuser%40example.com%2Fproject"}, want: []model.NotebookInfo{ { ObjectID: 457, @@ -263,14 +263,14 @@ func TestNotebooksAPI_ListRecursive(t *testing.T) { Recursive: true, }, }, - wantUri: []string{"/api/2.0/workspace/list?path=%2Ftest%2Fpath", "/api/2.0/workspace/list?path=%2FUsers%2Fuser%40example.com%2Fproject"}, + wantURI: []string{"/api/2.0/workspace/list?path=%2Ftest%2Fpath", "/api/2.0/workspace/list?path=%2FUsers%2Fuser%40example.com%2Fproject"}, want: nil, wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertMultipleRequestsWithMockServer(t, tt.args, []string{http.MethodGet, http.MethodGet}, tt.wantUri, []interface{}{&args{}}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertMultipleRequestsWithMockServer(t, tt.args, []string{http.MethodGet, http.MethodGet}, tt.wantURI, []interface{}{&args{}}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.Notebooks().List(tt.args[0].(*args).Path, tt.args[0].(*args).Recursive) }) }) @@ -286,7 +286,7 @@ func TestNotebooksAPI_Read(t *testing.T) { response string args args responseStatus int - wantUri string + wantURI string want model.NotebookInfo wantErr bool }{ @@ -308,7 +308,7 @@ func TestNotebooksAPI_Read(t *testing.T) { Path: "/Users/user@example.com/project/ScalaExampleNotebook", Language: model.Scala, }, - wantUri: "/api/2.0/workspace/get-status?path=%2Ftest%2Fpath", + wantURI: "/api/2.0/workspace/get-status?path=%2Ftest%2Fpath", wantErr: false, }, @@ -320,14 +320,14 @@ func TestNotebooksAPI_Read(t *testing.T) { }, responseStatus: http.StatusBadRequest, want: model.NotebookInfo{}, - wantUri: "/api/2.0/workspace/get-status?path=%2Ftest%2Fpath", + wantURI: "/api/2.0/workspace/get-status?path=%2Ftest%2Fpath", wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, &tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, &tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.Notebooks().Read(tt.args.Path) }) }) @@ -344,7 +344,7 @@ func TestNotebooksAPI_Export(t *testing.T) { response string args args responseStatus int - wantUri string + wantURI string want string wantErr bool }{ @@ -359,7 +359,7 @@ func TestNotebooksAPI_Export(t *testing.T) { }, responseStatus: http.StatusOK, want: "Ly8gRGF0YWJyaWNrcyBub3RlYm9vayBzb3VyY2UKMSsx", - wantUri: "/api/2.0/workspace/export?format=DBC&path=%2Ftest%2Fpath", + wantURI: "/api/2.0/workspace/export?format=DBC&path=%2Ftest%2Fpath", wantErr: false, }, { @@ -371,14 +371,14 @@ func TestNotebooksAPI_Export(t *testing.T) { }, responseStatus: http.StatusBadRequest, want: "", - wantUri: "/api/2.0/workspace/export?format=DBC&path=%2Ftest%2Fpath", + wantURI: "/api/2.0/workspace/export?format=DBC&path=%2Ftest%2Fpath", wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, &tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, &tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.Notebooks().Export(tt.args.Path, tt.args.Format) }) }) diff --git a/client/service/secret_acls.go b/client/service/secret_acls.go index 49d8fe4e1..b8a3d4aa5 100644 --- a/client/service/secret_acls.go +++ b/client/service/secret_acls.go @@ -6,7 +6,7 @@ import ( "net/http" ) -// SecretsAPI exposes the Secrets API +// SecretAclsAPI exposes the Secret ACL API type SecretAclsAPI struct { Client DBApiClient } diff --git a/client/service/secret_scopes.go b/client/service/secret_scopes.go index 41d284274..f9fb8682d 100644 --- a/client/service/secret_scopes.go +++ b/client/service/secret_scopes.go @@ -2,18 +2,17 @@ package service import ( "encoding/json" - "errors" "fmt" "github.com/databrickslabs/databricks-terraform/client/model" "net/http" ) -// SecretsAPI exposes the Secrets API +// SecretScopesAPI exposes the Secret Scopes API type SecretScopesAPI struct { Client DBApiClient } -// CreateSecretScope creates a new secret scope +// Create creates a new secret scope func (a SecretScopesAPI) Create(scope string, initialManagePrincipal string) error { data := struct { Scope string `json:"scope,omitempty"` @@ -26,7 +25,7 @@ func (a SecretScopesAPI) Create(scope string, initialManagePrincipal string) err return err } -// DeleteSecretScope deletes a secret scope +// Delete deletes a secret scope func (a SecretScopesAPI) Delete(scope string) error { data := struct { Scope string `json:"scope,omitempty" ` @@ -52,6 +51,7 @@ func (a SecretScopesAPI) List() ([]model.SecretScope, error) { return listSecretScopesResponse.Scopes, err } +// Read will return the metadata for the secret scope func (a SecretScopesAPI) Read(scopeName string) (model.SecretScope, error) { var secretScope model.SecretScope scopes, err := a.List() @@ -63,5 +63,5 @@ func (a SecretScopesAPI) Read(scopeName string) (model.SecretScope, error) { return scope, nil } } - return secretScope, errors.New(fmt.Sprintf("No Secret Scope found with scope name %s.", scopeName)) + return secretScope, fmt.Errorf("no Secret Scope found with scope name %s", scopeName) } diff --git a/client/service/secrets.go b/client/service/secrets.go index e4d765284..a939111ef 100644 --- a/client/service/secrets.go +++ b/client/service/secrets.go @@ -2,7 +2,6 @@ package service import ( "encoding/json" - "errors" "fmt" "github.com/databrickslabs/databricks-terraform/client/model" "net/http" @@ -13,7 +12,7 @@ type SecretsAPI struct { Client DBApiClient } -// PutSecretString creates or modifies a string secret depends on the type of scope backend +// Create creates or modifies a string secret depends on the type of scope backend func (a SecretsAPI) Create(stringValue, scope, key string) error { data := struct { StringValue string `json:"string_value,omitempty" mask:"true"` @@ -28,7 +27,7 @@ func (a SecretsAPI) Create(stringValue, scope, key string) error { return err } -// DeleteSecret deletes a secret depends on the type of scope backend +// Delete deletes a secret depends on the type of scope backend func (a SecretsAPI) Delete(scope, key string) error { data := struct { Scope string `json:"scope,omitempty"` @@ -41,7 +40,7 @@ func (a SecretsAPI) Delete(scope, key string) error { return err } -// ListSecrets lists the secret keys that are stored at this scope +// List lists the secret keys that are stored at this scope func (a SecretsAPI) List(scope string) ([]model.SecretMetadata, error) { var secretsList struct { Secrets []model.SecretMetadata `json:"secrets,omitempty"` @@ -62,6 +61,7 @@ func (a SecretsAPI) List(scope string) ([]model.SecretMetadata, error) { return secretsList.Secrets, err } +// Read returns the metadata for the secret and not the contents of the secret func (a SecretsAPI) Read(scope string, key string) (model.SecretMetadata, error) { var secretMeta model.SecretMetadata secrets, err := a.List(scope) @@ -73,5 +73,5 @@ func (a SecretsAPI) Read(scope string, key string) (model.SecretMetadata, error) return secret, nil } } - return secretMeta, errors.New(fmt.Sprintf("No Secret Scope found with secret metadata scope name: %s and key: %s.", scope, key)) + return secretMeta, fmt.Errorf("no Secret Scope found with secret metadata scope name: %s and key: %s", scope, key) } diff --git a/client/service/secrets_scopes_acls_integration_test.go b/client/service/secrets_scopes_acls_integration_test.go index 8bec5bb57..181af6eb4 100644 --- a/client/service/secrets_scopes_acls_integration_test.go +++ b/client/service/secrets_scopes_acls_integration_test.go @@ -54,10 +54,10 @@ func TestSecretsScopesAclsIntegration(t *testing.T) { assert.NoError(t, err, err) assert.True(t, len(secretAcls) > 0, "Secrets acls are empty list") - secretAcl, err := client.SecretAcls().Read(testScope, testPrincipal) + secretACL, err := client.SecretAcls().Read(testScope, testPrincipal) assert.NoError(t, err, err) - assert.Equal(t, testPrincipal, secretAcl.Principal, "Secret lookup does not yield same key") - assert.Equal(t, model.ACLPermissionManage, secretAcl.Permission, "Secret lookup does not yield same key") + assert.Equal(t, testPrincipal, secretACL.Principal, "Secret lookup does not yield same key") + assert.Equal(t, model.ACLPermissionManage, secretACL.Permission, "Secret lookup does not yield same key") err = client.Secrets().Delete(testScope, testKey) assert.NoError(t, err, err) diff --git a/client/service/tokens.go b/client/service/tokens.go index 6d0ad9f78..ed376733b 100644 --- a/client/service/tokens.go +++ b/client/service/tokens.go @@ -12,6 +12,7 @@ type TokensAPI struct { Client *DBApiClient } +// Create creates a api token given a expiration duration and a comment func (a TokensAPI) Create(lifeTimeSeconds int32, comment string) (model.TokenResponse, error) { var tokenData model.TokenResponse @@ -32,6 +33,7 @@ func (a TokensAPI) Create(lifeTimeSeconds int32, comment string) (model.TokenRes return tokenData, err } +// List will list all the token metadata and not the content of the tokens in the workspace func (a TokensAPI) List() ([]model.TokenInfo, error) { var tokenListResult struct { TokenInfos []model.TokenInfo `json:"token_infos,omitempty"` @@ -44,6 +46,7 @@ func (a TokensAPI) List() ([]model.TokenInfo, error) { return tokenListResult.TokenInfos, err } +// Read will return the token metadata and not the content of the token func (a TokensAPI) Read(tokenID string) (model.TokenInfo, error) { var tokenInfo model.TokenInfo tokenList, err := a.List() @@ -58,9 +61,10 @@ func (a TokensAPI) Read(tokenID string) (model.TokenInfo, error) { return tokenInfo, errors.New("Unable to locate token: " + tokenID) } +// Delete will delete the token given a token id func (a TokensAPI) Delete(tokenID string) error { tokenDeleteRequest := struct { - TokenId string `json:"token_id,omitempty"` + TokenID string `json:"token_id,omitempty"` }{ tokenID, } diff --git a/client/service/tokens_test.go b/client/service/tokens_test.go index 67388250b..5b99aebcc 100644 --- a/client/service/tokens_test.go +++ b/client/service/tokens_test.go @@ -70,7 +70,7 @@ func TestTokensAPI_Create(t *testing.T) { func TestTokensAPI_Delete(t *testing.T) { type args struct { - TokenId string `json:"token_id,omitempty"` + TokenID string `json:"token_id,omitempty"` } tests := []struct { name string @@ -85,7 +85,7 @@ func TestTokensAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusOK, args: args{ - TokenId: "5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4", + TokenID: "5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4", }, want: nil, wantErr: false, @@ -95,7 +95,7 @@ func TestTokensAPI_Delete(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var input args AssertRequestWithMockServer(t, &tt.args, http.MethodPost, "/api/2.0/token/delete", &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Tokens().Delete(tt.args.TokenId) + return nil, client.Tokens().Delete(tt.args.TokenID) }) }) } @@ -108,7 +108,7 @@ func TestTokensAPI_List(t *testing.T) { response string responseStatus int args *args - wantUri string + wantURI string want []model.TokenInfo wantErr bool }{ @@ -132,7 +132,7 @@ func TestTokensAPI_List(t *testing.T) { }`, responseStatus: http.StatusOK, args: nil, - wantUri: "/api/2.0/token/list?", + wantURI: "/api/2.0/token/list?", want: []model.TokenInfo{ { TokenID: "5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4", @@ -154,7 +154,7 @@ func TestTokensAPI_List(t *testing.T) { response: ``, responseStatus: http.StatusBadRequest, args: nil, - wantUri: "/api/2.0/token/list?", + wantURI: "/api/2.0/token/list?", want: nil, wantErr: true, }, @@ -162,7 +162,7 @@ func TestTokensAPI_List(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertRequestWithMockServer(t, tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { return client.Tokens().List() }) }) @@ -171,14 +171,14 @@ func TestTokensAPI_List(t *testing.T) { func TestTokensAPI_Read(t *testing.T) { type args struct { - TokenId string `json:"token_id,omitempty"` + TokenID string `json:"token_id,omitempty"` } tests := []struct { name string response string args args responseStatus int - wantUri string + wantURI string want model.TokenInfo wantErr bool }{ @@ -201,7 +201,7 @@ func TestTokensAPI_Read(t *testing.T) { ] }`, args: args{ - TokenId: "5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4", + TokenID: "5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4", }, responseStatus: http.StatusOK, want: model.TokenInfo{ @@ -210,18 +210,18 @@ func TestTokensAPI_Read(t *testing.T) { ExpiryTime: 1513120616294, Comment: "this is an example token", }, - wantUri: "/api/2.0/token/list?", + wantURI: "/api/2.0/token/list?", wantErr: false, }, { name: "Read list fails", response: ``, args: args{ - TokenId: "5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4", + TokenID: "5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4", }, responseStatus: http.StatusBadRequest, want: model.TokenInfo{}, - wantUri: "/api/2.0/token/list?", + wantURI: "/api/2.0/token/list?", wantErr: true, }, { @@ -243,19 +243,19 @@ func TestTokensAPI_Read(t *testing.T) { ] }`, args: args{ - TokenId: "5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4", + TokenID: "5715498424f15ee0213be729257b53fc35a47d5953e3bdfd8ed22a0b93b339f4", }, responseStatus: http.StatusOK, want: model.TokenInfo{}, - wantUri: "/api/2.0/token/list?", + wantURI: "/api/2.0/token/list?", wantErr: true, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, &tt.args, http.MethodGet, tt.wantUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return client.Tokens().Read(tt.args.TokenId) + AssertRequestWithMockServer(t, &tt.args, http.MethodGet, tt.wantURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return client.Tokens().Read(tt.args.TokenID) }) }) } diff --git a/client/service/users.go b/client/service/users.go index a52c341e9..9a4f07d31 100644 --- a/client/service/users.go +++ b/client/service/users.go @@ -13,6 +13,7 @@ type UsersAPI struct { Client DBApiClient } +// Create given a username, displayname, entitlements, and roles will create a scim user via SCIM api func (a UsersAPI) Create(userName string, displayName string, entitlements []string, roles []string) (model.User, error) { var user model.User scimUserRequest := struct { @@ -43,8 +44,9 @@ func (a UsersAPI) Create(userName string, displayName string, entitlements []str return user, err } -func (a UsersAPI) Read(userId string) (model.User, error) { - user, err := a.read(userId) +// Read returns the user object and all the attributes of a scim user +func (a UsersAPI) Read(userID string) (model.User, error) { + user, err := a.read(userID) if err != nil { return user, err } @@ -64,9 +66,9 @@ func (a UsersAPI) Read(userId string) (model.User, error) { return user, err } -func (a UsersAPI) read(userId string) (model.User, error) { +func (a UsersAPI) read(userID string) (model.User, error) { var user model.User - userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userId) + userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userID) resp, err := a.Client.performQuery(http.MethodGet, userPath, "2.0", scimHeaders, nil, nil) if err != nil { @@ -77,8 +79,9 @@ func (a UsersAPI) read(userId string) (model.User, error) { return user, err } -func (a UsersAPI) Update(userId string, userName string, displayName string, entitlements []string, roles []string) error { - userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userId) +// Update will update the user given the user id, username, display name, entitlements and roles +func (a UsersAPI) Update(userID string, userName string, displayName string, entitlements []string, roles []string) error { + userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userID) scimUserUpdateRequest := struct { Schemas []model.URN `json:"schemas,omitempty"` UserName string `json:"userName,omitempty"` @@ -99,7 +102,7 @@ func (a UsersAPI) Update(userId string, userName string, displayName string, ent scimUserUpdateRequest.Roles = append(scimUserUpdateRequest.Roles, model.RoleListItem{Value: role}) } //Get any existing groups that the user is part of - user, err := a.read(userId) + user, err := a.read(userID) if err != nil { return err } @@ -108,16 +111,18 @@ func (a UsersAPI) Update(userId string, userName string, displayName string, ent return err } -func (a UsersAPI) Delete(userId string) error { +// Delete will delete the user given the user id +func (a UsersAPI) Delete(userID string) error { - userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userId) + userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userID) _, err := a.Client.performQuery(http.MethodDelete, userPath, "2.0", scimHeaders, nil, nil) return err } -func (a UsersAPI) SetUserAsAdmin(userId string, adminGroupId string) error { - userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userId) +// SetUserAsAdmin will add the user to a admin group given the admin group id and user id +func (a UsersAPI) SetUserAsAdmin(userID string, adminGroupID string) error { + userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userID) var addOperations model.UserPatchOperations @@ -129,7 +134,7 @@ func (a UsersAPI) SetUserAsAdmin(userId string, adminGroupId string) error { addOperations = model.UserPatchOperations{ Op: "add", Value: &model.GroupsValue{ - Groups: []model.ValueListItem{model.ValueListItem{Value: adminGroupId}}, + Groups: []model.ValueListItem{model.ValueListItem{Value: adminGroupID}}, }, } userPatchRequest.Operations = append(userPatchRequest.Operations, addOperations) @@ -139,13 +144,14 @@ func (a UsersAPI) SetUserAsAdmin(userId string, adminGroupId string) error { return err } -func (a UsersAPI) VerifyUserAsAdmin(userId string, adminGroupId string) (bool, error) { - user, err := a.read(userId) +// VerifyUserAsAdmin will verify the user belongs to the admin group given the admin group id and user id +func (a UsersAPI) VerifyUserAsAdmin(userID string, adminGroupID string) (bool, error) { + user, err := a.read(userID) if err != nil { return false, err } for _, group := range user.Groups { - if group.Value == adminGroupId { + if group.Value == adminGroupID { return true, nil } } @@ -153,8 +159,9 @@ func (a UsersAPI) VerifyUserAsAdmin(userId string, adminGroupId string) (bool, e return false, nil } -func (a UsersAPI) RemoveUserAsAdmin(userId string, adminGroupId string) error { - userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userId) +// RemoveUserAsAdmin will remove the user from the admin group given the admin group id and user id +func (a UsersAPI) RemoveUserAsAdmin(userID string, adminGroupID string) error { + userPath := fmt.Sprintf("/preview/scim/v2/Users/%v", userID) var removeOperations model.UserPatchOperations @@ -163,7 +170,7 @@ func (a UsersAPI) RemoveUserAsAdmin(userId string, adminGroupId string) error { Operations: []model.UserPatchOperations{}, } - path := fmt.Sprintf("groups[value eq \"%s\"]", adminGroupId) + path := fmt.Sprintf("groups[value eq \"%s\"]", adminGroupID) removeOperations = model.UserPatchOperations{ Op: "remove", Path: path, diff --git a/client/service/users_integration_test.go b/client/service/users_integration_test.go index 4944e0891..eb134cf80 100644 --- a/client/service/users_integration_test.go +++ b/client/service/users_integration_test.go @@ -57,20 +57,20 @@ func TestCreateAdminUser(t *testing.T) { group, err := client.Groups().GetAdminGroup() assert.NoError(t, err, err) - adminGroupId := group.ID + adminGroupID := group.ID - err = client.Users().SetUserAsAdmin(user.ID, adminGroupId) + err = client.Users().SetUserAsAdmin(user.ID, adminGroupID) assert.NoError(t, err, err) - userIsAdmin, err := client.Users().VerifyUserAsAdmin(user.ID, adminGroupId) + userIsAdmin, err := client.Users().VerifyUserAsAdmin(user.ID, adminGroupID) assert.NoError(t, err, err) assert.True(t, userIsAdmin == true) log.Println(userIsAdmin) - err = client.Users().RemoveUserAsAdmin(user.ID, adminGroupId) + err = client.Users().RemoveUserAsAdmin(user.ID, adminGroupID) assert.NoError(t, err, err) - userIsAdmin, err = client.Users().VerifyUserAsAdmin(user.ID, adminGroupId) + userIsAdmin, err = client.Users().VerifyUserAsAdmin(user.ID, adminGroupID) assert.NoError(t, err, err) assert.True(t, userIsAdmin == false) log.Println(userIsAdmin) diff --git a/client/service/users_test.go b/client/service/users_test.go index cf6136b93..8c5a65db9 100644 --- a/client/service/users_test.go +++ b/client/service/users_test.go @@ -81,7 +81,7 @@ func TestScimUserAPI_Update(t *testing.T) { response []string responseStatus []int args []interface{} - wantUri []string + wantURI []string wantErr bool }{ { @@ -93,7 +93,7 @@ func TestScimUserAPI_Update(t *testing.T) { "", }, responseStatus: []int{http.StatusOK, http.StatusOK}, - wantUri: []string{"/api/2.0/preview/scim/v2/Users/101030?", "/api/2.0/preview/scim/v2/Users/101030"}, + wantURI: []string{"/api/2.0/preview/scim/v2/Users/101030?", "/api/2.0/preview/scim/v2/Users/101030"}, args: []interface{}{ nil, &args{ @@ -112,7 +112,7 @@ func TestScimUserAPI_Update(t *testing.T) { "", }, responseStatus: []int{http.StatusBadRequest, http.StatusOK}, - wantUri: []string{"/api/2.0/preview/scim/v2/Users/101030?", "/api/2.0/preview/scim/v2/Users/101030"}, + wantURI: []string{"/api/2.0/preview/scim/v2/Users/101030?", "/api/2.0/preview/scim/v2/Users/101030"}, args: []interface{}{ nil, &args{ @@ -128,7 +128,7 @@ func TestScimUserAPI_Update(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - AssertMultipleRequestsWithMockServer(t, tt.args, []string{http.MethodGet, http.MethodPut}, tt.wantUri, []interface{}{nil, &args{}}, tt.response, tt.responseStatus, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { + AssertMultipleRequestsWithMockServer(t, tt.args, []string{http.MethodGet, http.MethodPut}, tt.wantURI, []interface{}{nil, &args{}}, tt.response, tt.responseStatus, nil, tt.wantErr, func(client DBApiClient) (interface{}, error) { return nil, client.Users().Update("101030", tt.args[1].(*args).UserName, tt.args[1].(*args).DisplayName, []string{string(tt.args[1].(*args).Entitlements[0].Value)}, []string{tt.args[1].(*args).Roles[0].Value}) }) }) @@ -137,13 +137,13 @@ func TestScimUserAPI_Update(t *testing.T) { func TestScimUserAPI_Delete(t *testing.T) { type args struct { - UserId string `json:"user_id,omitempty"` + UserID string `json:"user_id,omitempty"` } tests := []struct { name string response string responseStatus int - requestUri string + requestURI string args args want interface{} wantErr bool @@ -153,9 +153,9 @@ func TestScimUserAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusOK, args: args{ - UserId: "10030", + UserID: "10030", }, - requestUri: "/api/2.0/preview/scim/v2/Users/10030", + requestURI: "/api/2.0/preview/scim/v2/Users/10030", want: nil, wantErr: false, }, @@ -164,9 +164,9 @@ func TestScimUserAPI_Delete(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - UserId: "10030", + UserID: "10030", }, - requestUri: "/api/2.0/preview/scim/v2/Users/10030", + requestURI: "/api/2.0/preview/scim/v2/Users/10030", want: nil, wantErr: true, }, @@ -174,8 +174,8 @@ func TestScimUserAPI_Delete(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertRequestWithMockServer(t, &tt.args, http.MethodDelete, tt.requestUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Users().Delete(tt.args.UserId) + AssertRequestWithMockServer(t, &tt.args, http.MethodDelete, tt.requestURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return nil, client.Users().Delete(tt.args.UserID) }) }) } @@ -183,14 +183,14 @@ 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"` + UserID string `json:"user_id,omitempty"` + AdminGroupID string `json:"user_id,omitempty"` } tests := []struct { name string response string responseStatus int - requestUri string + requestURI string args args want interface{} wantErr bool @@ -200,10 +200,10 @@ func TestScimUserAPI_SetUserAsAdmin(t *testing.T) { response: "", responseStatus: http.StatusOK, args: args{ - UserId: "10030", - AdminGroupId: "10000", + UserID: "10030", + AdminGroupID: "10000", }, - requestUri: "/api/2.0/preview/scim/v2/Users/10030", + requestURI: "/api/2.0/preview/scim/v2/Users/10030", want: nil, wantErr: false, }, @@ -212,10 +212,10 @@ func TestScimUserAPI_SetUserAsAdmin(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - UserId: "10030", - AdminGroupId: "10000", + UserID: "10030", + AdminGroupID: "10000", }, - requestUri: "/api/2.0/preview/scim/v2/Users/10030", + requestURI: "/api/2.0/preview/scim/v2/Users/10030", want: nil, wantErr: true, }, @@ -228,12 +228,12 @@ func TestScimUserAPI_SetUserAsAdmin(t *testing.T) { Operations: []model.UserPatchOperations{ { Op: "add", - Value: &model.GroupsValue{Groups: []model.ValueListItem{model.ValueListItem{Value: tt.args.AdminGroupId}}}, + Value: &model.GroupsValue{Groups: []model.ValueListItem{model.ValueListItem{Value: tt.args.AdminGroupID}}}, }, }, } - AssertRequestWithMockServer(t, &expectedPatchRequest, http.MethodPatch, tt.requestUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Users().SetUserAsAdmin(tt.args.UserId, tt.args.AdminGroupId) + AssertRequestWithMockServer(t, &expectedPatchRequest, http.MethodPatch, tt.requestURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return nil, client.Users().SetUserAsAdmin(tt.args.UserID, tt.args.AdminGroupID) }) }) } @@ -241,14 +241,14 @@ 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"` + UserID string `json:"user_id,omitempty"` + AdminGroupID string `json:"user_id,omitempty"` } tests := []struct { name string response string responseStatus int - requestUri string + requestURI string args args want interface{} wantErr bool @@ -279,10 +279,10 @@ func TestScimUserAPI_VerifyUserAsAdmin(t *testing.T) { }`, responseStatus: http.StatusOK, args: args{ - UserId: "10030", - AdminGroupId: "100002", + UserID: "10030", + AdminGroupID: "100002", }, - requestUri: "/api/2.0/preview/scim/v2/Users/10030?", + requestURI: "/api/2.0/preview/scim/v2/Users/10030?", want: true, wantErr: false, }, @@ -312,10 +312,10 @@ func TestScimUserAPI_VerifyUserAsAdmin(t *testing.T) { }`, responseStatus: http.StatusOK, args: args{ - UserId: "10030", - AdminGroupId: "10000", + UserID: "10030", + AdminGroupID: "10000", }, - requestUri: "/api/2.0/preview/scim/v2/Users/10030?", + requestURI: "/api/2.0/preview/scim/v2/Users/10030?", want: false, wantErr: false, }, @@ -324,10 +324,10 @@ func TestScimUserAPI_VerifyUserAsAdmin(t *testing.T) { response: "{}", responseStatus: http.StatusBadRequest, args: args{ - UserId: "10030", - AdminGroupId: "10000", + UserID: "10030", + AdminGroupID: "10000", }, - requestUri: "/api/2.0/preview/scim/v2/Users/10030?", + requestURI: "/api/2.0/preview/scim/v2/Users/10030?", want: false, wantErr: true, }, @@ -340,12 +340,12 @@ func TestScimUserAPI_VerifyUserAsAdmin(t *testing.T) { Operations: []model.UserPatchOperations{ { Op: "add", - Value: &model.GroupsValue{Groups: []model.ValueListItem{model.ValueListItem{Value: tt.args.AdminGroupId}}}, + Value: &model.GroupsValue{Groups: []model.ValueListItem{model.ValueListItem{Value: tt.args.AdminGroupID}}}, }, }, } - AssertRequestWithMockServer(t, &expectedPatchRequest, http.MethodGet, tt.requestUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return client.Users().VerifyUserAsAdmin(tt.args.UserId, tt.args.AdminGroupId) + AssertRequestWithMockServer(t, &expectedPatchRequest, http.MethodGet, tt.requestURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return client.Users().VerifyUserAsAdmin(tt.args.UserID, tt.args.AdminGroupID) }) }) } @@ -353,14 +353,14 @@ 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"` + UserID string `json:"user_id,omitempty"` + AdminGroupID string `json:"user_id,omitempty"` } tests := []struct { name string response string responseStatus int - requestUri string + requestURI string args args want interface{} wantErr bool @@ -370,10 +370,10 @@ func TestScimUserAPI_RemoveUserAsAdmin(t *testing.T) { response: "", responseStatus: http.StatusOK, args: args{ - UserId: "10030", - AdminGroupId: "10000", + UserID: "10030", + AdminGroupID: "10000", }, - requestUri: "/api/2.0/preview/scim/v2/Users/10030", + requestURI: "/api/2.0/preview/scim/v2/Users/10030", want: nil, wantErr: false, }, @@ -382,10 +382,10 @@ func TestScimUserAPI_RemoveUserAsAdmin(t *testing.T) { response: "", responseStatus: http.StatusBadRequest, args: args{ - UserId: "10030", - AdminGroupId: "10000", + UserID: "10030", + AdminGroupID: "10000", }, - requestUri: "/api/2.0/preview/scim/v2/Users/10030", + requestURI: "/api/2.0/preview/scim/v2/Users/10030", want: nil, wantErr: true, }, @@ -398,12 +398,12 @@ func TestScimUserAPI_RemoveUserAsAdmin(t *testing.T) { Operations: []model.UserPatchOperations{ { Op: "remove", - Path: fmt.Sprintf("groups[value eq \"%s\"]", tt.args.AdminGroupId), + Path: fmt.Sprintf("groups[value eq \"%s\"]", tt.args.AdminGroupID), }, }, } - AssertRequestWithMockServer(t, &expectedPatchRequest, http.MethodPatch, tt.requestUri, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return nil, client.Users().RemoveUserAsAdmin(tt.args.UserId, tt.args.AdminGroupId) + AssertRequestWithMockServer(t, &expectedPatchRequest, http.MethodPatch, tt.requestURI, &input, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return nil, client.Users().RemoveUserAsAdmin(tt.args.UserID, tt.args.AdminGroupID) }) }) } @@ -411,14 +411,14 @@ func TestScimUserAPI_RemoveUserAsAdmin(t *testing.T) { func TestScimUserAPI_Read(t *testing.T) { type args struct { - UserId string `json:"user_id"` + UserID string `json:"user_id"` } tests := []struct { name string response []string responseStatus []int args []args - wantUri []string + wantURI []string want model.User wantErr bool }{ @@ -490,10 +490,10 @@ func TestScimUserAPI_Read(t *testing.T) { responseStatus: []int{http.StatusOK, http.StatusOK, http.StatusOK}, args: []args{ { - UserId: "101030", + UserID: "101030", }, }, - wantUri: []string{"/api/2.0/preview/scim/v2/Users/101030?", "/api/2.0/preview/scim/v2/Groups/100002?", "/api/2.0/preview/scim/v2/Groups/101355?"}, + wantURI: []string{"/api/2.0/preview/scim/v2/Users/101030?", "/api/2.0/preview/scim/v2/Groups/100002?", "/api/2.0/preview/scim/v2/Groups/101355?"}, want: model.User{ ID: "101030", DisplayName: "test.user@databricks.com", @@ -535,10 +535,10 @@ func TestScimUserAPI_Read(t *testing.T) { responseStatus: []int{http.StatusBadRequest}, args: []args{ { - UserId: "101030", + UserID: "101030", }, }, - wantUri: []string{"/api/2.0/preview/scim/v2/Users/101030?"}, + wantURI: []string{"/api/2.0/preview/scim/v2/Users/101030?"}, want: model.User{}, wantErr: true, }, @@ -550,10 +550,10 @@ func TestScimUserAPI_Read(t *testing.T) { responseStatus: []int{http.StatusOK}, args: []args{ { - UserId: "101030", + UserID: "101030", }, }, - wantUri: []string{"/api/2.0/preview/scim/v2/Users/101030?"}, + wantURI: []string{"/api/2.0/preview/scim/v2/Users/101030?"}, want: model.User{}, wantErr: true, }, @@ -586,10 +586,10 @@ func TestScimUserAPI_Read(t *testing.T) { responseStatus: []int{http.StatusOK, http.StatusBadRequest}, args: []args{ { - UserId: "101030", + UserID: "101030", }, }, - wantUri: []string{"/api/2.0/preview/scim/v2/Users/101030?", "/api/2.0/preview/scim/v2/Groups/100002?"}, + wantURI: []string{"/api/2.0/preview/scim/v2/Users/101030?", "/api/2.0/preview/scim/v2/Groups/100002?"}, want: model.User{ ID: "101030", DisplayName: "test.user@databricks.com", @@ -614,8 +614,8 @@ func TestScimUserAPI_Read(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var input args - AssertMultipleRequestsWithMockServer(t, tt.args, []string{http.MethodGet, http.MethodGet, http.MethodGet}, tt.wantUri, []args{input}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { - return client.Users().Read(tt.args[0].UserId) + AssertMultipleRequestsWithMockServer(t, tt.args, []string{http.MethodGet, http.MethodGet, http.MethodGet}, tt.wantURI, []args{input}, tt.response, tt.responseStatus, tt.want, tt.wantErr, func(client DBApiClient) (interface{}, error) { + return client.Users().Read(tt.args[0].UserID) }) }) } From 08e3eb7cbacc964718609d7f4cdfacd5a66e89b2 Mon Sep 17 00:00:00 2001 From: Sriharsha Tikkireddy Date: Mon, 20 Apr 2020 12:27:08 -0400 Subject: [PATCH 3/5] Fixed & refactored linting issues in databricks package --- databricks/azure_ws_init.go | 15 ++- databricks/azure_ws_init_test.go | 2 +- databricks/mounts.go | 120 +++++++++++------- databricks/provider.go | 37 +++--- .../resource_databricks_aws_s3_mount.go | 20 +-- ...source_databricks_azure_adls_gen1_mount.go | 45 ++++--- ...source_databricks_azure_adls_gen2_mount.go | 45 ++++--- .../resource_databricks_azure_blob_mount.go | 23 ++-- databricks/resource_databricks_cluster.go | 18 +-- databricks/resource_databricks_dbfs_file.go | 4 +- .../resource_databricks_instance_pool.go | 12 +- .../resource_databricks_instance_profile.go | 4 +- databricks/resource_databricks_job.go | 8 +- databricks/resource_databricks_notebook.go | 4 +- databricks/resource_databricks_scim_group.go | 4 +- databricks/resource_databricks_scim_user.go | 4 +- .../resource_databricks_scim_user_test.go | 2 +- databricks/resource_databricks_secret.go | 12 +- databricks/resource_databricks_secret_acl.go | 38 +++--- .../resource_databricks_secret_acl_test.go | 22 ++-- .../resource_databricks_secret_scope.go | 4 +- .../resource_databricks_secret_scope_test.go | 2 +- databricks/resource_databricks_secret_test.go | 2 +- databricks/resource_databricks_token.go | 8 +- databricks/resource_databricks_token_test.go | 4 +- databricks/utils.go | 65 +++++----- 26 files changed, 273 insertions(+), 251 deletions(-) diff --git a/databricks/azure_ws_init.go b/databricks/azure_ws_init.go index b11b5eb9b..3154e0511 100644 --- a/databricks/azure_ws_init.go +++ b/databricks/azure_ws_init.go @@ -7,11 +7,13 @@ import ( "net/http" ) +// List of management information const ( ManagementResourceEndpoint string = "https://management.core.windows.net/" ADBResourceID string = "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d" ) +// AzureAuth is a struct that contains information about the azure sp authentication type AzureAuth struct { TokenPayload *TokenPayload ManagementToken string @@ -20,21 +22,24 @@ type AzureAuth struct { AdbPlatformToken string } +// TokenPayload contains all the auth information for azure sp authentication type TokenPayload struct { ManagedResourceGroup string AzureRegion string WorkspaceName string ResourceGroup string - SubscriptionId string + SubscriptionID string ClientSecret string ClientID string TenantID string } +// WsProps contains information about the workspace properties type WsProps struct { ManagedResourceGroupID string `json:"managedResourceGroupId"` } +// WorkspaceRequest contains the request information for getting workspace information type WorkspaceRequest struct { Properties *WsProps `json:"properties"` Name string `json:"name"` @@ -63,13 +68,13 @@ func (a *AzureAuth) getManagementToken(config *service.DBApiClientConfig) error return nil } -func (a *AzureAuth) getWorkspaceId(config *service.DBApiClientConfig) error { +func (a *AzureAuth) getWorkspaceID(config *service.DBApiClientConfig) error { log.Println("[DEBUG] Getting Workspace ID via management token.") - url := "https://management.azure.com/subscriptions/" + a.TokenPayload.SubscriptionId + "/resourceGroups/" + a.TokenPayload.ResourceGroup + "/providers/Microsoft.Databricks/workspaces/" + a.TokenPayload.WorkspaceName + "" + + url := "https://management.azure.com/subscriptions/" + a.TokenPayload.SubscriptionID + "/resourceGroups/" + a.TokenPayload.ResourceGroup + "/providers/Microsoft.Databricks/workspaces/" + a.TokenPayload.WorkspaceName + "" + "?api-version=2018-04-01" payload := &WorkspaceRequest{ - Properties: &WsProps{ManagedResourceGroupID: "/subscriptions/" + a.TokenPayload.SubscriptionId + "/resourceGroups/" + a.TokenPayload.ManagedResourceGroup}, + Properties: &WsProps{ManagedResourceGroupID: "/subscriptions/" + a.TokenPayload.SubscriptionID + "/resourceGroups/" + a.TokenPayload.ManagedResourceGroup}, Name: a.TokenPayload.WorkspaceName, Location: a.TokenPayload.AzureRegion, } @@ -157,7 +162,7 @@ func (a *AzureAuth) initWorkspaceAndGetClient(config *service.DBApiClientConfig) return dbClient, err } - err = a.getWorkspaceId(config) + err = a.getWorkspaceID(config) if err != nil { return dbClient, err } diff --git a/databricks/azure_ws_init_test.go b/databricks/azure_ws_init_test.go index 9ebcd2713..e7c406be5 100644 --- a/databricks/azure_ws_init_test.go +++ b/databricks/azure_ws_init_test.go @@ -33,7 +33,7 @@ func TestAzureAuthCreateApiToken(t *testing.T) { AdbAccessToken: "", AdbPlatformToken: "", } - azureAuth.TokenPayload.SubscriptionId = os.Getenv("ARM_SUBSCRIPTION_ID") + azureAuth.TokenPayload.SubscriptionID = os.Getenv("ARM_SUBSCRIPTION_ID") azureAuth.TokenPayload.TenantID = os.Getenv("ARM_TENANT_ID") azureAuth.TokenPayload.ClientID = os.Getenv("ARM_CLIENT_ID") azureAuth.TokenPayload.ClientSecret = os.Getenv("ARM_CLIENT_SECRET") diff --git a/databricks/mounts.go b/databricks/mounts.go index 483ef5265..2293d7d5b 100644 --- a/databricks/mounts.go +++ b/databricks/mounts.go @@ -9,29 +9,33 @@ import ( "strings" ) +// Mount interface describes the functionality of any mount which is create, read and delete type Mount interface { - Create(client service.DBApiClient, clusterId string) error - Delete(client service.DBApiClient, clusterId string) error - Read(client service.DBApiClient, clusterId string) (string, error) + Create(client service.DBApiClient, clusterID string) error + Delete(client service.DBApiClient, clusterID string) error + Read(client service.DBApiClient, clusterID string) (string, error) } +// AWSIamMount describes the object for a aws mount using iam role type AWSIamMount struct { Mount S3BucketName string MountName string } +// NewAWSIamMount constructor for AWSIamMount func NewAWSIamMount(s3BucketName string, mountName string) *AWSIamMount { return &AWSIamMount{S3BucketName: s3BucketName, MountName: mountName} } -func (m AWSIamMount) Create(client service.DBApiClient, clusterId string) error { +// Create creates an aws iam mount given a cluster ID +func (m AWSIamMount) Create(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.mount("s3a://%s", "/mnt/%s") dbutils.fs.ls("/mnt/%s") dbutils.notebook.exit("success") `, m.S3BucketName, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -42,13 +46,14 @@ dbutils.notebook.exit("success") return nil } -func (m AWSIamMount) Delete(client service.DBApiClient, clusterId string) error { +// Delete deletes an aws iam mount given a cluster ID +func (m AWSIamMount) Delete(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.unmount("/mnt/%s") dbutils.fs.refreshMounts() dbutils.notebook.exit("success") `, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -59,14 +64,15 @@ dbutils.notebook.exit("success") return nil } -func (m AWSIamMount) Read(client service.DBApiClient, clusterId string) (string, error) { +// Read verifies an aws iam mount given a cluster ID +func (m AWSIamMount) Read(client service.DBApiClient, clusterID string) (string, error) { iamMountCommand := fmt.Sprintf(` dbutils.fs.ls("/mnt/%s") for mount in dbutils.fs.mounts(): if mount.mountPoint == "/mnt/%s": dbutils.notebook.exit(mount.source) `, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return "", err } @@ -75,15 +81,16 @@ for mount in dbutils.fs.mounts(): return "", errors.New(resp.Results.Summary) } if resp.Results.ResultType == "text" && resp.Results.Data.(string) == "" { - return "", errors.New("Unable to find mount point!") + return "", errors.New("unable to find mount point") } respBucket := strings.Replace(resp.Results.Data.(string), "s3a://", "", 1) if resp.Results.ResultType == "text" && respBucket != m.S3BucketName { - return "", errors.New(fmt.Sprintf("Does not match bucket value! %s != %s!", resp.Results.Data.(string), m.S3BucketName)) + return "", fmt.Errorf("does not match bucket value! %s != %s", resp.Results.Data.(string), m.S3BucketName) } return respBucket, nil } +// AzureBlobMount describes the object for a azure blob storage mount type AzureBlobMount struct { Mount ContainerName string @@ -95,11 +102,13 @@ type AzureBlobMount struct { SecretKey string } +// NewAzureBlobMount constructor for AzureBlobMount func NewAzureBlobMount(containerName string, storageAccountName string, directory string, mountName string, authType string, secretScope string, secretKey string) *AzureBlobMount { return &AzureBlobMount{ContainerName: containerName, StorageAccountName: storageAccountName, Directory: directory, MountName: mountName, AuthType: authType, SecretScope: secretScope, SecretKey: secretKey} } -func (m AzureBlobMount) Create(client service.DBApiClient, clusterId string) error { +// Create creates a azure blob storage mount given a cluster id +func (m AzureBlobMount) Create(client service.DBApiClient, clusterID string) error { var confKey string if m.AuthType == "SAS" { @@ -118,7 +127,7 @@ except Exception as e: raise e dbutils.notebook.exit("success") `, m.ContainerName, m.StorageAccountName, m.Directory, m.MountName, confKey, m.SecretScope, m.SecretKey, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -129,13 +138,14 @@ dbutils.notebook.exit("success") return nil } -func (m AzureBlobMount) Delete(client service.DBApiClient, clusterId string) error { +// Delete deletes a azure blob storage mount given a cluster id +func (m AzureBlobMount) Delete(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.unmount("/mnt/%s") dbutils.fs.refreshMounts() dbutils.notebook.exit("success") `, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -146,14 +156,15 @@ dbutils.notebook.exit("success") return nil } -func (m AzureBlobMount) Read(client service.DBApiClient, clusterId string) (string, error) { +// Read verifies a azure blob storage mount given a cluster id +func (m AzureBlobMount) Read(client service.DBApiClient, clusterID string) (string, error) { iamMountCommand := fmt.Sprintf(` dbutils.fs.ls("/mnt/%s") for mount in dbutils.fs.mounts(): if mount.mountPoint == "/mnt/%s": dbutils.notebook.exit(mount.source) `, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return "", err } @@ -162,7 +173,7 @@ for mount in dbutils.fs.mounts(): return "", errors.New(resp.Results.Summary) } if resp.Results.ResultType == "text" && resp.Results.Data.(string) == "" { - return "", errors.New("Unable to find mount point!") + return "", errors.New("unable to find mount point") } container, storageAccount, directory, err := ProcessAzureWasbAbfssUris(resp.Results.Data.(string)) @@ -172,29 +183,32 @@ for mount in dbutils.fs.mounts(): if resp.Results.ResultType == "text" && container != m.ContainerName && storageAccount != m.StorageAccountName && m.Directory != directory { - return "", errors.New(fmt.Sprintf("Does not match uri with storage account and container values!"+ - " %s@%s != %s!", m.ContainerName, m.StorageAccountName, resp.Results.Data.(string))) + return "", fmt.Errorf("does not match uri with storage account and container values"+ + " %s@%s != %s!", m.ContainerName, m.StorageAccountName, resp.Results.Data.(string)) } return resp.Results.Data.(string), nil } +// AzureADLSGen1Mount describes the object for a azure datalake gen 1 storage mount type AzureADLSGen1Mount struct { Mount StorageResource string Directory string MountName string PrefixType string - ClientId string - TenantId string + ClientID string + TenantID string SecretScope string SecretKey string } -func NewAzureADLSGen1Mount(storageResource string, directory string, mountName string, prefixType string, clientId string, tenantId string, secretScope string, secretKey string) *AzureADLSGen1Mount { - return &AzureADLSGen1Mount{StorageResource: storageResource, Directory: directory, MountName: mountName, PrefixType: prefixType, ClientId: clientId, TenantId: tenantId, SecretScope: secretScope, SecretKey: secretKey} +// NewAzureADLSGen1Mount constructor for AzureADLSGen1Mount +func NewAzureADLSGen1Mount(storageResource string, directory string, mountName string, prefixType string, clientID string, tenantID string, secretScope string, secretKey string) *AzureADLSGen1Mount { + return &AzureADLSGen1Mount{StorageResource: storageResource, Directory: directory, MountName: mountName, PrefixType: prefixType, ClientID: clientID, TenantID: tenantID, SecretScope: secretScope, SecretKey: secretKey} } -func (m AzureADLSGen1Mount) Create(client service.DBApiClient, clusterId string) error { +// Create creates a azure datalake gen 1 storage mount given a cluster id +func (m AzureADLSGen1Mount) Create(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` try: configs = {"%s.oauth2.access.token.provider.type": "ClientCredential", @@ -209,9 +223,9 @@ except Exception as e: dbutils.fs.unmount("/mnt/%s") raise e dbutils.notebook.exit("success") -`, m.PrefixType, m.PrefixType, m.ClientId, m.PrefixType, m.SecretScope, m.SecretKey, m.PrefixType, m.TenantId, +`, m.PrefixType, m.PrefixType, m.ClientID, m.PrefixType, m.SecretScope, m.SecretKey, m.PrefixType, m.TenantID, m.StorageResource, m.Directory, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -222,13 +236,14 @@ dbutils.notebook.exit("success") return nil } -func (m AzureADLSGen1Mount) Delete(client service.DBApiClient, clusterId string) error { +// Delete deletes a azure datalake gen 1 storage mount given a cluster id +func (m AzureADLSGen1Mount) Delete(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.unmount("/mnt/%s") dbutils.fs.refreshMounts() dbutils.notebook.exit("success") `, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -239,14 +254,15 @@ dbutils.notebook.exit("success") return nil } -func (m AzureADLSGen1Mount) Read(client service.DBApiClient, clusterId string) (string, error) { +// Read verifies the azure datalake gen 1 storage mount given a cluster id +func (m AzureADLSGen1Mount) Read(client service.DBApiClient, clusterID string) (string, error) { iamMountCommand := fmt.Sprintf(` dbutils.fs.ls("/mnt/%s") for mount in dbutils.fs.mounts(): if mount.mountPoint == "/mnt/%s": dbutils.notebook.exit(mount.source) `, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return "", err } @@ -255,7 +271,7 @@ for mount in dbutils.fs.mounts(): return "", errors.New(resp.Results.Summary) } if resp.Results.ResultType == "text" && resp.Results.Data.(string) == "" { - return "", errors.New("Unable to find mount point!") + return "", errors.New("unable to find mount point") } storageResource, directory, err := ProcessAzureAdlsGen1Uri(resp.Results.Data.(string)) @@ -264,29 +280,32 @@ for mount in dbutils.fs.mounts(): } if resp.Results.ResultType == "text" && storageResource != m.StorageResource && m.Directory != directory { - return "", errors.New(fmt.Sprintf("Does not match uri with storage account and container values!"+ - " %s@%s != %s!", m.StorageResource, m.Directory, resp.Results.Data.(string))) + return "", fmt.Errorf("does not match uri with storage account and container values"+ + " %s@%s != %s!", m.StorageResource, m.Directory, resp.Results.Data.(string)) } return resp.Results.Data.(string), nil } +// AzureADLSGen2Mount describes the object for a azure datalake gen 2 storage mount type AzureADLSGen2Mount struct { Mount ContainerName string StorageAccountName string Directory string MountName string - ClientId string - TenantId string + ClientID string + TenantID string SecretScope string SecretKey string } -func NewAzureADLSGen2Mount(containerName string, storageAccountName string, directory string, mountName string, clientId string, tenantId string, secretScope string, secretKey string) *AzureADLSGen2Mount { - return &AzureADLSGen2Mount{ContainerName: containerName, StorageAccountName: storageAccountName, Directory: directory, MountName: mountName, ClientId: clientId, TenantId: tenantId, SecretScope: secretScope, SecretKey: secretKey} +// NewAzureADLSGen2Mount is a constructor for AzureADLSGen2Mount +func NewAzureADLSGen2Mount(containerName string, storageAccountName string, directory string, mountName string, clientID string, tenantID string, secretScope string, secretKey string) *AzureADLSGen2Mount { + return &AzureADLSGen2Mount{ContainerName: containerName, StorageAccountName: storageAccountName, Directory: directory, MountName: mountName, ClientID: clientID, TenantID: tenantID, SecretScope: secretScope, SecretKey: secretKey} } -func (m AzureADLSGen2Mount) Create(client service.DBApiClient, clusterId string) error { +// Create creates a azure datalake gen 2 storage mount +func (m AzureADLSGen2Mount) Create(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` try: configs = {"fs.azure.account.auth.type": "OAuth", @@ -302,8 +321,8 @@ except Exception as e: dbutils.fs.unmount("/mnt/%s") raise e dbutils.notebook.exit("success") -`, m.ClientId, m.SecretScope, m.SecretKey, m.TenantId, m.ContainerName, m.StorageAccountName, m.Directory, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) +`, m.ClientID, m.SecretScope, m.SecretKey, m.TenantID, m.ContainerName, m.StorageAccountName, m.Directory, m.MountName, m.MountName) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -314,13 +333,14 @@ dbutils.notebook.exit("success") return nil } -func (m AzureADLSGen2Mount) Delete(client service.DBApiClient, clusterId string) error { +// Delete deletes a azure datalake gen 2 storage mount +func (m AzureADLSGen2Mount) Delete(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.unmount("/mnt/%s") dbutils.fs.refreshMounts() dbutils.notebook.exit("success") `, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -331,14 +351,15 @@ dbutils.notebook.exit("success") return nil } -func (m AzureADLSGen2Mount) Read(client service.DBApiClient, clusterId string) (string, error) { +// Read verifies the azure datalake gen 2 storage mount +func (m AzureADLSGen2Mount) Read(client service.DBApiClient, clusterID string) (string, error) { iamMountCommand := fmt.Sprintf(` dbutils.fs.ls("/mnt/%s") for mount in dbutils.fs.mounts(): if mount.mountPoint == "/mnt/%s": dbutils.notebook.exit(mount.source) `, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return "", err } @@ -347,7 +368,7 @@ for mount in dbutils.fs.mounts(): return "", errors.New(resp.Results.Summary) } if resp.Results.ResultType == "text" && resp.Results.Data.(string) == "" { - return "", errors.New("Unable to find mount point!") + return "", errors.New("unable to find mount point") } containerName, storageAccountName, directory, err := ProcessAzureWasbAbfssUris(resp.Results.Data.(string)) @@ -356,12 +377,13 @@ for mount in dbutils.fs.mounts(): } if resp.Results.ResultType == "text" && containerName != m.ContainerName && m.StorageAccountName != storageAccountName && m.Directory != directory { - return "", errors.New(fmt.Sprintf("Does not match uri with storage account and container values!"+ - " %s@%s != %s!", m.ContainerName, m.StorageAccountName, resp.Results.Data.(string))) + return "", fmt.Errorf("does not match uri with storage account and container values"+ + " %s@%s != %s!", m.ContainerName, m.StorageAccountName, resp.Results.Data.(string)) } return resp.Results.Data.(string), nil } +// ProcessAzureAdlsGen1Uri will return given a adls gen 1 URI the storage account name and the directory if it exists func ProcessAzureAdlsGen1Uri(uri string) (string, string, error) { u, err := url.Parse(uri) if err != nil { @@ -377,6 +399,8 @@ func ProcessAzureAdlsGen1Uri(uri string) (string, string, error) { return storageAccount, directory, nil } +// ProcessAzureWasbAbfssUris will return given a WASBS or ABFSS URI the +// containerName, storageAccount and the directory if it exists func ProcessAzureWasbAbfssUris(uri string) (string, string, string, error) { u, err := url.Parse(uri) if err != nil { diff --git a/databricks/provider.go b/databricks/provider.go index b0bfb3791..0406a35e2 100644 --- a/databricks/provider.go +++ b/databricks/provider.go @@ -8,6 +8,7 @@ import ( "os" ) +// Provider returns the entire terraform provider object func Provider() terraform.ResourceProvider { provider := &schema.Provider{ DataSourcesMap: map[string]*schema.Resource{ @@ -18,19 +19,19 @@ func Provider() terraform.ResourceProvider { "databricks_zones": dataSourceClusterZones(), }, ResourcesMap: map[string]*schema.Resource{ - "databricks_token": resourceToken(), - "databricks_secret_scope": resourceSecretScope(), - "databricks_secret": resourceSecret(), - "databricks_secret_acl": resourceSecretAcl(), - "databricks_instance_pool": resourceInstancePool(), - "databricks_scim_user": resourceScimUser(), - "databricks_scim_group": resourceScimGroup(), - "databricks_notebook": resourceNotebook(), - "databricks_cluster": resourceCluster(), - "databricks_job": resourceJob(), - "databricks_dbfs_file": resourceDBFSFile(), - "databricks_dbfs_file_sync": resourceDBFSFileSync(), - "databricks_instance_profile": resourceInstanceProfile(), + "databricks_token": resourceToken(), + "databricks_secret_scope": resourceSecretScope(), + "databricks_secret": resourceSecret(), + "databricks_secret_acl": resourceSecretACL(), + "databricks_instance_pool": resourceInstancePool(), + "databricks_scim_user": resourceScimUser(), + "databricks_scim_group": resourceScimGroup(), + "databricks_notebook": resourceNotebook(), + "databricks_cluster": resourceCluster(), + "databricks_job": resourceJob(), + "databricks_dbfs_file": resourceDBFSFile(), + "databricks_dbfs_file_sync": resourceDBFSFileSync(), + "databricks_instance_profile": resourceInstanceProfile(), "databricks_aws_s3_mount": resourceAWSS3Mount(), "databricks_azure_blob_mount": resourceAzureBlobMount(), "databricks_azure_adls_gen1_mount": resourceAzureAdlsGen1Mount(), @@ -132,24 +133,24 @@ func providerConfigure(d *schema.ResourceData, s string) (interface{}, error) { tokenPayload.WorkspaceName = workspaceName } if subscriptionID, ok := azureAuthMap["subscription_id"].(string); ok { - tokenPayload.SubscriptionId = subscriptionID + tokenPayload.SubscriptionID = subscriptionID } else { - tokenPayload.SubscriptionId = os.Getenv("ARM_SUBSCRIPTION_ID") + tokenPayload.SubscriptionID = os.Getenv("ARM_SUBSCRIPTION_ID") } if clientSecret, ok := azureAuthMap["client_secret"].(string); ok { tokenPayload.ClientSecret = clientSecret } else { - tokenPayload.SubscriptionId = os.Getenv("ARM_CLIENT_SECRET") + tokenPayload.SubscriptionID = os.Getenv("ARM_CLIENT_SECRET") } if clientID, ok := azureAuthMap["client_id"].(string); ok { tokenPayload.ClientID = clientID } else { - tokenPayload.SubscriptionId = os.Getenv("ARM_CLIENT_ID") + tokenPayload.SubscriptionID = os.Getenv("ARM_CLIENT_ID") } if tenantID, ok := azureAuthMap["tenant_id"].(string); ok { tokenPayload.TenantID = tenantID } else { - tokenPayload.SubscriptionId = os.Getenv("ARM_TENANT_ID") + tokenPayload.SubscriptionID = os.Getenv("ARM_TENANT_ID") } azureAuthSetup := AzureAuth{ diff --git a/databricks/resource_databricks_aws_s3_mount.go b/databricks/resource_databricks_aws_s3_mount.go index f5e1f0cd1..fd330ac62 100644 --- a/databricks/resource_databricks_aws_s3_mount.go +++ b/databricks/resource_databricks_aws_s3_mount.go @@ -33,8 +33,8 @@ func resourceAWSS3Mount() *schema.Resource { func resourceAWSS3Create(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -43,14 +43,14 @@ func resourceAWSS3Create(d *schema.ResourceData, m interface{}) error { s3BucketMount := NewAWSIamMount(s3BucketName, mountName) - err = s3BucketMount.Create(client, clusterId) + err = s3BucketMount.Create(client, clusterID) if err != nil { return err } d.SetId(mountName) - err = d.Set("cluster_id", clusterId) + err = d.Set("cluster_id", clusterID) if err != nil { return err } @@ -64,8 +64,8 @@ func resourceAWSS3Create(d *schema.ResourceData, m interface{}) error { func resourceAWSS3Read(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -74,7 +74,7 @@ func resourceAWSS3Read(d *schema.ResourceData, m interface{}) error { s3BucketMount := NewAWSIamMount(s3BucketName, mountName) - s3BucketNameMounted, err := s3BucketMount.Read(client, clusterId) + s3BucketNameMounted, err := s3BucketMount.Read(client, clusterID) if err != nil { return err } @@ -85,13 +85,13 @@ func resourceAWSS3Read(d *schema.ResourceData, m interface{}) error { func resourceAWSS3Delete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } s3BucketName := d.Get("s3_bucket_name").(string) mountName := d.Get("mount_name").(string) s3BucketMount := NewAWSIamMount(s3BucketName, mountName) - return s3BucketMount.Delete(client, clusterId) + return s3BucketMount.Delete(client, clusterID) } diff --git a/databricks/resource_databricks_azure_adls_gen1_mount.go b/databricks/resource_databricks_azure_adls_gen1_mount.go index 4b55736df..71021f2e1 100644 --- a/databricks/resource_databricks_azure_adls_gen1_mount.go +++ b/databricks/resource_databricks_azure_adls_gen1_mount.go @@ -42,9 +42,8 @@ func resourceAzureAdlsGen1Mount() *schema.Resource { directory := val.(string) if strings.HasPrefix(directory, "/") { return - } else { - errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) } + errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) return }, }, @@ -79,8 +78,8 @@ func resourceAzureAdlsGen1Mount() *schema.Resource { func resourceAzureAdlsGen1Create(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -88,21 +87,21 @@ func resourceAzureAdlsGen1Create(d *schema.ResourceData, m interface{}) error { sparkConfPrefix := d.Get("spark_conf_prefix").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) adlsGen1Mount := NewAzureADLSGen1Mount(storageResourceName, directory, mountName, - sparkConfPrefix, clientId, tenantId, clientSecretScope, clientSecretKey) + sparkConfPrefix, clientID, tenantID, clientSecretScope, clientSecretKey) - err = adlsGen1Mount.Create(client, clusterId) + err = adlsGen1Mount.Create(client, clusterID) if err != nil { return err } d.SetId(mountName) - err = d.Set("cluster_id", clusterId) + err = d.Set("cluster_id", clusterID) if err != nil { return err } @@ -110,11 +109,11 @@ func resourceAzureAdlsGen1Create(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - err = d.Set("tenant_id", tenantId) + err = d.Set("tenant_id", tenantID) if err != nil { return err } - err = d.Set("client_id", clientId) + err = d.Set("client_id", clientID) if err != nil { return err } @@ -135,8 +134,8 @@ func resourceAzureAdlsGen1Create(d *schema.ResourceData, m interface{}) error { } func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -144,15 +143,15 @@ func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error { sparkConfPrefix := d.Get("spark_conf_prefix").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) adlsGen1Mount := NewAzureADLSGen1Mount(storageResourceName, directory, mountName, - sparkConfPrefix, clientId, tenantId, clientSecretScope, clientSecretKey) + sparkConfPrefix, clientID, tenantID, clientSecretScope, clientSecretKey) - url, err := adlsGen1Mount.Read(client, clusterId) + url, err := adlsGen1Mount.Read(client, clusterID) if err != nil { //Reset id in case of inability to find mount if strings.Contains(err.Error(), "Unable to find mount point!") || @@ -173,8 +172,8 @@ func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error { func resourceAzureAdlsGen1Delete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -182,12 +181,12 @@ func resourceAzureAdlsGen1Delete(d *schema.ResourceData, m interface{}) error { sparkConfPrefix := d.Get("spark_conf_prefix").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) adlsGen1Mount := NewAzureADLSGen1Mount(storageResourceName, directory, mountName, - sparkConfPrefix, clientId, tenantId, clientSecretScope, clientSecretKey) - return adlsGen1Mount.Delete(client, clusterId) + sparkConfPrefix, clientID, tenantID, clientSecretScope, clientSecretKey) + return adlsGen1Mount.Delete(client, clusterID) } diff --git a/databricks/resource_databricks_azure_adls_gen2_mount.go b/databricks/resource_databricks_azure_adls_gen2_mount.go index f4a80ff29..1cd017e7f 100644 --- a/databricks/resource_databricks_azure_adls_gen2_mount.go +++ b/databricks/resource_databricks_azure_adls_gen2_mount.go @@ -39,9 +39,8 @@ func resourceAzureAdlsGen2Mount() *schema.Resource { directory := val.(string) if strings.HasPrefix(directory, "/") { return - } else { - errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) } + errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) return }, }, @@ -76,8 +75,8 @@ func resourceAzureAdlsGen2Mount() *schema.Resource { func resourceAzureAdlsGen2Create(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -85,21 +84,21 @@ func resourceAzureAdlsGen2Create(d *schema.ResourceData, m interface{}) error { storageAccountName := d.Get("storage_account_name").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) - adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientId, tenantId, + adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientID, tenantID, clientSecretScope, clientSecretKey) - err = adlsGen2Mount.Create(client, clusterId) + err = adlsGen2Mount.Create(client, clusterID) if err != nil { return err } d.SetId(mountName) - err = d.Set("cluster_id", clusterId) + err = d.Set("cluster_id", clusterID) if err != nil { return err } @@ -107,11 +106,11 @@ func resourceAzureAdlsGen2Create(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - err = d.Set("tenant_id", tenantId) + err = d.Set("tenant_id", tenantID) if err != nil { return err } - err = d.Set("client_id", clientId) + err = d.Set("client_id", clientID) if err != nil { return err } @@ -128,8 +127,8 @@ func resourceAzureAdlsGen2Create(d *schema.ResourceData, m interface{}) error { } func resourceAzureAdlsGen2Read(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -137,15 +136,15 @@ func resourceAzureAdlsGen2Read(d *schema.ResourceData, m interface{}) error { storageAccountName := d.Get("storage_account_name").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) - adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientId, tenantId, + adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientID, tenantID, clientSecretScope, clientSecretKey) - url, err := adlsGen2Mount.Read(client, clusterId) + url, err := adlsGen2Mount.Read(client, clusterID) if err != nil { //Reset id in case of inability to find mount if strings.Contains(err.Error(), "Unable to find mount point!") || @@ -170,8 +169,8 @@ func resourceAzureAdlsGen2Read(d *schema.ResourceData, m interface{}) error { func resourceAzureAdlsGen2Delete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -179,12 +178,12 @@ func resourceAzureAdlsGen2Delete(d *schema.ResourceData, m interface{}) error { storageAccountName := d.Get("storage_account_name").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) - adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientId, tenantId, + adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientID, tenantID, clientSecretScope, clientSecretKey) - return adlsGen2Mount.Delete(client, clusterId) + return adlsGen2Mount.Delete(client, clusterID) } diff --git a/databricks/resource_databricks_azure_blob_mount.go b/databricks/resource_databricks_azure_blob_mount.go index a68ff1547..5915e441e 100644 --- a/databricks/resource_databricks_azure_blob_mount.go +++ b/databricks/resource_databricks_azure_blob_mount.go @@ -40,9 +40,8 @@ func resourceAzureBlobMount() *schema.Resource { directory := val.(string) if strings.HasPrefix(directory, "/") { return - } else { - errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) } + errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) return }, }, @@ -73,8 +72,8 @@ func resourceAzureBlobMount() *schema.Resource { func resourceAzureBlobMountCreate(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -89,11 +88,11 @@ func resourceAzureBlobMountCreate(d *schema.ResourceData, m interface{}) error { blobMount := NewAzureBlobMount(containerName, storageAccountName, directory, mountName, authType, tokenSecretScope, tokenSecretKey) - err = blobMount.Create(client, clusterId) + err = blobMount.Create(client, clusterID) d.SetId(mountName) - err = d.Set("cluster_id", clusterId) + err = d.Set("cluster_id", clusterID) if err != nil { return err } @@ -118,8 +117,8 @@ func resourceAzureBlobMountCreate(d *schema.ResourceData, m interface{}) error { } func resourceAzureBlobMountRead(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -134,7 +133,7 @@ func resourceAzureBlobMountRead(d *schema.ResourceData, m interface{}) error { blobMount := NewAzureBlobMount(containerName, storageAccountName, directory, mountName, authType, tokenSecretScope, tokenSecretKey) - url, err := blobMount.Read(client, clusterId) + url, err := blobMount.Read(client, clusterID) if err != nil { //Reset id in case of inability to find mount if strings.Contains(err.Error(), "Unable to find mount point!") { @@ -158,8 +157,8 @@ func resourceAzureBlobMountRead(d *schema.ResourceData, m interface{}) error { func resourceAzureBlobMountDelete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -173,5 +172,5 @@ func resourceAzureBlobMountDelete(d *schema.ResourceData, m interface{}) error { blobMount := NewAzureBlobMount(containerName, storageAccountName, directory, mountName, authType, tokenSecretScope, tokenSecretKey) - return blobMount.Delete(client, clusterId) + return blobMount.Delete(client, clusterID) } diff --git a/databricks/resource_databricks_cluster.go b/databricks/resource_databricks_cluster.go index 7811694af..e9bfee317 100644 --- a/databricks/resource_databricks_cluster.go +++ b/databricks/resource_databricks_cluster.go @@ -1047,7 +1047,7 @@ func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error { return resourceClusterRead(d, m) } - return errors.New("Unable to edit cluster due to cluster state not being in a runnable/terminated state.") + return errors.New("unable to edit cluster due to cluster state not being in a runnable/terminated state") } func resourceClusterDelete(d *schema.ResourceData, m interface{}) error { @@ -1107,8 +1107,8 @@ func parseSchemaToCluster(d *schema.ResourceData, schemaAttPrefix string) model. if availability, ok := awsAttributesMap["availability"]; ok { awsAttributes.Availability = model.AwsAvailability(availability.(string)) } - if zoneId, ok := awsAttributesMap["zone_id"]; ok { - awsAttributes.ZoneID = zoneId.(string) + if zoneID, ok := awsAttributesMap["zone_id"]; ok { + awsAttributes.ZoneID = zoneID.(string) } if spotBidPricePercent, ok := awsAttributesMap["spot_bid_price_percent"]; ok { //val, _ := strconv.ParseInt(spotBidPricePercent.(string), 10, 32) @@ -1136,13 +1136,13 @@ func parseSchemaToCluster(d *schema.ResourceData, schemaAttPrefix string) model. } //Deal with driver node type id - if driverNodeTypeId, ok := d.GetOk(schemaAttPrefix + "driver_node_type_id"); ok { - cluster.DriverNodeTypeID = driverNodeTypeId.(string) + if driverNodeTypeID, ok := d.GetOk(schemaAttPrefix + "driver_node_type_id"); ok { + cluster.DriverNodeTypeID = driverNodeTypeID.(string) } //Deal with worker node type id - if nodeTypeId, ok := d.GetOk(schemaAttPrefix + "node_type_id"); ok { - cluster.NodeTypeID = nodeTypeId.(string) + if nodeTypeID, ok := d.GetOk(schemaAttPrefix + "node_type_id"); ok { + cluster.NodeTypeID = nodeTypeID.(string) } //Deal with worker ssh public keys @@ -1337,7 +1337,7 @@ func getMapFromOneItemSet(input interface{}) map[string]interface{} { return nil } -func isClusterMissing(errorMsg, resourceId string) bool { +func isClusterMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "INVALID_PARAMETER_VALUE") && - strings.Contains(errorMsg, fmt.Sprintf("Cluster %s does not exist", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("Cluster %s does not exist", resourceID)) } diff --git a/databricks/resource_databricks_dbfs_file.go b/databricks/resource_databricks_dbfs_file.go index 93d0347a2..a2dc4501c 100644 --- a/databricks/resource_databricks_dbfs_file.go +++ b/databricks/resource_databricks_dbfs_file.go @@ -144,7 +144,7 @@ func resourceDBFSFileDelete(d *schema.ResourceData, m interface{}) error { return err } -func isDBFSFileMissing(errorMsg, resourceId string) bool { +func isDBFSFileMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "RESOURCE_DOES_NOT_EXIST") && - strings.Contains(errorMsg, fmt.Sprintf("No file or directory exists on path %s.", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("No file or directory exists on path %s.", resourceID)) } diff --git a/databricks/resource_databricks_instance_pool.go b/databricks/resource_databricks_instance_pool.go index cac26a0fb..6d916fb88 100644 --- a/databricks/resource_databricks_instance_pool.go +++ b/databricks/resource_databricks_instance_pool.go @@ -163,8 +163,8 @@ func resourceInstancePoolCreate(d *schema.ResourceData, m interface{}) error { if availability, ok := awsAttributesMap["availability"]; ok { instancePoolAwsAttributes.Availability = model.AwsAvailability(availability.(string)) } - if zoneId, ok := awsAttributesMap["zone_id"]; ok { - instancePoolAwsAttributes.ZoneID = zoneId.(string) + if zoneID, ok := awsAttributesMap["zone_id"]; ok { + instancePoolAwsAttributes.ZoneID = zoneID.(string) } if spotBidPricePercent, ok := awsAttributesMap["spot_bid_price_percent"]; ok { //val, _ := strconv.ParseInt(spotBidPricePercent.(string), 10, 32) @@ -173,8 +173,8 @@ func resourceInstancePoolCreate(d *schema.ResourceData, m interface{}) error { instancePool.AwsAttributes = &instancePoolAwsAttributes } - if nodeTypeId, ok := d.GetOk("node_type_id"); ok { - instancePool.NodeTypeID = nodeTypeId.(string) + if nodeTypeID, ok := d.GetOk("node_type_id"); ok { + instancePool.NodeTypeID = nodeTypeID.(string) } if customTags, ok := d.GetOk("custom_tags"); ok { @@ -345,7 +345,7 @@ func resourceInstancePoolDelete(d *schema.ResourceData, m interface{}) error { return err } -func isInstancePoolMissing(errorMsg, resourceId string) bool { +func isInstancePoolMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "RESOURCE_DOES_NOT_EXIST") && - strings.Contains(errorMsg, fmt.Sprintf("Can't find an instance pool with id: %s", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("Can't find an instance pool with id: %s", resourceID)) } diff --git a/databricks/resource_databricks_instance_profile.go b/databricks/resource_databricks_instance_profile.go index 9dbab02b7..f9b178c2e 100644 --- a/databricks/resource_databricks_instance_profile.go +++ b/databricks/resource_databricks_instance_profile.go @@ -69,7 +69,7 @@ func resourceInstanceProfileDelete(d *schema.ResourceData, m interface{}) error return err } -func isInstanceProfileMissing(errorMsg, resourceId string) bool { +func isInstanceProfileMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, fmt.Sprintf("Instance profile with name: %s not found in "+ - "list of instance profiles in the workspace!", resourceId)) + "list of instance profiles in the workspace!", resourceID)) } diff --git a/databricks/resource_databricks_job.go b/databricks/resource_databricks_job.go index bd0f81416..e065ab6b2 100644 --- a/databricks/resource_databricks_job.go +++ b/databricks/resource_databricks_job.go @@ -869,8 +869,8 @@ func parseSchemaToJobSettings(d *schema.ResourceData) model.JobSettings { var jobSettings model.JobSettings - if existingClusterId, ok := d.GetOk("existing_cluster_id"); ok { - jobSettings.ExistingClusterID = existingClusterId.(string) + if existingClusterID, ok := d.GetOk("existing_cluster_id"); ok { + jobSettings.ExistingClusterID = existingClusterID.(string) } cluster := parseSchemaToCluster(d, "new_cluster.0.") @@ -1096,7 +1096,7 @@ func parseSchemaToLibraries(d *schema.ResourceData) []model.Library { return libraryList } -func isJobMissing(errorMsg, resourceId string) bool { +func isJobMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "INVALID_PARAMETER_VALUE") && - strings.Contains(errorMsg, fmt.Sprintf("Job %s does not exist.", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("Job %s does not exist.", resourceID)) } diff --git a/databricks/resource_databricks_notebook.go b/databricks/resource_databricks_notebook.go index 94d69f8ed..becc8d0aa 100644 --- a/databricks/resource_databricks_notebook.go +++ b/databricks/resource_databricks_notebook.go @@ -248,7 +248,7 @@ func getDBCCheckSumForCommands(fileIO io.ReadCloser) (int, error) { return int(crc32.ChecksumIEEE(commandsBuffer.Bytes())), nil } -func isNotebookMissing(errorMsg, resourceId string) bool { +func isNotebookMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "RESOURCE_DOES_NOT_EXIST") && - strings.Contains(errorMsg, fmt.Sprintf("Path (%s) doesn't exist.", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("Path (%s) doesn't exist.", resourceID)) } diff --git a/databricks/resource_databricks_scim_group.go b/databricks/resource_databricks_scim_group.go index b7de842ce..0060b035e 100644 --- a/databricks/resource_databricks_scim_group.go +++ b/databricks/resource_databricks_scim_group.go @@ -232,8 +232,8 @@ func resourceScimGroupDelete(d *schema.ResourceData, m interface{}) error { return err } -func isScimGroupMissing(errorMsg, resourceId string) bool { +func isScimGroupMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "urn:ietf:params:scim:api:messages:2.0:Error") && - strings.Contains(errorMsg, fmt.Sprintf("Group with id %s not found.", resourceId)) && + strings.Contains(errorMsg, fmt.Sprintf("Group with id %s not found.", resourceID)) && strings.Contains(errorMsg, "404") } diff --git a/databricks/resource_databricks_scim_user.go b/databricks/resource_databricks_scim_user.go index 71dd7e404..902527294 100644 --- a/databricks/resource_databricks_scim_user.go +++ b/databricks/resource_databricks_scim_user.go @@ -245,8 +245,8 @@ func resourceScimUserDelete(d *schema.ResourceData, m interface{}) error { return err } -func isScimUserMissing(errorMsg, resourceId string) bool { +func isScimUserMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "urn:ietf:params:scim:api:messages:2.0:Error") && - strings.Contains(errorMsg, fmt.Sprintf("User with id %s not found.", resourceId)) && + strings.Contains(errorMsg, fmt.Sprintf("User with id %s not found.", resourceID)) && strings.Contains(errorMsg, "404") } diff --git a/databricks/resource_databricks_scim_user_test.go b/databricks/resource_databricks_scim_user_test.go index eb2976f23..c091cc8c6 100644 --- a/databricks/resource_databricks_scim_user_test.go +++ b/databricks/resource_databricks_scim_user_test.go @@ -56,7 +56,7 @@ func testScimUserResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource Scim User is not cleaned up!") + return errors.New("resource Scim User is not cleaned up") } return nil } diff --git a/databricks/resource_databricks_secret.go b/databricks/resource_databricks_secret.go index bb00a3894..fb3e3c9f1 100644 --- a/databricks/resource_databricks_secret.go +++ b/databricks/resource_databricks_secret.go @@ -39,12 +39,12 @@ func resourceSecret() *schema.Resource { } } -func getSecretId(scope string, key string) (string, error) { +func getSecretID(scope string, key string) (string, error) { return scope + "|||" + key, nil } -func getScopeAndKeyFromSecretId(secretIdString string) (string, string, error) { - return strings.Split(secretIdString, "|||")[0], strings.Split(secretIdString, "|||")[1], nil +func getScopeAndKeyFromSecretID(secretIDString string) (string, string, error) { + return strings.Split(secretIDString, "|||")[0], strings.Split(secretIDString, "|||")[1], nil } func resourceSecretCreate(d *schema.ResourceData, m interface{}) error { @@ -56,7 +56,7 @@ func resourceSecretCreate(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - id, err := getSecretId(scopeName, key) + id, err := getSecretID(scopeName, key) if err != nil { return err } @@ -67,7 +67,7 @@ func resourceSecretCreate(d *schema.ResourceData, m interface{}) error { func resourceSecretRead(d *schema.ResourceData, m interface{}) error { id := d.Id() client := m.(service.DBApiClient) - scope, key, err := getScopeAndKeyFromSecretId(id) + scope, key, err := getScopeAndKeyFromSecretID(id) if err != nil { return err } @@ -101,7 +101,7 @@ func resourceSecretRead(d *schema.ResourceData, m interface{}) error { func resourceSecretDelete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) id := d.Id() - scope, key, err := getScopeAndKeyFromSecretId(id) + scope, key, err := getScopeAndKeyFromSecretID(id) if err != nil { return err } diff --git a/databricks/resource_databricks_secret_acl.go b/databricks/resource_databricks_secret_acl.go index 4a7530d4d..d95c7b7c1 100644 --- a/databricks/resource_databricks_secret_acl.go +++ b/databricks/resource_databricks_secret_acl.go @@ -9,11 +9,11 @@ import ( "strings" ) -func resourceSecretAcl() *schema.Resource { +func resourceSecretACL() *schema.Resource { return &schema.Resource{ - Create: resourceSecretAclCreate, - Read: resourceSecretAclRead, - Delete: resourceSecretAclDelete, + Create: resourceSecretACLCreate, + Read: resourceSecretACLRead, + Delete: resourceSecretACLDelete, Schema: map[string]*schema.Schema{ "scope": &schema.Schema{ @@ -35,17 +35,15 @@ func resourceSecretAcl() *schema.Resource { } } -type SecretAclId map[string]string - -func getSecretAclId(scope string, key string) (string, error) { +func getSecretACLID(scope string, key string) (string, error) { return scope + "|||" + key, nil } -func getScopeAndKeyFromSecretAclId(SecretAclIdString string) (string, string, error) { - return strings.Split(SecretAclIdString, "|||")[0], strings.Split(SecretAclIdString, "|||")[1], nil +func getScopeAndKeyFromSecretACLID(SecretACLIDString string) (string, string, error) { + return strings.Split(SecretACLIDString, "|||")[0], strings.Split(SecretACLIDString, "|||")[1], nil } -func resourceSecretAclCreate(d *schema.ResourceData, m interface{}) error { +func resourceSecretACLCreate(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) scopeName := d.Get("scope").(string) principal := d.Get("principal").(string) @@ -54,24 +52,24 @@ func resourceSecretAclCreate(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - id, err := getSecretAclId(scopeName, principal) + id, err := getSecretACLID(scopeName, principal) if err != nil { return err } d.SetId(id) - return resourceSecretAclRead(d, m) + return resourceSecretACLRead(d, m) } -func resourceSecretAclRead(d *schema.ResourceData, m interface{}) error { +func resourceSecretACLRead(d *schema.ResourceData, m interface{}) error { id := d.Id() - scope, principal, err := getScopeAndKeyFromSecretAclId(id) + scope, principal, err := getScopeAndKeyFromSecretACLID(id) if err != nil { return err } client := m.(service.DBApiClient) - secretAcl, err := client.SecretAcls().Read(scope, principal) + secretACL, err := client.SecretAcls().Read(scope, principal) if err != nil { - if isSecretAclMissing(err.Error(), scope, principal) { + if isSecretACLMissing(err.Error(), scope, principal) { log.Printf("Missing secret acl in scope with id: %s and principal: %s.", scope, principal) d.SetId("") return nil @@ -86,14 +84,14 @@ func resourceSecretAclRead(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - err = d.Set("permission", secretAcl.Permission) + err = d.Set("permission", secretACL.Permission) return err } -func resourceSecretAclDelete(d *schema.ResourceData, m interface{}) error { +func resourceSecretACLDelete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) id := d.Id() - scope, key, err := getScopeAndKeyFromSecretAclId(id) + scope, key, err := getScopeAndKeyFromSecretACLID(id) if err != nil { return err } @@ -101,7 +99,7 @@ func resourceSecretAclDelete(d *schema.ResourceData, m interface{}) error { return err } -func isSecretAclMissing(errorMsg, scope string, principal string) bool { +func isSecretACLMissing(errorMsg, scope string, principal string) bool { return strings.Contains(errorMsg, "RESOURCE_DOES_NOT_EXIST") && strings.Contains(errorMsg, fmt.Sprintf("Failed to get secret acl for principal %s for scope %s.", principal, scope)) } diff --git a/databricks/resource_databricks_secret_acl_test.go b/databricks/resource_databricks_secret_acl_test.go index 991c41158..100660ed7 100644 --- a/databricks/resource_databricks_secret_acl_test.go +++ b/databricks/resource_databricks_secret_acl_test.go @@ -13,7 +13,7 @@ import ( func TestAccSecretAclResource(t *testing.T) { //var secretScope model.Secre - var secretAcl model.ACLItem + var secretACL model.ACLItem // generate a random name for each tokenInfo test run, to avoid // collisions from multiple concurrent tests. // the acctest package includes many helpers such as RandStringFromCharSet @@ -26,17 +26,17 @@ func TestAccSecretAclResource(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testSecretAclResourceDestroy, + CheckDestroy: testSecretACLResourceDestroy, Steps: []resource.TestStep{ { // use a dynamic configuration with the random name from above - Config: testSecretAclResource(scope, principal, permission), + Config: testSecretACLResource(scope, principal, permission), // compose a basic test, checking both remote and local values Check: resource.ComposeTestCheckFunc( // query the API to retrieve the tokenInfo object - testSecretAclResourceExists("databricks_secret_acl.my_secret_acl", &secretAcl, t), + testSecretACLResourceExists("databricks_secret_acl.my_secret_acl", &secretACL, t), // verify remote values - testSecretAclValues(t, &secretAcl, permission, principal), + testSecretACLValues(t, &secretACL, permission, principal), // verify local values resource.TestCheckResourceAttr("databricks_secret_acl.my_secret_acl", "scope", scope), resource.TestCheckResourceAttr("databricks_secret_acl.my_secret_acl", "principal", principal), @@ -47,7 +47,7 @@ func TestAccSecretAclResource(t *testing.T) { }) } -func testSecretAclResourceDestroy(s *terraform.State) error { +func testSecretACLResourceDestroy(s *terraform.State) error { client := testAccProvider.Meta().(service.DBApiClient) for _, rs := range s.RootModule().Resources { if rs.Type != "databricks_secret_acl" { @@ -57,16 +57,16 @@ func testSecretAclResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource secret acl is not cleaned up!") + return errors.New("resource secret acl is not cleaned up") } return nil } -func testSecretAclPreCheck(t *testing.T) { +func testSecretACLPreCheck(t *testing.T) { return } -func testSecretAclValues(t *testing.T, acl *model.ACLItem, permission, principal string) resource.TestCheckFunc { +func testSecretACLValues(t *testing.T, acl *model.ACLItem, permission, principal string) resource.TestCheckFunc { return func(s *terraform.State) error { assert.True(t, acl.Permission == model.ACLPermissionRead) assert.True(t, acl.Principal == principal) @@ -75,7 +75,7 @@ func testSecretAclValues(t *testing.T, acl *model.ACLItem, permission, principal } // testAccCheckTokenResourceExists queries the API and retrieves the matching Widget. -func testSecretAclResourceExists(n string, aclItem *model.ACLItem, t *testing.T) resource.TestCheckFunc { +func testSecretACLResourceExists(n string, aclItem *model.ACLItem, t *testing.T) resource.TestCheckFunc { return func(s *terraform.State) error { // find the corresponding state object rs, ok := s.RootModule().Resources[n] @@ -99,7 +99,7 @@ func testSecretAclResourceExists(n string, aclItem *model.ACLItem, t *testing.T) } // testAccTokenResource returns an configuration for an Example Widget with the provided name -func testSecretAclResource(scopeName, principal, permission string) string { +func testSecretACLResource(scopeName, principal, permission string) string { return fmt.Sprintf(` resource "databricks_secret_scope" "my_scope" { name = "%s" diff --git a/databricks/resource_databricks_secret_scope.go b/databricks/resource_databricks_secret_scope.go index 45046bc18..b3ddfdd0b 100644 --- a/databricks/resource_databricks_secret_scope.go +++ b/databricks/resource_databricks_secret_scope.go @@ -74,6 +74,6 @@ func resourceSecretScopeDelete(d *schema.ResourceData, m interface{}) error { return err } -func isSecretScopeMissing(errorMsg, resourceId string) bool { - return strings.Contains(errorMsg, fmt.Sprintf("No Secret Scope found with scope name %s.", resourceId)) +func isSecretScopeMissing(errorMsg, resourceID string) bool { + return strings.Contains(errorMsg, fmt.Sprintf("no Secret Scope found with scope name %s", resourceID)) } diff --git a/databricks/resource_databricks_secret_scope_test.go b/databricks/resource_databricks_secret_scope_test.go index 4d2d085e0..1bbda725e 100644 --- a/databricks/resource_databricks_secret_scope_test.go +++ b/databricks/resource_databricks_secret_scope_test.go @@ -54,7 +54,7 @@ func testSecretScopeResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource token is not cleaned up!") + return errors.New("resource token is not cleaned up") } return nil } diff --git a/databricks/resource_databricks_secret_test.go b/databricks/resource_databricks_secret_test.go index 9d91990ab..2750a883c 100644 --- a/databricks/resource_databricks_secret_test.go +++ b/databricks/resource_databricks_secret_test.go @@ -57,7 +57,7 @@ func testSecretResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource secret is not cleaned up!") + return errors.New("resource secret is not cleaned up") } return nil } diff --git a/databricks/resource_databricks_token.go b/databricks/resource_databricks_token.go index 26e8706e7..fc3094176 100644 --- a/databricks/resource_databricks_token.go +++ b/databricks/resource_databricks_token.go @@ -83,12 +83,12 @@ func resourceTokenRead(d *schema.ResourceData, m interface{}) error { } func resourceTokenDelete(d *schema.ResourceData, m interface{}) error { - tokenId := d.Id() + tokenID := d.Id() client := m.(service.DBApiClient) - err := client.Tokens().Delete(tokenId) + err := client.Tokens().Delete(tokenID) return err } -func isTokenMissing(errorMsg, resourceId string) bool { - return strings.Contains(errorMsg, fmt.Sprintf("Unable to locate token: %s", resourceId)) +func isTokenMissing(errorMsg, resourceID string) bool { + return strings.Contains(errorMsg, fmt.Sprintf("Unable to locate token: %s", resourceID)) } diff --git a/databricks/resource_databricks_token_test.go b/databricks/resource_databricks_token_test.go index a47df2b31..e25890984 100644 --- a/databricks/resource_databricks_token_test.go +++ b/databricks/resource_databricks_token_test.go @@ -53,7 +53,7 @@ func testAccCheckTokenResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource token is not cleaned up!") + return errors.New("resource token is not cleaned up") } return nil } @@ -65,7 +65,7 @@ func testAccPreCheck(t *testing.T) { func testAccCheckTokenValues(tokenInfo *model.TokenInfo, comment string) resource.TestCheckFunc { return func(s *terraform.State) error { if tokenInfo.Comment != comment { - return errors.New("The comment for the token created does not equal the value passed in!") + return errors.New("the comment for the token created does not equal the value passed in") } return nil } diff --git a/databricks/utils.go b/databricks/utils.go index 95d7df6a9..ed7f9b0d9 100644 --- a/databricks/utils.go +++ b/databricks/utils.go @@ -19,51 +19,49 @@ type typeCheckerReturnString interface { setNext(typeCheckerReturnString) } -type StringChecker struct { +type stringChecker struct { next typeCheckerReturnString } -func (r *StringChecker) execute(p interface{}) string { +func (r *stringChecker) execute(p interface{}) string { stringVal, ok := p.(string) if ok { if len(stringVal) > 0 { return stringVal - } else { - return "" } + return "" } return r.next.execute(p) } -func (r *StringChecker) setNext(next typeCheckerReturnString) { +func (r *stringChecker) setNext(next typeCheckerReturnString) { r.next = next } -type IntChecker struct { +type intChecker struct { next typeCheckerReturnString } -func (r *IntChecker) execute(p interface{}) string { +func (r *intChecker) execute(p interface{}) string { intVal, ok := p.(int) if ok { if intVal > 0 { return strconv.Itoa(intVal) - } else { - return "" } + return "" } return r.next.execute(p) } -func (r *IntChecker) setNext(next typeCheckerReturnString) { +func (r *intChecker) setNext(next typeCheckerReturnString) { r.next = next } -type BoolChecker struct { +type boolChecker struct { next typeCheckerReturnString } -func (r *BoolChecker) execute(p interface{}) string { +func (r *boolChecker) execute(p interface{}) string { boolVal, ok := p.(bool) if ok { return strconv.FormatBool(boolVal) @@ -71,15 +69,15 @@ func (r *BoolChecker) execute(p interface{}) string { return r.next.execute(p) } -func (r *BoolChecker) setNext(next typeCheckerReturnString) { +func (r *boolChecker) setNext(next typeCheckerReturnString) { r.next = next } -type StringSliceChecker struct { +type stringSliceChecker struct { next typeCheckerReturnString } -func (r *StringSliceChecker) execute(p interface{}) string { +func (r *stringSliceChecker) execute(p interface{}) string { sliceVal, ok := p.([]string) if ok { var stringSlice []string @@ -88,20 +86,19 @@ func (r *StringSliceChecker) execute(p interface{}) string { } sort.Strings(stringSlice) return strings.Join(stringSlice, "") - } else { - return "" } + return "" } -func (r *StringSliceChecker) setNext(next typeCheckerReturnString) { +func (r *stringSliceChecker) setNext(next typeCheckerReturnString) { r.next = next } func fetchStringFromCheckers(strVal interface{}) string { - stringChecker := &StringChecker{} - intChecker := &IntChecker{} - boolChecker := &BoolChecker{} - sliceChecker := &StringSliceChecker{} + stringChecker := &stringChecker{} + intChecker := &intChecker{} + boolChecker := &boolChecker{} + sliceChecker := &stringSliceChecker{} stringChecker.setNext(intChecker) intChecker.setNext(boolChecker) boolChecker.setNext(sliceChecker) @@ -114,7 +111,7 @@ func mapHash(v interface{}) int { m := v.(map[string]interface{}) var keys []string - for k, _ := range m { + for k := range m { keys = append(keys, k) } sort.Strings(keys) @@ -181,9 +178,9 @@ func determineAwsAttributesDiff(diff *schema.ResourceDiff, m interface{}) error return err } -func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) error { +func changeClusterIntoRunningState(clusterID string, client service.DBApiClient) error { //return nil - clusterInfo, err := client.Clusters().Get(clusterId) + clusterInfo, err := client.Clusters().Get(clusterID) if err != nil { return err } @@ -195,7 +192,7 @@ func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) } if model.ContainsClusterState([]model.ClusterState{model.ClusterStatePending, model.ClusterStateResizing, model.ClusterStateRestarting}, currentState) { - err := client.Clusters().WaitForClusterRunning(clusterId, 5, 180) + err := client.Clusters().WaitForClusterRunning(clusterID, 5, 180) if err != nil { return err } @@ -204,17 +201,17 @@ func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) } if model.ContainsClusterState([]model.ClusterState{model.ClusterStateTerminating}, currentState) { - err := client.Clusters().WaitForClusterTerminated(clusterId, 5, 180) + err := client.Clusters().WaitForClusterTerminated(clusterID, 5, 180) if err != nil { return err } - err = client.Clusters().Start(clusterId) + err = client.Clusters().Start(clusterID) if err != nil { - if !strings.Contains(err.Error(), fmt.Sprintf("Cluster %s is in unexpected state Pending.", clusterId)) { + if !strings.Contains(err.Error(), fmt.Sprintf("Cluster %s is in unexpected state Pending.", clusterID)) { return err } } - err = client.Clusters().WaitForClusterRunning(clusterId, 5, 180) + err = client.Clusters().WaitForClusterRunning(clusterID, 5, 180) if err != nil { return err } @@ -223,14 +220,14 @@ func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) } if model.ContainsClusterState([]model.ClusterState{model.ClusterStateTerminated}, currentState) { - err = client.Clusters().Start(clusterId) + err = client.Clusters().Start(clusterID) if err != nil { - if !strings.Contains(err.Error(), fmt.Sprintf("Cluster %s is in unexpected state Pending.", clusterId)) { + if !strings.Contains(err.Error(), fmt.Sprintf("Cluster %s is in unexpected state Pending.", clusterID)) { return err } } - err = client.Clusters().WaitForClusterRunning(clusterId, 5, 180) + err = client.Clusters().WaitForClusterRunning(clusterID, 5, 180) if err != nil { return err } @@ -238,6 +235,6 @@ func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) return nil } - return errors.New(fmt.Sprintf("Cluster is in a non recoverable state: %s!", currentState)) + return fmt.Errorf("cluster is in a non recoverable state: %s", currentState) } From 90cbd312540ad25d68aa1cda4f9915f33b6245f8 Mon Sep 17 00:00:00 2001 From: Sriharsha Tikkireddy Date: Mon, 20 Apr 2020 12:28:14 -0400 Subject: [PATCH 4/5] reformatted code after linting --- client/model/cluster.go | 67 ++++++++++++++++++------------------- client/model/group.go | 4 +-- client/model/job.go | 14 ++++---- databricks/azure_ws_init.go | 2 +- databricks/provider.go | 26 +++++++------- 5 files changed, 56 insertions(+), 57 deletions(-) diff --git a/client/model/cluster.go b/client/model/cluster.go index ba3636e7e..c70185b69 100644 --- a/client/model/cluster.go +++ b/client/model/cluster.go @@ -11,9 +11,9 @@ type AwsAvailability string const ( // AwsAvailabilitySpot is spot instance type for clusters - AwsAvailabilitySpot = "SPOT" + AwsAvailabilitySpot = "SPOT" // AwsAvailabilityOnDemand is OnDemand instance type for clusters - AwsAvailabilityOnDemand = "ON_DEMAND" + AwsAvailabilityOnDemand = "ON_DEMAND" // AwsAvailabilitySpotWithFallback is Spot instance type for clusters with option // to fallback into on-demand if instance cannot be acquired AwsAvailabilitySpotWithFallback = "SPOT_WITH_FALLBACK" @@ -26,7 +26,7 @@ const ( // AzureDiskVolumeTypeStandard is for standard local redundant storage AzureDiskVolumeTypeStandard = "STANDARD_LRS" // AzureDiskVolumeTypePremium is for premium local redundant storage - AzureDiskVolumeTypePremium = "PREMIUM_LRS" + AzureDiskVolumeTypePremium = "PREMIUM_LRS" ) // EbsVolumeType is disk type on aws vms @@ -34,39 +34,38 @@ type EbsVolumeType string const ( // EbsVolumeTypeGeneralPurposeSsd is general purpose ssd (starts at 32 gb) - EbsVolumeTypeGeneralPurposeSsd = "GENERAL_PURPOSE_SSD" + EbsVolumeTypeGeneralPurposeSsd = "GENERAL_PURPOSE_SSD" // EbsVolumeTypeThroughputOptimizedHdd is throughput optimized hdd (starts at 500 gb) EbsVolumeTypeThroughputOptimizedHdd = "THROUGHPUT_OPTIMIZED_HDD" ) - // ClusterState is for describing possible cluster states type ClusterState string const ( // ClusterStatePending is for PENDING state - ClusterStatePending = "PENDING" + ClusterStatePending = "PENDING" // ClusterStateRunning is for RUNNING state - ClusterStateRunning = "RUNNING" + ClusterStateRunning = "RUNNING" // ClusterStateRestarting is for RESTARTING state - ClusterStateRestarting = "RESTARTING" + ClusterStateRestarting = "RESTARTING" // ClusterStateResizing is for RESIZING state - ClusterStateResizing = "RESIZING" + ClusterStateResizing = "RESIZING" // ClusterStateTerminating is for TERMINATING state ClusterStateTerminating = "TERMINATING" // ClusterStateTerminated is for TERMINATED state - ClusterStateTerminated = "TERMINATED" + ClusterStateTerminated = "TERMINATED" // ClusterStateError is for ERROR state - ClusterStateError = "ERROR" + ClusterStateError = "ERROR" // ClusterStateUnknown is for UNKNOWN state - ClusterStateUnknown = "UNKNOWN" + ClusterStateUnknown = "UNKNOWN" ) // ClusterStateNonRunnable is a list of states in which the cluster cannot go back into running by itself @@ -188,14 +187,14 @@ type DockerImage struct { // Cluster contains the information when trying to submit api calls or editing a cluster type Cluster struct { - ClusterID string `json:"cluster_id,omitempty"` - NumWorkers int32 `json:"num_workers,omitempty"` - Autoscale *AutoScale `json:"autoscale,omitempty"` - ClusterName string `json:"cluster_name,omitempty"` - SparkVersion string `json:"spark_version,omitempty"` - SparkConf map[string]string `json:"spark_conf,omitempty"` - AwsAttributes *AwsAttributes `json:"aws_attributes,omitempty"` - NodeTypeID string `json:"node_type_id,omitempty"` + ClusterID string `json:"cluster_id,omitempty"` + NumWorkers int32 `json:"num_workers,omitempty"` + Autoscale *AutoScale `json:"autoscale,omitempty"` + ClusterName string `json:"cluster_name,omitempty"` + SparkVersion string `json:"spark_version,omitempty"` + SparkConf map[string]string `json:"spark_conf,omitempty"` + AwsAttributes *AwsAttributes `json:"aws_attributes,omitempty"` + NodeTypeID string `json:"node_type_id,omitempty"` DriverNodeTypeID string `json:"driver_node_type_id,omitempty"` SSHPublicKeys []string `json:"ssh_public_keys,omitempty"` CustomTags map[string]string `json:"custom_tags,omitempty"` @@ -225,20 +224,20 @@ type ClusterInfo struct { AwsAttributes *AwsAttributes `json:"aws_attributes,omitempty"` NodeTypeID string `json:"node_type_id,omitempty"` DriverNodeTypeID string `json:"driver_node_type_id,omitempty"` - SSHPublicKeys []string `json:"ssh_public_keys,omitempty"` - CustomTags map[string]string `json:"custom_tags,omitempty"` - ClusterLogConf *StorageInfo `json:"cluster_log_conf,omitempty"` - InitScripts []StorageInfo `json:"init_scripts,omitempty"` - SparkEnvVars map[string]string `json:"spark_env_vars,omitempty"` - AutoterminationMinutes int32 `json:"autotermination_minutes,omitempty"` - EnableElasticDisk bool `json:"enable_elastic_disk,omitempty"` - InstancePoolID string `json:"instance_pool_id,omitempty"` - ClusterSource AwsAvailability `json:"cluster_source,omitempty"` - DockerImage *DockerImage `json:"docker_image,omitempty"` - State ClusterState `json:"state,omitempty"` - StateMessage string `json:"state_message,omitempty"` - StartTime int64 `json:"start_time,omitempty"` - TerminateTime int64 `json:"terminate_time,omitempty"` + SSHPublicKeys []string `json:"ssh_public_keys,omitempty"` + CustomTags map[string]string `json:"custom_tags,omitempty"` + ClusterLogConf *StorageInfo `json:"cluster_log_conf,omitempty"` + InitScripts []StorageInfo `json:"init_scripts,omitempty"` + SparkEnvVars map[string]string `json:"spark_env_vars,omitempty"` + AutoterminationMinutes int32 `json:"autotermination_minutes,omitempty"` + EnableElasticDisk bool `json:"enable_elastic_disk,omitempty"` + InstancePoolID string `json:"instance_pool_id,omitempty"` + ClusterSource AwsAvailability `json:"cluster_source,omitempty"` + DockerImage *DockerImage `json:"docker_image,omitempty"` + State ClusterState `json:"state,omitempty"` + StateMessage string `json:"state_message,omitempty"` + StartTime int64 `json:"start_time,omitempty"` + TerminateTime int64 `json:"terminate_time,omitempty"` LastStateLossTime int64 `json:"last_state_loss_time,omitempty"` LastActivityTime int64 `json:"last_activity_time,omitempty"` ClusterMemoryMb int64 `json:"cluster_memory_mb,omitempty"` diff --git a/client/model/group.go b/client/model/group.go index 0b087fc17..81428c2a4 100644 --- a/client/model/group.go +++ b/client/model/group.go @@ -18,10 +18,10 @@ type GroupPathType string const ( // GroupMembersPath is the members path for SCIM patch operation. - GroupMembersPath GroupPathType = "members" + GroupMembersPath GroupPathType = "members" // GroupRolesPath is the roles path for SCIM patch operation. - GroupRolesPath GroupPathType = "roles" + GroupRolesPath GroupPathType = "roles" // GroupEntitlementsPath is the entitlements path for SCIM patch operation. GroupEntitlementsPath GroupPathType = "entitlements" diff --git a/client/model/job.go b/client/model/job.go index f9140dab9..da530fd0c 100644 --- a/client/model/job.go +++ b/client/model/job.go @@ -40,13 +40,13 @@ type CronSchedule struct { // JobSettings contains the information for configuring a job on databricks type JobSettings struct { - ExistingClusterID string `json:"existing_cluster_id,omitempty"` - NewCluster *Cluster `json:"new_cluster,omitempty"` - NotebookTask *NotebookTask `json:"notebook_task,omitempty"` - SparkJarTask *SparkJarTask `json:"spark_jar_task,omitempty"` - SparkPythonTask *SparkPythonTask `json:"spark_python_task,omitempty"` - SparkSubmitTask *SparkSubmitTask `json:"spark_submit_task,omitempty"` - Name string `json:"name,omitempty"` + ExistingClusterID string `json:"existing_cluster_id,omitempty"` + NewCluster *Cluster `json:"new_cluster,omitempty"` + NotebookTask *NotebookTask `json:"notebook_task,omitempty"` + SparkJarTask *SparkJarTask `json:"spark_jar_task,omitempty"` + SparkPythonTask *SparkPythonTask `json:"spark_python_task,omitempty"` + SparkSubmitTask *SparkSubmitTask `json:"spark_submit_task,omitempty"` + Name string `json:"name,omitempty"` Libraries []Library `json:"libraries,omitempty"` EmailNotifications *JobEmailNotifications `json:"email_notifications,omitempty"` TimeoutSeconds int32 `json:"timeout_seconds,omitempty"` diff --git a/databricks/azure_ws_init.go b/databricks/azure_ws_init.go index 3154e0511..894f8666d 100644 --- a/databricks/azure_ws_init.go +++ b/databricks/azure_ws_init.go @@ -7,7 +7,7 @@ import ( "net/http" ) -// List of management information +// List of management information const ( ManagementResourceEndpoint string = "https://management.core.windows.net/" ADBResourceID string = "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d" diff --git a/databricks/provider.go b/databricks/provider.go index 0406a35e2..849e9aaf8 100644 --- a/databricks/provider.go +++ b/databricks/provider.go @@ -19,19 +19,19 @@ func Provider() terraform.ResourceProvider { "databricks_zones": dataSourceClusterZones(), }, ResourcesMap: map[string]*schema.Resource{ - "databricks_token": resourceToken(), - "databricks_secret_scope": resourceSecretScope(), - "databricks_secret": resourceSecret(), - "databricks_secret_acl": resourceSecretACL(), - "databricks_instance_pool": resourceInstancePool(), - "databricks_scim_user": resourceScimUser(), - "databricks_scim_group": resourceScimGroup(), - "databricks_notebook": resourceNotebook(), - "databricks_cluster": resourceCluster(), - "databricks_job": resourceJob(), - "databricks_dbfs_file": resourceDBFSFile(), - "databricks_dbfs_file_sync": resourceDBFSFileSync(), - "databricks_instance_profile": resourceInstanceProfile(), + "databricks_token": resourceToken(), + "databricks_secret_scope": resourceSecretScope(), + "databricks_secret": resourceSecret(), + "databricks_secret_acl": resourceSecretACL(), + "databricks_instance_pool": resourceInstancePool(), + "databricks_scim_user": resourceScimUser(), + "databricks_scim_group": resourceScimGroup(), + "databricks_notebook": resourceNotebook(), + "databricks_cluster": resourceCluster(), + "databricks_job": resourceJob(), + "databricks_dbfs_file": resourceDBFSFile(), + "databricks_dbfs_file_sync": resourceDBFSFileSync(), + "databricks_instance_profile": resourceInstanceProfile(), "databricks_aws_s3_mount": resourceAWSS3Mount(), "databricks_azure_blob_mount": resourceAzureBlobMount(), "databricks_azure_adls_gen1_mount": resourceAzureAdlsGen1Mount(), From 36022efd8a892d383c7435994e84da63ba897494 Mon Sep 17 00:00:00 2001 From: Sriharsha Tikkireddy Date: Mon, 20 Apr 2020 12:30:42 -0400 Subject: [PATCH 5/5] added linting to the build target and fmt target --- Makefile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5a5a2c8e4..5fee4a872 100644 --- a/Makefile +++ b/Makefile @@ -18,11 +18,16 @@ coverage-int: int int-build: int build -build: +build: fmt @echo "==> Building source code with go build..." @go build -mod vendor -v -o terraform-provider-databricks -fmt: +lint: + @echo "==> Linting source code with golint..." + @golint -set_exit_status ./databricks/... + @golint -set_exit_status ./client/... + +fmt: lint @echo "==> Formatting source code with gofmt..." @go fmt ./... @@ -54,7 +59,7 @@ terraform-acc: fmt build @echo "==> Running Terraform Acceptance Tests..." @TF_ACC=1 go test -v -short ./databricks/... -terraform-setup: fmt build +terraform-setup: build @echo "==> Initializing Terraform..." @terraform init