-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathcredentials.go
More file actions
298 lines (227 loc) · 8.18 KB
/
Copy pathcredentials.go
File metadata and controls
298 lines (227 loc) · 8.18 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package credentials
import (
"fmt"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags"
"github.com/databricks/databricks-sdk-go/service/provisioning"
"github.com/spf13/cobra"
)
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var cmdOverrides []func(*cobra.Command)
func New() *cobra.Command {
cmd := &cobra.Command{
Use: "credentials",
Short: `These APIs manage credential configurations for this workspace.`,
Long: `These APIs manage credential configurations for this workspace. Databricks
needs access to a cross-account service IAM role in your AWS account so that
Databricks can deploy clusters in the appropriate VPC for the new workspace. A
credential configuration encapsulates this role information, and its ID is
used when creating a new workspace.`,
GroupID: "provisioning",
RunE: root.ReportUnknownSubcommand,
}
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
// Add methods
cmd.AddCommand(newCreate())
cmd.AddCommand(newDelete())
cmd.AddCommand(newGet())
cmd.AddCommand(newList())
// Apply optional overrides to this command.
for _, fn := range cmdOverrides {
fn(cmd)
}
return cmd
}
// start create command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var createOverrides []func(
*cobra.Command,
*provisioning.CreateCredentialRequest,
)
func newCreate() *cobra.Command {
cmd := &cobra.Command{}
var createReq provisioning.CreateCredentialRequest
var createJson flags.JsonFlag
cmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Use = "create"
cmd.Short = `Create credential configuration.`
cmd.Long = `Create credential configuration.
Creates a Databricks credential configuration that represents cloud
cross-account credentials for a specified account. Databricks uses this to set
up network infrastructure properly to host Databricks clusters. For your AWS
IAM role, you need to trust the External ID (the Databricks Account API
account ID) in the returned credential object, and configure the required
access policy.
Save the response's credentials_id field, which is the ID for your new
credential configuration object.
For information about how to create a new workspace with this API, see [Create
a new workspace using the Account API]
[Create a new workspace using the Account API]: http://docs.databricks.com/administration-guide/account-api/new-workspace.html`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
cmd.PreRunE = root.MustAccountClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
a := cmdctx.AccountClient(ctx)
if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq)
if diags.HasError() {
return diags.Error()
}
if len(diags) > 0 {
err := cmdio.RenderDiagnostics(ctx, diags)
if err != nil {
return err
}
}
} else {
return fmt.Errorf("please provide command input in JSON format by specifying the --json flag")
}
response, err := a.Credentials.Create(ctx, createReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range createOverrides {
fn(cmd, &createReq)
}
return cmd
}
// start delete command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var deleteOverrides []func(
*cobra.Command,
*provisioning.DeleteCredentialRequest,
)
func newDelete() *cobra.Command {
cmd := &cobra.Command{}
var deleteReq provisioning.DeleteCredentialRequest
cmd.Use = "delete CREDENTIALS_ID"
cmd.Short = `Delete credential configuration.`
cmd.Long = `Delete credential configuration.
Deletes a Databricks credential configuration object for an account, both
specified by ID. You cannot delete a credential that is associated with any
workspace.
Arguments:
CREDENTIALS_ID: Databricks Account API credential configuration ID`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1)
return check(cmd, args)
}
cmd.PreRunE = root.MustAccountClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
a := cmdctx.AccountClient(ctx)
deleteReq.CredentialsId = args[0]
response, err := a.Credentials.Delete(ctx, deleteReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range deleteOverrides {
fn(cmd, &deleteReq)
}
return cmd
}
// start get command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var getOverrides []func(
*cobra.Command,
*provisioning.GetCredentialRequest,
)
func newGet() *cobra.Command {
cmd := &cobra.Command{}
var getReq provisioning.GetCredentialRequest
cmd.Use = "get CREDENTIALS_ID"
cmd.Short = `Get credential configuration.`
cmd.Long = `Get credential configuration.
Gets a Databricks credential configuration object for an account, both
specified by ID.
Arguments:
CREDENTIALS_ID: Credential configuration ID`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1)
return check(cmd, args)
}
cmd.PreRunE = root.MustAccountClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
a := cmdctx.AccountClient(ctx)
getReq.CredentialsId = args[0]
response, err := a.Credentials.Get(ctx, getReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range getOverrides {
fn(cmd, &getReq)
}
return cmd
}
// start list command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var listOverrides []func(
*cobra.Command,
)
func newList() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "list"
cmd.Short = `List credential configuration.`
cmd.Long = `List credential configuration.
List Databricks credential configuration objects for an account, specified by
ID.`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
cmd.PreRunE = root.MustAccountClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
a := cmdctx.AccountClient(ctx)
response, err := a.Credentials.List(ctx)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range listOverrides {
fn(cmd)
}
return cmd
}
// end service Credentials