pub struct CodeQL { /* private fields */ }
Expand description
CodeQL CLI Wrapper to make it easier to run CodeQL commands
Implementations§
Source§impl CodeQL
impl CodeQL
Sourcepub fn init() -> CodeQLBuilder
pub fn init() -> CodeQLBuilder
Initialize a new CodeQL Builder instance
Sourcepub fn append_search_path(&mut self, path: impl Into<PathBuf>)
pub fn append_search_path(&mut self, path: impl Into<PathBuf>)
Append a search path to the CodeQL CLI
Sourcepub fn default_suite(&self) -> String
pub fn default_suite(&self) -> String
Get the default suite for the CodeQL CLI
Sourcepub fn add_extractor(&mut self, extractor: &CodeQLExtractor)
pub fn add_extractor(&mut self, extractor: &CodeQLExtractor)
Add an external extractor to the CodeQL CLI (search path)
Sourcepub async fn find_codeql() -> Option<PathBuf>
pub async fn find_codeql() -> Option<PathBuf>
Find CodeQL CLI on the system (asynchronous)
Sourcepub async fn load_extractor(
&mut self,
path: impl Into<PathBuf>,
) -> Result<CodeQLExtractor, GHASError>
pub async fn load_extractor( &mut self, path: impl Into<PathBuf>, ) -> Result<CodeQLExtractor, GHASError>
Load a CodeQL extractor from a path
Sourcepub async fn run(&self, args: Vec<impl AsRef<str>>) -> Result<String, GHASError>
pub async fn run(&self, args: Vec<impl AsRef<str>>) -> Result<String, GHASError>
Run a CodeQL command asynchronously
This function will run the CodeQL command with the given arguments and return the output.
It will also set the CODEQL_REGISTRIES_AUTH
environment variable if a token is provided.
Sourcepub fn database<'a>(
&'a self,
db: &'a CodeQLDatabase,
) -> CodeQLDatabaseHandler<'_, '_>
pub fn database<'a>( &'a self, db: &'a CodeQLDatabase, ) -> CodeQLDatabaseHandler<'_, '_>
Pass a CodeQLDatabase to the CodeQL CLI to return a CodeQLDatabaseHandler. This handler can be used to run queries and other operations on the database.
Sourcepub fn pack<'a>(&'a self, pack: &'a CodeQLPack) -> CodeQLPackHandler<'_, '_>
pub fn pack<'a>(&'a self, pack: &'a CodeQLPack) -> CodeQLPackHandler<'_, '_>
Pass a CodeQLPack to the CodeQL CLI to return a CodeQLPackHandler.
This handler can be used to run queries and other operations on the pack.
Sourcepub async fn scan<'a>(
&'a self,
db: &'a mut CodeQLDatabase,
queries: impl Into<String>,
) -> Result<Sarif, GHASError>
pub async fn scan<'a>( &'a self, db: &'a mut CodeQLDatabase, queries: impl Into<String>, ) -> Result<Sarif, GHASError>
An async function to run a CodeQL scan on a database.
This includes the following steps:
- Creating the database
- Running the analysis
§Example
use ghastoolkit::codeql::{CodeQL, CodeQLDatabase};
let codeql = CodeQL::new().await;
let mut db = CodeQLDatabase::init()
.source("./")
.language("python")
.build()
.expect("Failed to create database");
let sarif = codeql.scan(&mut db, "codeql/python-queries").await
.expect("Failed to run scan");
// ... do something with the sarif
Sourcepub fn sarif(&self, path: impl Into<PathBuf>) -> Result<Sarif, GHASError>
pub fn sarif(&self, path: impl Into<PathBuf>) -> Result<Sarif, GHASError>
Get the SARIF file from the CodeQL CLI
Sourcepub async fn is_installed(&self) -> bool
pub async fn is_installed(&self) -> bool
Check to see if the CodeQL CLI is installed
Sourcepub async fn get_version(path: &Path) -> Result<String, GHASError>
pub async fn get_version(path: &Path) -> Result<String, GHASError>
Get the version of the CodeQL CLI
Sourcepub async fn get_languages(&self) -> Result<Vec<CodeQLLanguage>, GHASError>
pub async fn get_languages(&self) -> Result<Vec<CodeQLLanguage>, GHASError>
Get the programming languages supported by the CodeQL CLI.
This function will return the primary languages supported by the CodeQL and exclude
any secondary languages (checkout get_secondary_languages()
).
§Example
use ghastoolkit::CodeQL;
let codeql = CodeQL::default();
let languages = codeql.get_languages()
.await
.expect("Failed to get languages");
for language in languages {
println!("Language: {}", language.pretty());
// Do something with the language
}
Sourcepub async fn get_secondary_languages(
&self,
) -> Result<Vec<CodeQLLanguage>, GHASError>
pub async fn get_secondary_languages( &self, ) -> Result<Vec<CodeQLLanguage>, GHASError>
Get the secondary languages supported by the CodeQL CLI
Sourcepub async fn get_all_languages(&self) -> Result<CodeQLLanguages, GHASError>
pub async fn get_all_languages(&self) -> Result<CodeQLLanguages, GHASError>
Get all languages supported by the CodeQL CLI
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CodeQL
impl RefUnwindSafe for CodeQL
impl Send for CodeQL
impl Sync for CodeQL
impl Unpin for CodeQL
impl UnwindSafe for CodeQL
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.