Skip to content

Commit 4d79829

Browse files
committed
2.0.4 wip
1 parent 8824d59 commit 4d79829

10 files changed

Lines changed: 89 additions & 28 deletions

File tree

examples/databricks/serverless/resources/OLD/databricks_account/update_group_membership.iql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ update databricks_account.iam.groups
33
set schemas = '["urn:ietf:params:scim:api:messages:2.0:PatchOp"]',
44
Operations = '[{"op": "replace", "path": "members", "value": {{ databricks_workspace_group_members }} }]'
55
WHERE account_id = '{{ databricks_account_id }}'
6-
AND id = '{{ databricks_group_id }}';
6+
AND id = '{{ databricks_group_id }}';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*+ exports, retries=3, retry_delay=5 */
2+
SELECT
3+
JSON_GROUP_ARRAY(JSON_OBJECT('value', id)) as databricks_workspace_group_members
4+
FROM databricks_account.iam.account_users
5+
WHERE account_id = '{{ databricks_account_id }}'
6+
AND userName in {{ users | sql_list }};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*+ command */
2+
update databricks_account.iam.account_groups
3+
set schemas = '["urn:ietf:params:scim:api:messages:2.0:PatchOp"]',
4+
Operations = '[{"op": "replace", "path": "members", "value": {{ databricks_workspace_group_members }} }]'
5+
WHERE account_id = '{{ databricks_account_id }}'
6+
AND id = '{{ databricks_group_id }}';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*+ createorupdate */
2+
REPLACE databricks_account.iam.workspace_assignment
3+
SET
4+
permissions = '["ADMIN"]'
5+
WHERE
6+
account_id = '{{ databricks_account_id }}'
7+
AND workspace_id = '{{ workspace_id }}'
8+
AND principal_id = '{{ databricks_group_id }}'
9+
RETURNING
10+
error,
11+
permissions,
12+
principal;
13+
14+
15+
/*+ statecheck, retries=5, retry_delay=10 */
16+
SELECT COUNT(*) as count
17+
FROM databricks_account.iam.workspace_assignment
18+
WHERE
19+
account_id = '{{ databricks_account_id }}'
20+
AND workspace_id = '{{ workspace_id }}'
21+
AND JSON_EXTRACT(principal, '$.principal_id') = {{ databricks_group_id }}
22+
AND permissions LIKE '%ADMIN%';
23+
24+
25+
/*+ delete */
26+
DELETE FROM databricks_account.iam.workspace_assignment
27+
WHERE account_id = '{{ databricks_account_id }}'
28+
AND workspace_id = '{{ workspace_id }}'
29+
AND principal_id = '{{ databricks_group_id }}'
30+
;

examples/databricks/serverless/stackql_manifest.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,22 +288,23 @@ resources:
288288
- databricks_group_id
289289
- display_name
290290

291-
# - name: databricks_account/get_users
292-
# type: query
293-
# props:
294-
# - name: users
295-
# value:
296-
# - "javen@stackql.io"
297-
# - "krimmer@stackql.io"
298-
# exports:
299-
# - databricks_workspace_group_members
291+
- name: get_databricks_users
292+
file: databricks_account/get_users.iql
293+
type: query
294+
props:
295+
- name: users
296+
value:
297+
- "javen@stackql.io"
298+
- "krimmer@stackql.io"
299+
exports:
300+
- databricks_workspace_group_members
300301

301-
# - name: databricks_account/update_group_membership
302-
# type: command
303-
# props: []
302+
- name: databricks_account/update_group_membership
303+
type: command
304+
props: []
304305

305-
# - name: databricks_account/workspace_permission_assignments
306-
# props: []
306+
- name: databricks_account/workspace_assignment
307+
props: []
307308

308309
# - name: databricks_workspace/storage_credential
309310
# props:

src/commands/build.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ pub fn execute(matches: &ArgMatches) {
9090
);
9191

9292
if is_dry_run {
93-
println!("dry-run build complete");
93+
print_unicode_box("dry-run build complete", BorderColor::Green);
9494
} else {
95-
println!("build complete");
95+
print_unicode_box("build complete", BorderColor::Green);
9696
}
9797

9898
stop_local_server();
@@ -239,14 +239,19 @@ fn run_build(
239239
// this.* fields into full_context.
240240
let mut exports_query_str: Option<String> = None;
241241

242-
// Handle query type with no exports
243-
if res_type == "query" && exports_query_str.is_none() {
242+
// Handle query type: render exports eagerly (query types don't
243+
// have exists/statecheck so there's no this.* deferral needed).
244+
if res_type == "query" {
244245
if let Some(ref iq) = inline_query {
245246
exports_query_str = Some(iq.clone());
246247
} else {
247-
catch_error_and_exit(
248-
"Inline sql must be supplied or an iql file must be present with an 'exports' anchor for query type resources.",
249-
);
248+
exports_query_str =
249+
render_exports!(runner, resource_queries, resource, &full_context);
250+
if exports_query_str.is_none() {
251+
catch_error_and_exit(
252+
"Inline sql must be supplied or an iql file must be present with an 'exports' anchor for query type resources.",
253+
);
254+
}
250255
}
251256
}
252257

src/commands/teardown.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ pub fn execute(matches: &ArgMatches) {
7878
&format!("{:?}", on_failure_val),
7979
);
8080

81-
println!("teardown complete (dry run: {})", is_dry_run);
81+
if is_dry_run {
82+
print_unicode_box("dry-run teardown complete", BorderColor::Green);
83+
} else {
84+
print_unicode_box("teardown complete", BorderColor::Green);
85+
}
8286

8387
stop_local_server();
8488
}

src/commands/test.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ pub fn execute(matches: &ArgMatches) {
8989
output_file.map(|s| s.as_str()),
9090
);
9191

92-
println!("tests complete (dry run: {})", is_dry_run);
92+
if is_dry_run {
93+
print_unicode_box("dry-run tests complete", BorderColor::Green);
94+
} else {
95+
print_unicode_box("tests complete", BorderColor::Green);
96+
}
9397

9498
stop_local_server();
9599
}

src/core/templating.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ pub fn render_query(
294294
let expanded = match preprocess_this_prefix(template, res_name) {
295295
Ok(t) => t,
296296
Err(e) => {
297-
error!("[{}] [{}] {}", res_name, anchor, e);
298-
process::exit(1);
297+
crate::core::utils::catch_error_and_exit(&format!("[{}] [{}] {}", res_name, anchor, e));
299298
}
300299
};
301300

@@ -348,7 +347,10 @@ pub fn render_query(
348347
ctx.keys().collect::<Vec<_>>()
349348
);
350349

351-
process::exit(1);
350+
crate::core::utils::catch_error_and_exit(&format!(
351+
"Failed to render query for [{}] [{}]",
352+
res_name, anchor
353+
));
352354
}
353355
}
354356
}

src/core/utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pub fn catch_error_and_exit(msg: &str) -> ! {
2121
error!("{}", msg);
2222
// Stop the local server before exiting to avoid stale sessions
2323
crate::utils::server::stop_local_server();
24-
eprintln!("stackql-deploy operation failed");
24+
crate::utils::display::print_unicode_box(
25+
"stackql-deploy operation failed",
26+
crate::utils::display::BorderColor::Red,
27+
);
2528
process::exit(1);
2629
}
2730

0 commit comments

Comments
 (0)