Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ jobs:
needs: [changes, lockfile]
if: needs.changes.outputs.performance == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 15
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ fn evaluate_json(py: Python<'_>, request_json: &str) -> PyResult<String> {
.map_err(value_error)
}

#[pyfunction]
fn run_custom_host_json(py: Python<'_>, spec_json: &str) -> PyResult<String> {
py.compiler_detach(|| crate::engine::main::custom_host::run_custom_host_json(spec_json))
.map_err(value_error)
}

#[pyfunction]
fn lint_sql_json(py: Python<'_>, request_json: &str) -> PyResult<String> {
py.compiler_detach(|| crate::sql_lint::main::engine::lint_json(request_json))
Expand Down Expand Up @@ -422,6 +428,7 @@ fn skill_freshness(content: Option<&str>, input_fingerprint: &str) -> String {
pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
module.add_function(wrap_pyfunction!(evaluate_json, module)?)?;
module.add_function(wrap_pyfunction!(finalize_rule_findings_json, module)?)?;
module.add_function(wrap_pyfunction!(run_custom_host_json, module)?)?;
module.add_function(wrap_pyfunction!(lint_sql_json, module)?)?;
module.add_function(wrap_pyfunction!(prepare_lint_sql, module)?)?;
module.add(
Expand Down
6 changes: 0 additions & 6 deletions crates/sqlbuild-rules-native/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub(crate) const GENERIC_BASIC_NAME: &str = "basic";
pub(crate) const GENERIC_SCENARIO_NAME: &str = "scenario";
pub(crate) const GENERIC_CASE_NAME: &str = "case";
pub(crate) const CUSTOM_RULE_NAMESPACE: &str = "XSQBR";
pub(crate) const TARGET_DIRECTORY: &str = "target";
pub(crate) const REFERENCE_KIND: &str = "ref";
pub(crate) const MODEL_SCHEMA_CONFIG_KEY: &str = "schema";
pub(crate) const STAGING_LAYER_DIRECTORY: &str = "staging";
Expand All @@ -33,11 +32,6 @@ pub(crate) const NEGATION_OPERATOR: &str = "-";
pub(crate) const DECLARATION_DOMAIN_COMPONENTS: usize = 3;
pub(crate) const DIRECT_DEPENDENCY_PATH_LENGTH: usize = 2;
pub(crate) const RULE_CODE_NUMBER_LENGTH: usize = 3;
pub(crate) const CUSTOM_HOST_REQUIRED_ERROR: &str = "selected custom rules require a custom host";
pub(crate) const LOGS_DIRECTORY: &str = "logs";
pub(crate) const GIT_DIRECTORY: &str = ".git";
pub(crate) const RULES_DIRECTORY: &str = "rules";
pub(crate) const PYTHON_EXTENSION: &str = "py";
pub(crate) const SQL_WILDCARD: &str = "*";
pub(crate) const UNKNOWN_SQL_TYPE: &str = "UNKNOWN";
pub(crate) const VARCHAR_SQL_TYPE: &str = "VARCHAR";
Expand Down
45 changes: 0 additions & 45 deletions crates/sqlbuild-rules-native/src/engine/_helpers/cache.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::models::Fault;
use fensu_policy::lifecycle::models::CacheRead;
use fensu_policy::{read_cache, write_cache};
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -28,36 +26,6 @@ impl Cache {
})
}

pub(crate) fn get(&self, path: &str, fingerprint: &str) -> Result<Option<Vec<Fault>>, String> {
match read_cache::<Vec<Fault>>(&self.root, path, fingerprint)
.map_err(|error| format!("could not read rules cache: {error}"))?
{
CacheRead::Hit(faults) => Ok(Some(faults)),
CacheRead::Miss | CacheRead::Invalidated => Ok(None),
}
}

pub(crate) fn put(
&self,
path: &str,
fingerprint: &str,
faults: &[Fault],
) -> Result<(), String> {
write_cache(&self.root, path, fingerprint, &faults)
.map_err(|error| format!("could not write rules cache: {error}"))
}

pub(crate) fn custom_rule_bucket(
&self,
code: &str,
rule_identity: &str,
) -> Result<RuleCacheBucket, String> {
read_bucket(
&self.root.join("bulk").join(format!("custom-{code}.json")),
rule_identity,
)
}

pub(crate) fn native_rules_bucket(
&self,
ruleset_identity: &str,
Expand All @@ -76,19 +44,6 @@ impl Cache {
bucket,
)
}

pub(crate) fn put_custom_rule_bucket(
&self,
code: &str,
rule_identity: &str,
bucket: &RuleCacheBucket,
) -> Result<(), String> {
write_bucket(
&self.root.join("bulk").join(format!("custom-{code}.json")),
rule_identity,
bucket,
)
}
}

fn read_bucket(path: &Path, fingerprint: &str) -> Result<RuleCacheBucket, String> {
Expand Down
29 changes: 29 additions & 0 deletions crates/sqlbuild-rules-native/src/engine/_helpers/custom_host.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crate::models::CustomHostSpec;
use fensu_policy::lifecycle::models::{
CustomHostInvocation, CustomHostOutputLimits, CustomHostRequest,
};
use fensu_policy::run_custom_host;
use std::path::Path;
use std::time::Duration;

pub(crate) fn run_custom_host_json(spec_json: &str) -> Result<String, String> {
let spec: CustomHostSpec = serde_json::from_str(spec_json)
.map_err(|error| format!("invalid custom host request: {error}"))?;
let request = CustomHostRequest {
protocol: fensu_policy::lifecycle::constants::CUSTOM_HOST_PROTOCOL_VERSION,
runtime_version: spec.runtime_version.clone(),
payload: spec.payload,
};
let response = run_custom_host::<_, serde_json::Value>(CustomHostInvocation {
program: Path::new(&spec.program),
arguments: &spec.arguments,
timeout: Duration::from_millis(spec.timeout_millis),
output_limits: CustomHostOutputLimits::default(),
request: &request,
})
.map_err(|error| format!("invalid rules lifecycle: {error}"))?;
let payload = response.payload.ok_or_else(|| {
"custom rule host returned no payload after successful validation".to_owned()
})?;
serde_json::to_string(&payload).map_err(|error| error.to_string())
}
Loading
Loading