Skip to content

Commit

Permalink
rebase package
Browse files Browse the repository at this point in the history
  • Loading branch information
5d committed Dec 12, 2024
1 parent 957ccf7 commit ea8b8f0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 36 deletions.
54 changes: 24 additions & 30 deletions packages/@aws-cdk/aws-redshift-alpha/lib/private/privileges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ITable, TableAction } from '../table';
import { IUser } from '../user';
import { DatabaseQuery } from './database-query';
import { HandlerName } from './database-query-provider/handler-name';
import { UserTablePrivilegesHandlerProps } from './handler-props';
import { TablePrivilege as SerializedTablePrivilege, UserTablePrivilegesHandlerProps } from './handler-props';

/**
* The Redshift table and action that make up a privilege that can be granted to a Redshift user.
Expand Down Expand Up @@ -62,25 +62,33 @@ export class UserTablePrivileges extends Construct {
username: props.user.username,
tablePrivileges: cdk.Lazy.any({
produce: () => {
const groupedPrivileges = this.privileges.reduce(
(privileges, { table, actions }) => ({
...privileges,
[table.node.id]: {
actions: [
...(privileges[table.node.id]?.actions ?? []),
...actions,
],
const reducedPrivileges = this.privileges.reduce((privileges, { table, actions }) => {
const tableId = table.node.id;
if (!(tableId in privileges)) {
privileges[tableId] = {
tableName: table.tableName,
},
}),
{} as Record<string, { tableName: string; actions: TableAction[] }>,
);

return Object.entries(groupedPrivileges).map(([tableId, config]) => ({
actions: [],
};
}
actions = actions.concat(privileges[tableId].actions);
if (actions.includes(TableAction.ALL)) {
actions = [TableAction.ALL];
}
if (actions.includes(TableAction.UPDATE) || actions.includes(TableAction.DELETE)) {
actions.push(TableAction.SELECT);
}
privileges[tableId] = {
tableName: table.tableName,
actions: Array.from(new Set(actions)),
};
return privileges;
}, {} as { [key: string]: { tableName: string; actions: TableAction[] } });
const serializedPrivileges: SerializedTablePrivilege[] = Object.entries(reducedPrivileges).map(([tableId, config]) => ({
tableId,
tableName: config.tableName,
actions: unifyTableActions(config.actions).map(action => TableAction[action]),
actions: config.actions.map(action => TableAction[action]),
}));
return serializedPrivileges;
},
}) as any,
},
Expand All @@ -94,17 +102,3 @@ export class UserTablePrivileges extends Construct {
this.privileges.push({ table, actions });
}
}

const unifyTableActions = (tableActions: TableAction[]): TableAction[] => {
const set = new Set<TableAction>(tableActions);

if (set.has(TableAction.ALL)) {
return [TableAction.ALL];
}

if (set.has(TableAction.UPDATE) || set.has(TableAction.DELETE)) {
set.add(TableAction.SELECT);
}

return [...set];
};
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-redshift-alpha/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export class Table extends TableBase {
properties: {
tableName: {
prefix: props.tableName ?? cdk.Names.uniqueId(this),
generateSuffix: (props.tableName == null).toString(),
generateSuffix: !props.tableName ? 'true' : 'false',
},
tableColumns: this.tableColumns,
distStyle: props.distStyle,
Expand All @@ -282,7 +282,7 @@ export class Table extends TableBase {
},
});

this.tableName = props.tableName ?? this.resource.ref;
this.tableName = this.resource.ref;
}

/**
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,9 @@
"tablePrivileges": [
{
"tableId": "Table",
"tableName": "IntegTable",
"tableName": {
"Ref": "Table7ABB320E"
},
"actions": [
"INSERT",
"DELETE",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea8b8f0

Please sign in to comment.