-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
122 additions
and
135 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn run lint-staged |
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 |
---|---|---|
@@ -1,32 +1,68 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`json path filter returns only selected fields 1`] = ` | ||
exports[`json path filter returns complete data on error 1`] = ` | ||
{ | ||
"data": { | ||
"apiVersion": "rbac.authorization.k8s.io/v1", | ||
"items": [ | ||
{ | ||
"metadata": { | ||
"managedFields": [ | ||
{ | ||
"manager": "clusterrole-aggregation-controller", | ||
"operation": "Apply", | ||
}, | ||
{ | ||
"manager": "kube-apiserver", | ||
"operation": "Update", | ||
}, | ||
], | ||
"name": "admin", | ||
"resourceVersion": "345", | ||
"uid": "4251609f-b3ca-4875-8ec6-76b40ab62748", | ||
}, | ||
}, | ||
{ | ||
"metadata": { | ||
"managedFields": [ | ||
{ | ||
"manager": "kubectl-client-side-apply", | ||
"operation": "Update", | ||
}, | ||
], | ||
"name": "aws-node", | ||
"resourceVersion": "273", | ||
"uid": "63a3bed8-a750-440d-bca9-b5f41c8786c2", | ||
}, | ||
}, | ||
], | ||
"kind": "ClusterRoleList", | ||
}, | ||
"headers": { | ||
"audit-id": "6a816d03-d29f-4657-b624-35766c8a5572", | ||
"cache-control": "no-cache, private", | ||
"content-type": "application/json", | ||
"date": "Wed, 25 Oct 2023 06:08:30 GMT", | ||
"transfer-encoding": "chunked", | ||
"x-kubernetes-pf-flowschema-uid": "ef7c3d21-4649-422d-a4fa-e5b85d52f141", | ||
"x-kubernetes-pf-prioritylevel-uid": "a6704cd4-c4fb-48bb-982e-a1ed79bfb12d", | ||
"metadata": { | ||
"resourceVersion": "4423772", | ||
}, | ||
}, | ||
"status": 200, | ||
"statusText": "OK", | ||
} | ||
`; | ||
|
||
exports[`json path filter returns only selected fields 1`] = ` | ||
{ | ||
"data": { | ||
"items": [ | ||
{ | ||
"metadata": { | ||
"name": "admin", | ||
}, | ||
}, | ||
{ | ||
"metadata": { | ||
"name": "aws-node", | ||
}, | ||
}, | ||
], | ||
"kind": "ClusterRoleList", | ||
}, | ||
"status": 200, | ||
} | ||
`; |
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 |
---|---|---|
@@ -1,20 +1,27 @@ | ||
import { createLogger } from "../log"; | ||
import { isArray } from "lodash"; | ||
|
||
const logger = createLogger({ name: "filter" }); | ||
|
||
// jq-node doesn't support `import` syntax | ||
const jq = require("node-jq"); | ||
|
||
export const jpFilter = async ( | ||
data: any, | ||
jqHeader: string | string[] | undefined | ||
): Promise<any> => { | ||
const jpSelectQuery = isArray(jqHeader) ? jqHeader[0] : jqHeader; | ||
if (!jpSelectQuery) { | ||
const query = isArray(jqHeader) ? jqHeader[0] : jqHeader; | ||
if (!query) { | ||
return data; | ||
} | ||
try { | ||
return await jq.run(jpSelectQuery, data, { input: "json", output: "json" }); | ||
} catch (e: any) { | ||
console.log(e); | ||
// jq.run() returns a Promise | ||
return await jq.run(query, data, { input: "json", output: "json" }); | ||
} catch (error: any) { | ||
logger.error( | ||
{ error, jpSelectQuery: query }, | ||
"Error running jq query, ignoring filters" | ||
); | ||
return data; | ||
} | ||
}; |
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
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
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
Oops, something went wrong.