This repository was archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofiles_service.go
126 lines (114 loc) · 2.63 KB
/
profiles_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package databricks
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
)
// ProfilesService is a service for interacting with the DBFS.
type ProfilesService struct {
client Client
}
// Add registers an instance profile in Databricks. In the UI, you can then
// give users the permission to use this instance profile when launching
// clusters. This API is only available to admin users.
func (s *ProfilesService) Add(
ctx context.Context,
profileARN string,
skipValidation bool,
) error {
raw, err := json.Marshal(struct {
InstanceProfileARN string
SkipValidation bool
}{
profileARN,
skipValidation,
})
if err != nil {
return err
}
req, err := http.NewRequest(
http.MethodPost,
s.client.url+"2.0/instance-profiles/add",
bytes.NewBuffer(raw),
)
if err != nil {
return err
}
req = req.WithContext(ctx)
res, err := s.client.client.Do(req)
if err != nil {
return err
}
if res.StatusCode >= 300 || res.StatusCode <= 199 {
return fmt.Errorf(
"Failed to returns 2XX response: %d", res.StatusCode)
}
return nil
}
// List is used to return the instance profiles that the calling user can use
// to launch a cluster. This API is available to all users.
func (s *ProfilesService) List(
ctx context.Context,
) ([]string, error) {
req, err := http.NewRequest(
http.MethodGet,
s.client.url+"2.0/instance-profiles/get",
nil,
)
if err != nil {
return []string{}, err
}
req = req.WithContext(ctx)
res, err := s.client.client.Do(req)
if err != nil {
return []string{}, err
}
if res.StatusCode >= 300 || res.StatusCode <= 199 {
return []string{}, fmt.Errorf(
"Failed to returns 2XX response: %d", res.StatusCode)
}
defer res.Body.Close()
decoder := json.NewDecoder(res.Body)
listRes := struct {
InstanceProfiles []string
}{[]string{}}
err = decoder.Decode(&listRes)
return listRes.InstanceProfiles, err
}
// Remove is used to Remove the instance profile with the provided ARN.
// Existing clusters with this instance profile will continue to function.
//
// This API is only accessible to admin users.
func (s *ProfilesService) Remove(
ctx context.Context,
profileARN string,
) error {
raw, err := json.Marshal(struct {
InstanceProfileARN string
}{
profileARN,
})
if err != nil {
return err
}
req, err := http.NewRequest(
http.MethodPost,
s.client.url+"2.0/instance-profiles/remove",
bytes.NewBuffer(raw),
)
if err != nil {
return err
}
req = req.WithContext(ctx)
res, err := s.client.client.Do(req)
if err != nil {
return err
}
if res.StatusCode >= 300 || res.StatusCode <= 199 {
return fmt.Errorf(
"Failed to returns 2XX response: %d", res.StatusCode)
}
return nil
}