{"id":19478060,"url":"https://github.com/snyk/cloud-config-parser","last_synced_at":"2025-07-27T13:09:09.459Z","repository":{"id":40484595,"uuid":"247686346","full_name":"snyk/cloud-config-parser","owner":"snyk","description":"A utility library for finding issues in configuration files","archived":false,"fork":false,"pushed_at":"2025-03-31T16:25:23.000Z","size":199,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":87,"default_branch":"master","last_synced_at":"2025-06-28T19:44:08.560Z","etag":null,"topics":["infrastructure-as-code"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/snyk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-03-16T11:35:46.000Z","updated_at":"2025-04-04T04:39:36.000Z","dependencies_parsed_at":"2025-04-24T01:09:23.871Z","dependency_job_id":"5db92138-cb56-48ec-bf5b-254e20d92bf3","html_url":"https://github.com/snyk/cloud-config-parser","commit_stats":{"total_commits":67,"total_committers":15,"mean_commits":4.466666666666667,"dds":0.7313432835820896,"last_synced_commit":"9fbdca4a285f7a0718836fb3851e61f6d04a5e51"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/snyk/cloud-config-parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snyk%2Fcloud-config-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snyk%2Fcloud-config-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snyk%2Fcloud-config-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snyk%2Fcloud-config-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/snyk","download_url":"https://codeload.github.com/snyk/cloud-config-parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/snyk%2Fcloud-config-parser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267361761,"owners_count":24074983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["infrastructure-as-code"],"created_at":"2024-11-10T19:46:54.671Z","updated_at":"2025-07-27T13:09:09.427Z","avatar_url":"https://github.com/snyk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Snyk logo](https://snyk.io/style/asset/logo/snyk-print.svg)\n\n---\n\n# Snyk cloud-config-parser\n\nA utility library that support Snyk IaC parsing.\nThe two supported types of functionalities are:\n\n1. Identify issue path in a cloud config file.\n2. Parse a serialized string issue path into an array for use with the `getLineNumber()` function.\n\n## Identify issue path in a cloud config file.\n\nIdentifying the issue path in a YAML/JSON/HCL file and returning the relevant line number in order to highlight the relevant line to the users in their files.\n\nIt also exposes a customised YAML parser.\n\nThis library is being used as part of snyk cloud configuration product.\n\n### How it works\n\nThe library has three main methods:\n\n1. `getTrees` - this function receives a fileType and a configuration fileContent and builds the relevant tree (FileStructureTree). An example tree would look like this:\n\n```\n   '0': {\n      nodes: [\n         {\n            key: 'apiVersion',\n            lineLocation: {\n            columnEnd: 14,\n            columnStart: 4,\n            line: 2,\n         },\n         values: [...],\n         {...},\n      ],\n   '1': {...}\n   ...\n   },\n```\n\n2. `getLineNumber`- this function receives a path (array of strings) , a fileType (YAML/JSON/HCL), and a tree and returns the number of the line which is the closest to the path received.\n   In case that the full path does not exist, the returned line number will correspond to the deepest entry in the path array that was found.\n\nThe function `issuesToLineNumbers` invokes both of them: it will build the tree by parsing the fileContent and then return the lineNumber.\n\n3. `parseFileContent`- this function receives the contents of a file and returns the parsed JSON representation of the contents.\n   The file contents can be either YAML or JSON.\n   **Note** This parser uses a different underlying parser to the `getTrees` function - the implementation of `getTrees` will change once we replace the `yaml-js` parser with this one.\n\n### Examples:\n\n---\n\nFor the received path:\n\n- `['spec', 'template', 'spec', 'containers[0]', 'nonExistingResource', 'securityContext', 'capabilities']`\n\nIt will return the line number of the first element in the containers array (because nonExistingResource does not exist).\n\nFor the received path:\n\n- `['spec', 'template', 'spec', 'containers[0]', 'resources', 'securityContext', 'capabilities']`\n\nIt will return the line number of 'capabilities'.\n\n#### Elements with array:\n\n---\n\nUntil now, the paths received in the Cloud Config issues were `containers[snyky1]`, where `snyky1` was the value of the `name` property in one of the objects in `containers`.\n\nWe are supporting both `containers[snyky1]` and `containers[0]`, while the new issues will be in the format of `containers[0]`.\n\nThe piece of code that creates the paths is creating elements like `containers[0]`, but in cases of `containers[snyky1]`, it goes over the elements of the array and looks for a sub-element with key: `name` and value `snyky1`.\n\n#### **Paths starting with 'input'**\n\n---\n\nFor example:\n\n`['input', 'spec', 'template', 'spec', 'containers[0]', 'resources', 'securityContext', 'capabilities']`\n\nThe input value will be removed and the path we are looking for will be like this:\n\n`['spec', 'template', 'spec', 'containers[0]', 'resources', 'securityContext', 'capabilities']`\n\n#### **YAML DocId:**\n\n---\n\n- In the case that the files are JSON or single YAML - the `DocId` will be `0`.\n- In the case of a multi-document file - the `DocId` will be according to the order of the documents.\n\n#### Line numbers\n\n---\n\nAre 1 based!\n\n#### Keys - not value\n\n---\n\nWe are looking for the key in the path and not the value.\n\nFor example , `drop` may have multiple values as an array of strings. We can show `drop[0]` as the first array of values but not `drop['192.168.0.1']`.\n\n## Parse serialized issue path for use in `getLineNumber()`.\n\nThis parser get an issue path and returns array of it's components.\nThe parser split by `.`, unless the object is inside brackets and then it remain it as single object\n\n### Example:\n\n1. **Input:** foo\n   **Output:** ['foo']\n2. **Input:** foo.bar.baz\n   **Output:** ['foo', 'bar', 'baz']\n3. **Input:** foo_1.\\_bar2.baz3\\_\n   **Output:** ['foo\\_1', '\\_bar2', 'baz3\\_']\n4. **Input:** foo.bar[abc].baz\n   **Output:** ['foo', 'bar[abc]', 'baz']\n5. **Input:** foo.bar[abc.def].baz\n   **Output:** ['foo', 'bar[abc.def]', 'baz']\n6. **Input:** foo.bar['abc.def'].baz\n   **Output:** ['foo', \"bar['abc.def']\", 'baz']\n7. **Input:** foo.bar[\"abc.def\"].baz\n   **Output:** ['foo', 'bar[\"abc.def\"]', 'baz']\n8. **Input:** foo.bar['abc/def'].baz\n   **Output:** ['foo', \"bar['abc/def']\", 'baz']\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnyk%2Fcloud-config-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsnyk%2Fcloud-config-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsnyk%2Fcloud-config-parser/lists"}