Skip to content

Stored Procedure support for new Execute operation - REST and GraphQL #1107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 84 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
bc8e86c
prelim changes.
seantleonard Jan 19, 2023
79ab48c
Updating operation/action handling in validation and ensuring SP's ar…
seantleonard Jan 20, 2023
27fd899
Proper operation resolution and execute field naming for SP's
seantleonard Jan 20, 2023
e022fed
Updates for adding Operation configuraiton for StoredProcedure GraphQ…
seantleonard Jan 23, 2023
309d0de
updated processing.
seantleonard Jan 23, 2023
8a92973
Updated Authorization and REST processing of EXECUTE for SPs.
seantleonard Jan 24, 2023
c3ff6ea
Revisions and helper methods, and method comments added.
seantleonard Jan 24, 2023
fae92a5
Add tests.
seantleonard Jan 24, 2023
855cfd5
Added more comments.
seantleonard Jan 24, 2023
7b29920
Added more GraphQL tests and added more comments referencing GraphQL …
seantleonard Jan 24, 2023
746ca9d
Fixed spacing and usings.
seantleonard Jan 24, 2023
0ee6ecb
update reference configuration for stored procedures.
seantleonard Jan 24, 2023
832eb22
Merge branch 'main' into dev/seleonar/operationSpExecute
seantleonard Jan 24, 2023
9b2fd3e
remove whitespace. and fix broken query generation logic.
seantleonard Jan 25, 2023
c87cc72
Merge branch 'dev/seleonar/operationSpExecute' of https://github.com/…
seantleonard Jan 25, 2023
2e2a7f2
Merge branch 'main' into dev/seleonar/operationSpExecute
seantleonard Jan 26, 2023
adfa158
updated tests.
seantleonard Jan 26, 2023
fd4ec5a
Merge branch 'dev/seleonar/operationSpExecute' of https://github.com/…
seantleonard Jan 26, 2023
5848c75
Merge branch 'main' into dev/seleonar/operationSpExecute
seantleonard Jan 26, 2023
83b497e
Fix permissions operations to be execute for stored procedure entitie…
seantleonard Jan 26, 2023
38350f3
Updated CLI handling of execute operation.
seantleonard Jan 26, 2023
6df9443
Fix CLI tests to be compatible with Execute operation for stored proc…
seantleonard Jan 27, 2023
ae4f486
fix permissions on mssqlcommands script.
seantleonard Jan 27, 2023
7dfc6d6
Updated tests and Configuration handling.
seantleonard Jan 27, 2023
b28d631
Addressing PR feedback.
seantleonard Jan 27, 2023
aedfa97
fix formatting
seantleonard Jan 27, 2023
3f84ad9
fixed test.
seantleonard Jan 27, 2023
a3e3a00
CLI - Execute action for stored procedures (#1129)
severussundar Jan 28, 2023
bf2dd7d
updates for compatibility
seantleonard Jan 28, 2023
6f07e07
Addressing PR feedback.
seantleonard Jan 30, 2023
28c5a44
refining logic.
seantleonard Jan 30, 2023
cbc5a84
added code comments.
seantleonard Jan 30, 2023
8aa7e2c
Merge branch 'main' into dev/seleonar/operationSpExecute
seantleonard Jan 30, 2023
cfb144f
Updated spacing.
seantleonard Jan 30, 2023
5b08044
Merge branch 'main' into dev/seleonar/operationSpExecute
seantleonard Jan 31, 2023
6459f79
Execute Action - Update Command (#1139)
severussundar Jan 31, 2023
7b9acf3
updated from Feedback
seantleonard Jan 31, 2023
79e5f9a
Remove stored procedure entities from sql reference json schema since…
seantleonard Jan 31, 2023
f7d8595
REST json key `method` to `methods`
seantleonard Jan 31, 2023
ba1a05c
Clean up nits and add comments to methods without descriptions.
seantleonard Jan 31, 2023
d9d929c
added comments
seantleonard Jan 31, 2023
f351525
Merge branch 'main' into dev/seleonar/operationSpExecute
Aniruddh25 Jan 31, 2023
f727551
added Sales table back to reference.
seantleonard Jan 31, 2023
6b0d9e3
Merge branch 'dev/seleonar/operationSpExecute' of https://github.com/…
seantleonard Jan 31, 2023
4aaf27d
remove changed file.
seantleonard Jan 31, 2023
0df031f
more concise switch + code comments.
seantleonard Jan 31, 2023
79bd673
more code comments, renames for clarification and removal of empty li…
seantleonard Jan 31, 2023
8c3da8a
remove using.
seantleonard Feb 1, 2023
7704c00
merge conflict resolve
seantleonard Feb 1, 2023
ad6dcbb
Merge branch 'main' into dev/seleonar/operationSpExecute
seantleonard Feb 1, 2023
07b291a
Merge branch 'main' into dev/seleonar/operationSpExecute
severussundar Feb 1, 2023
7cf3cad
Merge branch 'dev/seleonar/operationSpExecute' of https://github.com/…
severussundar Feb 1, 2023
a001740
addressing nits
severussundar Feb 1, 2023
7ce7c36
Merge branch 'main' into dev/seleonar/operationSpExecute
severussundar Feb 1, 2023
08bcdb5
fixing deserialization of graphql operation, removing ignore in query…
severussundar Feb 1, 2023
5cbe288
fixing deserialization test
severussundar Feb 1, 2023
7d104ec
fix formatting
severussundar Feb 1, 2023
3baea85
updating rest methods for GetBook, GetBooks
severussundar Feb 1, 2023
916a56d
Including REST find tests for SPs
severussundar Feb 1, 2023
78a05b5
adding rest methods to find api tests
severussundar Feb 1, 2023
0d2f964
enabling source type conversion
severussundar Feb 1, 2023
d7da119
fixing formatting
severussundar Feb 1, 2023
a25f767
updating logic for update rest,grapql options
severussundar Feb 1, 2023
5060872
remove rest command from cosmos db commands
severussundar Feb 1, 2023
befcf24
fix return type from 403 to 405 to match HTTP spec and fix type casting.
seantleonard Feb 1, 2023
f8cf3a2
resolve nits in PR feedback.
seantleonard Feb 1, 2023
490cc77
Address feedback from PR
seantleonard Feb 2, 2023
b568a99
address feedback for renaming GetGraphQLType() to GetGraphQLEnabledOr…
seantleonard Feb 2, 2023
ecae95c
CLI resolve operations for permission based on SourceType, special ha…
seantleonard Feb 2, 2023
c5f1a84
fix empty code
seantleonard Feb 2, 2023
3cf33c7
additional check for stored proc
seantleonard Feb 2, 2023
c435fba
Fix flip flopped valid ops
seantleonard Feb 2, 2023
b88905a
Update return types and remove unnecessary method.
seantleonard Feb 2, 2023
9f2b277
update valid RestMethod calculation.
seantleonard Feb 2, 2023
22d77d2
Additional Stored Procedure Check.
seantleonard Feb 2, 2023
224624b
Remove dupe code and address feedback. removed unneeded logging.
seantleonard Feb 2, 2023
6dd1ebd
Merge branch 'main' into dev/seleonar/operationSpExecute
seantleonard Feb 2, 2023
c09237b
nit: remove ending tabs from line 243:249
seantleonard Feb 2, 2023
d01d685
Extra line
seantleonard Feb 2, 2023
b625204
update check.
seantleonard Feb 2, 2023
00e1d81
address comment.
seantleonard Feb 2, 2023
63dfc16
adding method summary, modifying a check
severussundar Feb 2, 2023
790b280
Merge branch 'dev/seleonar/operationSpExecute' of https://github.com/…
severussundar Feb 2, 2023
d5375f7
Merge branch 'main' into dev/seleonar/operationSpExecute
severussundar Feb 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions ConfigGenerators/MsSqlCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ add Journal --config "dab-config.MsSql.json" --source "journals" --rest true --g
add ArtOfWar --config "dab-config.MsSql.json" --source "aow" --rest true --permissions "anonymous:*"
add series --config "dab-config.MsSql.json" --source "series" --permissions "anonymous:*"
add Sales --config "dab-config.MsSql.json" --source "sales" --permissions "anonymous:*" --rest true --graphql true
add GetBooks --config "dab-config.MsSql.json" --source "get_books" --source.type "stored-procedure" --permissions "anonymous:read" --rest true --graphql true
add GetBook --config "dab-config.MsSql.json" --source "get_book_by_id" --source.type "stored-procedure" --permissions "anonymous:read" --rest true --graphql false
add GetPublisher --config "dab-config.MsSql.json" --source "get_publisher_by_id" --source.type "stored-procedure" --source.params "id:1" --permissions "anonymous:read" --rest true --graphql true
add InsertBook --config "dab-config.MsSql.json" --source "insert_book" --source.type "stored-procedure" --source.params "title:randomX,publisher_id:1234" --permissions "anonymous:create" --rest true --graphql true
add CountBooks --config "dab-config.MsSql.json" --source "count_books" --source.type "stored-procedure" --permissions "anonymous:read" --rest true --graphql true
add DeleteLastInsertedBook --config "dab-config.MsSql.json" --source "delete_last_inserted_book" --source.type "stored-procedure" --permissions "anonymous:delete" --rest true --graphql true
add GetBooks --config "dab-config.MsSql.json" --source "get_books" --source.type "stored-procedure" --permissions "anonymous:execute" --rest true --graphql true
add GetBook --config "dab-config.MsSql.json" --source "get_book_by_id" --source.type "stored-procedure" --permissions "anonymous:execute" --rest true --graphql false
add GetPublisher --config "dab-config.MsSql.json" --source "get_publisher_by_id" --source.type "stored-procedure" --source.params "id:1" --permissions "anonymous:execute" --rest true --graphql true
add InsertBook --config "dab-config.MsSql.json" --source "insert_book" --source.type "stored-procedure" --source.params "title:randomX,publisher_id:1234" --permissions "anonymous:execute" --rest true --graphql true
add CountBooks --config "dab-config.MsSql.json" --source "count_books" --source.type "stored-procedure" --permissions "anonymous:execute" --rest true --graphql true
add DeleteLastInsertedBook --config "dab-config.MsSql.json" --source "delete_last_inserted_book" --source.type "stored-procedure" --permissions "anonymous:execute" --rest true --graphql true
add UpdateBookTitle --config "dab-config.MsSql.json" --source "update_book_title" --source.type "stored-procedure" --source.params "id:1,title:Testing Tonight" --permissions "anonymous:update" --rest true --graphql true
add GetAuthorsHistoryByFirstName --config "dab-config.MsSql.json" --source "get_authors_history_by_first_name" --source.type "stored-procedure" --source.params "firstName:Aaron" --permissions "anonymous:read" --rest true --graphql SearchAuthorByFirstName
add InsertAndDisplayAllBooksUnderGivenPublisher --config "dab-config.MsSql.json" --source "insert_and_display_all_books_for_given_publisher" --source.type "stored-procedure" --source.params "title:MyTitle,publisher_name:MyPublisher" --permissions "anonymous:create" --rest true --graphql true
add GetAuthorsHistoryByFirstName --config "dab-config.MsSql.json" --source "get_authors_history_by_first_name" --source.type "stored-procedure" --source.params "firstName:Aaron" --permissions "anonymous:execute" --rest true --graphql SearchAuthorByFirstName
add InsertAndDisplayAllBooksUnderGivenPublisher --config "dab-config.MsSql.json" --source "insert_and_display_all_books_for_given_publisher" --source.type "stored-procedure" --source.params "title:MyTitle,publisher_name:MyPublisher" --permissions "anonymous:execute" --rest true --graphql true
update Publisher --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many
update Publisher --config "dab-config.MsSql.json" --permissions "policy_tester_01:create,delete"
update Publisher --config "dab-config.MsSql.json" --permissions "policy_tester_01:update" --fields.include "*"
Expand Down
80 changes: 58 additions & 22 deletions ConfigGenerators/dab-config.sql.reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -915,15 +915,18 @@
"object": "get_books"
},
"rest": true,
"graphql": true,
"graphql": {
"type": "GetBooks",
"operation": "query"
},
"permissions": [
{
"role": "anonymous",
"actions": [ "read" ]
"actions": [ "execute" ]
},
{
"role": "authenticated",
"actions": [ "read" ]
"actions": [ "execute" ]
}
]
},
Expand All @@ -932,16 +935,19 @@
"type": "stored-procedure",
"object": "get_book_by_id"
},
"rest": true,
"rest": {
"path": "GetBook",
"method": [ "GET" ]
},
"graphql": false,
"permissions": [
{
"role": "anonymous",
"actions": [ "read" ]
"actions": [ "execute" ]
},
{
"role": "authenticated",
"actions": [ "read" ]
"actions": [ "execute" ]
}
]
},
Expand Down Expand Up @@ -978,53 +984,68 @@
},
"key-fields": []
},
"rest": true,
"rest": {
"path": "InsertBook",
"method": [ "POST" ]
},
"permissions": [
{
"role": "anonymous",
"actions": [
"create"
"execute"
]
},
{
"role": "authenticated",
"actions": [
"create"
"execute"
]
}
],
"graphql": true
"graphql": {
"type": "InsertBook",
"operation": "mutation"
}
},
"CountBooks": {
"source": {
"type": "stored-procedure",
"object": "count_books",
"key-fields": []
},
"rest": true,
"rest": {
"path": "CountBooks",
"method": [ "GET" ]
},
"permissions": [
{
"role": "anonymous",
"actions": [
"read"
"execute"
]
},
{
"role": "authenticated",
"actions": [
"read"
"execute"
]
}
],
"graphql": true
"graphql": {
"type": "CountBooks",
"operation": "query"
}
},
"DeleteLastInsertedBook": {
"source": {
"type": "stored-procedure",
"object": "delete_last_inserted_book",
"key-fields": []
},
"rest": true,
"rest": {
"path": "DeleteLastInsertedBook",
"method": [ "DELETE" ]
},
"permissions": [
{
"role": "anonymous",
Expand All @@ -1039,7 +1060,10 @@
]
}
],
"graphql": true
"graphql": {
"type": "DeleteLastInsertedBook",
"operation": "mutation"
}
},
"UpdateBookTitle": {
"source": {
Expand All @@ -1051,22 +1075,28 @@
},
"key-fields": []
},
"rest": true,
"rest": {
"path": "UpdateBookTitle",
"method": [ "PUT", "PATCH" ]
},
"permissions": [
{
"role": "anonymous",
"actions": [
"update"
"execute"
]
},
{
"role": "authenticated",
"actions": [
"update"
"execute"
]
}
],
"graphql": true
"graphql": {
"type": "UpdateBookTitle",
"operation": "mutation"
}
},
"GetPublisher": {
"source": {
Expand All @@ -1076,7 +1106,10 @@
"id": 1
}
},
"rest": true,
"rest": {
"path": "GetPublisher",
"method": [ "GET" ]
},
"permissions": [
{
"role": "anonymous",
Expand All @@ -1091,7 +1124,10 @@
]
}
],
"graphql": true
"graphql": {
"type": "GetPublisher",
"operation": "query"
}
}
}
}
11 changes: 11 additions & 0 deletions src/Auth/AuthorizationMetadataHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public class EntityMetadata
/// i.e. Read operation is permitted in {Role1, Role2, ..., RoleN}
/// </summary>
public Dictionary<Operation, List<string>> OperationToRolesMap { get; set; } = new();

/// <summary>
/// List of Http verbs enabled for Stored Procedure entities that have their REST endpoint enabled.
/// </summary>
public HashSet<string> StoredProcedureHttpVerbs { get; set; } = new();

/// <summary>
/// Defines the type of database object the entity represents.
/// Examples include Table, View, StoredProcedure
/// </summary>
public SourceType ObjectType { get; set; } = SourceType.Table;
}

/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Auth/IAuthorizationResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public interface IAuthorizationResolver
/// <returns>Collection of role names allowed to perform operation on Entity's field.</returns>
public IEnumerable<string> GetRolesForField(string entityName, string field, Operation operation);

/// <summary>
///
/// </summary>
/// <param name="entityName"></param>
/// <param name="roleName"></param>
/// <param name="httpVerb"></param>
/// <returns>True if the execution of the stored procedure is permitted.</returns>
public bool IsStoredProcedureExecutionPermitted(string entityName, string roleName, string httpVerb);

/// <summary>
/// Returns a list of roles which define permissions for the provided operation.
/// i.e. list of roles which allow the operation 'Read' on entityName.
Expand Down
9 changes: 7 additions & 2 deletions src/Config/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public record PermissionOperation(
Field? Fields)
{
// Set of allowed operations for a request.
public static readonly HashSet<Operation> ValidPermissionOperations = new() { Operation.Create, Operation.Read, Operation.Update, Operation.Delete };
public static readonly HashSet<Operation> ValidPermissionOperations = new() { Operation.Create, Operation.Read, Operation.Update, Operation.Delete, Operation.Execute };
}

/// <summary>
Expand Down Expand Up @@ -59,8 +59,10 @@ public override void Write(Utf8JsonWriter writer, Operation value, JsonSerialize
public enum Operation
{
None,

// *
All,

// Common Operations
Delete, Read,

Expand All @@ -71,7 +73,10 @@ public enum Operation
Insert, Update, UpdateGraphQL,

// Additional
UpsertIncremental, UpdateIncremental
UpsertIncremental, UpdateIncremental,

// Stored Procedures / Functions
Execute
}

/// <summary>
Expand Down
Loading