-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GO-53] Allow to invalidate token metadata via API (#36)
* [GO-53] Allow to invalidate token metadata via API * Lint
- Loading branch information
Showing
7 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"type": "bulk", | ||
"source": "default", | ||
"resource_version": 195, | ||
"args": [ | ||
{ | ||
"type": "pg_add_computed_field", | ||
"args": { | ||
"table": { "schema": "public", "name": "token_metadata" }, | ||
"name": "expired", | ||
"definition": { | ||
"function": { "name": "token_metadata_expired", "schema": "public" }, | ||
"table_argument": null, | ||
"session_argument": null | ||
}, | ||
"comment": null, | ||
"source": "default" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"type": "bulk", | ||
"source": "default", | ||
"resource_version": 195, | ||
"args": [ | ||
{ | ||
"type": "pg_create_select_permission", | ||
"args": { | ||
"table": { "name": "token_metadata", "schema": "public" }, | ||
"role": "partner", | ||
"permission": { | ||
"columns": [ | ||
"id", | ||
"created_at", | ||
"updated_at", | ||
"update_id", | ||
"token_id", | ||
"network", | ||
"contract", | ||
"link", | ||
"metadata", | ||
"retry_count", | ||
"status", | ||
"image_processed", | ||
"error" | ||
], | ||
"computed_fields": ["expired"], | ||
"backend_only": false, | ||
"filter": {}, | ||
"limit": 100, | ||
"allow_aggregations": false | ||
}, | ||
"source": "default" | ||
} | ||
}, | ||
{ | ||
"type": "pg_create_update_permission", | ||
"args": { | ||
"table": { "name": "token_metadata", "schema": "public" }, | ||
"role": "partner", | ||
"permission": { | ||
"columns": ["retry_count", "status"], | ||
"filter": { | ||
"_and": [ | ||
{ "contract": { "_eq": "X-Hasura-User-Id" } }, | ||
{ "status": { "_neq": 1 } }, | ||
{ "expired": { "_eq": "true" } } | ||
] | ||
}, | ||
"backend_only": false, | ||
"set": {} | ||
}, | ||
"source": "default" | ||
} | ||
} | ||
] | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
cmd/metadata/custom_hasura_config/2_invalidate_endpoint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"type": "bulk", | ||
"source": "default", | ||
"resource_version": 195, | ||
"args": [ | ||
{ | ||
"type": "add_query_to_collection", | ||
"args": { | ||
"collection_name": "allowed-queries", | ||
"query_name": "Invalidate token metadata", | ||
"query": "mutation Invalidate($contract: String) {\n update_token_metadata(\n where: {\n contract: {_eq: $contract}, \n status: {_neq: \"1\"}, \n expired: {_eq: true}\n }, \n _set: {\n status: \"1\", \n retry_count: \"0\"\n }) {\n \taffected_rows\n }\n}" | ||
} | ||
}, | ||
{ | ||
"type": "create_rest_endpoint", | ||
"args": { | ||
"name": "Invalidate token metadata", | ||
"url": "invalidate_token_metadata", | ||
"definition": { | ||
"query": { | ||
"query_name": "Invalidate token metadata", | ||
"collection_name": "allowed-queries" | ||
} | ||
}, | ||
"methods": ["PUT", "PATCH"] | ||
} | ||
} | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CREATE OR REPLACE FUNCTION public.token_metadata_expired(IN p_item token_metadata) | ||
RETURNS boolean | ||
LANGUAGE 'plpgsql' STABLE | ||
PARALLEL SAFE | ||
COST 100 | ||
|
||
AS $BODY$ | ||
begin | ||
return to_timestamp(p_item.updated_at + 7200) < now(); | ||
end; | ||
$BODY$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters