From 9d4b7b79aa976332a8ef80e200356f53b6371781 Mon Sep 17 00:00:00 2001 From: gersbach Date: Mon, 23 Dec 2024 11:55:00 -0800 Subject: [PATCH] EAS-2573 : Add GraphQL support for the permission scanner --- crates/forge_analyzer/src/definitions.rs | 26 +++++++++++++++++++++++- crates/fsrt/src/main.rs | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/forge_analyzer/src/definitions.rs b/crates/forge_analyzer/src/definitions.rs index d8535e0..32a6c5e 100644 --- a/crates/forge_analyzer/src/definitions.rs +++ b/crates/forge_analyzer/src/definitions.rs @@ -1,9 +1,9 @@ #![allow(dead_code, unused)] use std::borrow::BorrowMut; -use std::env; use std::hash::Hash; use std::{borrow::Borrow, fmt, mem}; +use std::{env, string}; use crate::utils::{calls_method, eq_prop_name}; use forge_file_resolver::{FileResolver, ForgeResolver}; @@ -146,6 +146,12 @@ pub fn run_resolver( // This for loop parses each token of each code statement in the file. for (curr_mod, module) in modules.iter_enumerated() { + + let mut string_collector = StringCollector { strings: vec![] }; + + module.visit_children_with(&mut string_collector); + environment.all_strings.extend(string_collector.strings); + let mut export_collector = ExportCollector { res_table: &mut environment.resolver, curr_mod, @@ -583,6 +589,7 @@ pub struct Environment { pub defs: Definitions, default_exports: FxHashMap, pub resolver: ResolverTable, + pub all_strings: Vec, } struct ImportCollector<'cx> { @@ -3298,6 +3305,23 @@ impl Visit for GlobalCollector<'_> { } } +struct StringCollector { + strings: Vec, +} + +impl Visit for StringCollector { + fn visit_str(&mut self, n: &Str) { + self.add_str(n); + } +} + +impl StringCollector { + pub fn add_str(&mut self, n: &Str) { + let a = n.value.clone(); + self.strings.push(a); + } +} + impl Visit for ExportCollector<'_> { noop_visit_type!(); fn visit_export_decl(&mut self, n: &ExportDecl) { diff --git a/crates/fsrt/src/main.rs b/crates/fsrt/src/main.rs index 9968a8c..f141518 100644 --- a/crates/fsrt/src/main.rs +++ b/crates/fsrt/src/main.rs @@ -460,6 +460,8 @@ pub(crate) fn scan_directory<'a>( } } + // TODO: map permissions here for proj.env.all_strings, will implement after new API is merged in + let mut used_graphql_perms: Vec<&str> = definition_analysis_interp .value_manager .varid_to_value_with_proj