databricks-sdk-golang/aws/instance_profiles.go

58 lines
1.7 KiB
Go
Raw Permalink Normal View History

2019-05-27 21:29:27 +00:00
package aws
2019-05-27 20:42:37 +00:00
2019-05-29 01:01:48 +00:00
import (
"encoding/json"
"net/http"
2021-04-07 14:01:52 +00:00
"github.com/FlipsideCrypto/databricks-sdk-golang/aws/models"
2019-05-29 01:01:48 +00:00
)
2019-05-27 20:42:37 +00:00
// InstanceProfilesAPI exposes the Instance Profiles API
type InstanceProfilesAPI struct {
2019-05-29 00:33:54 +00:00
Client DBClient
2019-05-27 20:42:37 +00:00
}
2019-05-29 00:33:54 +00:00
func (a InstanceProfilesAPI) init(client DBClient) InstanceProfilesAPI {
a.Client = client
return a
}
2019-05-29 01:01:48 +00:00
// Add registers an instance profile in Databricks
func (a InstanceProfilesAPI) Add(instanceProfileArn string, skipValidation bool) error {
data := struct {
InstanceProfileArn string `json:"instance_profile_arn,omitempty" url:"instance_profile_arn,omitempty"`
SkipValidation bool `json:"skip_validation,omitempty" url:"skip_validation,omitempty"`
}{
instanceProfileArn,
skipValidation,
}
_, err := a.Client.performQuery(http.MethodPost, "/instance-profiles/add", data, nil)
return err
}
// List lists the instance profiles that the calling user can use to launch a cluster
func (a InstanceProfilesAPI) List() ([]models.InstanceProfile, error) {
2019-05-29 02:00:58 +00:00
var listResponse struct {
InstanceProfiles []models.InstanceProfile `json:"instance_profiles,omitempty" url:"instance_profiles,omitempty"`
}
2019-05-29 01:01:48 +00:00
resp, err := a.Client.performQuery(http.MethodGet, "/instance-profiles/list", nil, nil)
if err != nil {
return listResponse.InstanceProfiles, err
}
err = json.Unmarshal(resp, &listResponse)
return listResponse.InstanceProfiles, err
}
// Remove removes the instance profile with the provided ARN
func (a InstanceProfilesAPI) Remove(instanceProfileArn string) error {
data := struct {
InstanceProfileArn string `json:"instance_profile_arn,omitempty" url:"instance_profile_arn,omitempty"`
}{
instanceProfileArn,
}
_, err := a.Client.performQuery(http.MethodPost, "/instance-profiles/remove", data, nil)
return err
}