Skip to content

Commit f06c534

Browse files
authored
Merge pull request #1 from preloopdev/mitm-proxy
Mitm proxy
1 parent c087845 commit f06c534

48 files changed

Lines changed: 3533 additions & 216 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
*.log
66
.DS_Store
77

8+
experiments/mitm/.cache/
9+
experiments/mitm/captures/
10+
experiments/mitm/reports/
11+
__pycache__/

‎crates/aksh-conformance/src/main.rs‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use std::path::PathBuf;
44
use std::process::Stdio;
55

6+
use aksh_gha_parser::{expand_jobs, parse_workflow};
67
use anyhow::{bail, Context};
78
use clap::{Parser, Subcommand};
8-
use aksh_gha_parser::{expand_jobs, parse_workflow};
99
use tokio::process::Command;
1010
use walkdir::WalkDir;
1111

@@ -122,11 +122,7 @@ fn looks_like_workflow(text: &str) -> bool {
122122
})
123123
}
124124

125-
async fn compare_command(
126-
upstream: String,
127-
aksh: String,
128-
args: Vec<String>,
129-
) -> anyhow::Result<()> {
125+
async fn compare_command(upstream: String, aksh: String, args: Vec<String>) -> anyhow::Result<()> {
130126
let upstream_output = Command::new(&upstream)
131127
.args(&args)
132128
.stdout(Stdio::piped())

‎crates/aksh-gha-parser/src/eval.rs‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
1111
use std::collections::BTreeMap;
1212

13-
use indexmap::IndexMap;
1413
use aksh_gha_expressions::{eval_expression, Context};
14+
use indexmap::IndexMap;
1515
use serde_json::{Map, Value};
1616

1717
/// Resolve all `${{ }}` expressions in a string using the given context.
@@ -119,10 +119,8 @@ pub fn build_context(
119119
.collect();
120120
ctx.insert("vars", Value::Object(vars_value));
121121

122-
let matrix_value: Map<String, Value> = matrix
123-
.iter()
124-
.map(|(k, v)| (k.clone(), v.clone()))
125-
.collect();
122+
let matrix_value: Map<String, Value> =
123+
matrix.iter().map(|(k, v)| (k.clone(), v.clone())).collect();
126124
ctx.insert("matrix", Value::Object(matrix_value));
127125

128126
ctx.insert("strategy", strategy.clone());
@@ -155,10 +153,7 @@ mod tests {
155153
let mut env = Map::new();
156154
env.insert("MY_VAR".to_owned(), Value::String("hello".to_owned()));
157155
ctx.insert("env", Value::Object(env));
158-
ctx.insert(
159-
"matrix",
160-
json!({"os": "ubuntu-latest", "node": "18"}),
161-
);
156+
ctx.insert("matrix", json!({"os": "ubuntu-latest", "node": "18"}));
162157
ctx
163158
}
164159

@@ -201,10 +196,7 @@ mod tests {
201196
#[test]
202197
fn resolve_env_value() {
203198
let ctx = make_context();
204-
assert_eq!(
205-
resolve_string("${{ env.MY_VAR }}", &ctx).unwrap(),
206-
"hello"
207-
);
199+
assert_eq!(resolve_string("${{ env.MY_VAR }}", &ctx).unwrap(), "hello");
208200
}
209201

210202
#[test]

‎crates/aksh-gha-parser/src/job_builder.rs‎

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
use std::collections::BTreeMap;
77

88
use aksh_gha_protocol::azdo::{
9-
AgentJobRequestMessage, EndpointAuthorization, MaskHint, MaskType,
10-
PipelineContextData, ServiceEndpoint, TaskResources, TaskStep,
11-
TimelineReference, VariableValue,
9+
AgentJobRequestMessage, EndpointAuthorization, MaskHint, MaskType, PipelineContextData,
10+
ServiceEndpoint, TaskResources, TaskStep, TimelineReference, VariableValue,
1211
};
1312

14-
use crate::JobPlan;
1513
use crate::eval::{build_context, resolve_map, resolve_string};
14+
use crate::JobPlan;
1615
use aksh_gha_expressions::Context;
1716
use serde_json::Value;
1817

@@ -67,7 +66,9 @@ pub fn build_agent_job_message(
6766
variables.insert(k.clone(), VariableValue::new(v));
6867
}
6968
for (k, v) in global_env {
70-
variables.entry(k.clone()).or_insert_with(|| VariableValue::new(v));
69+
variables
70+
.entry(k.clone())
71+
.or_insert_with(|| VariableValue::new(v));
7172
}
7273
for (k, v) in vars {
7374
variables.insert(k.clone(), VariableValue::new(v));
@@ -90,8 +91,7 @@ pub fn build_agent_job_message(
9091
.collect();
9192

9293
// Service endpoints (SystemVssConnection)
93-
let mut endpoints = Vec::new();
94-
endpoints.push(ServiceEndpoint {
94+
let endpoints = vec![ServiceEndpoint {
9595
data: BTreeMap::new(),
9696
name: "SystemVssConnection".to_owned(),
9797
endpoint_type: Some("azdoserver".to_owned()),
@@ -108,7 +108,7 @@ pub fn build_agent_job_message(
108108
)]),
109109
is_shared: Some(false),
110110
service_owner: Some("github".to_owned()),
111-
});
111+
}];
112112

113113
let resources = TaskResources {
114114
endpoints,
@@ -153,10 +153,7 @@ pub fn build_agent_job_message(
153153
"needs".to_owned(),
154154
PipelineContextData::Dict(BTreeMap::new()),
155155
);
156-
context_data.insert(
157-
"strategy".to_owned(),
158-
to_context_data(&strategy_value),
159-
);
156+
context_data.insert("strategy".to_owned(), to_context_data(&strategy_value));
160157

161158
// Actions download info
162159
let actions_download_info = BTreeMap::new();
@@ -180,7 +177,7 @@ pub fn build_agent_job_message(
180177
}
181178

182179
/// Build a `TaskStep` from a `StepPlan`.
183-
fn build_task_step(step: &crate::StepPlan, index: usize, context: &Context) -> TaskStep {
180+
fn build_task_step(step: &crate::StepPlan, _index: usize, context: &Context) -> TaskStep {
184181
let step_id = uuid::Uuid::new_v4();
185182

186183
// Resolve expressions in env and with
@@ -189,7 +186,8 @@ fn build_task_step(step: &crate::StepPlan, index: usize, context: &Context) -> T
189186
.with
190187
.iter()
191188
.map(|(k, v)| {
192-
let resolved = resolve_string(&v.to_string(), context).unwrap_or_else(|_| v.to_string());
189+
let resolved =
190+
resolve_string(&v.to_string(), context).unwrap_or_else(|_| v.to_string());
193191
(k.clone(), resolved)
194192
})
195193
.collect();
@@ -209,14 +207,15 @@ fn build_task_step(step: &crate::StepPlan, index: usize, context: &Context) -> T
209207
display_name: step.name.clone(),
210208
condition,
211209
script: run,
212-
reference: step.uses.as_ref().map(|uses| {
213-
aksh_gha_protocol::azdo::TaskReference {
210+
reference: step
211+
.uses
212+
.as_ref()
213+
.map(|uses| aksh_gha_protocol::azdo::TaskReference {
214214
id: None,
215215
name: Some(uses.clone()),
216216
version: None,
217217
reference_type: None,
218-
}
219-
}),
218+
}),
220219
inputs: with,
221220
env,
222221
continue_on_error: None,
@@ -272,13 +271,23 @@ jobs:
272271
"sha": "abc123"
273272
});
274273

275-
let msg = build_agent_job_message(plan, &github, &BTreeMap::new(), &BTreeMap::new(), &BTreeMap::new())
276-
.unwrap();
274+
let msg = build_agent_job_message(
275+
plan,
276+
&github,
277+
&BTreeMap::new(),
278+
&BTreeMap::new(),
279+
&BTreeMap::new(),
280+
)
281+
.unwrap();
277282

278283
assert!(!msg.steps.is_empty());
279284
assert!(msg.timeline.id != uuid::Uuid::nil());
280285
assert!(msg.job_id != uuid::Uuid::nil());
281-
assert!(msg.resources.endpoints.iter().any(|e| e.name == "SystemVssConnection"));
286+
assert!(msg
287+
.resources
288+
.endpoints
289+
.iter()
290+
.any(|e| e.name == "SystemVssConnection"));
282291
}
283292

284293
#[test]
@@ -299,8 +308,14 @@ jobs:
299308
assert_eq!(plans.len(), 2);
300309

301310
let github = serde_json::json!({"event_name": "push"});
302-
let msg = build_agent_job_message(&plans[0], &github, &BTreeMap::new(), &BTreeMap::new(), &BTreeMap::new())
303-
.unwrap();
311+
let msg = build_agent_job_message(
312+
&plans[0],
313+
&github,
314+
&BTreeMap::new(),
315+
&BTreeMap::new(),
316+
&BTreeMap::new(),
317+
)
318+
.unwrap();
304319

305320
// Matrix should be in context data
306321
assert!(msg.context_data.contains_key("matrix"));
@@ -323,8 +338,14 @@ jobs:
323338
secrets.insert("MY_SECRET".to_owned(), "s3cr3t".to_owned());
324339

325340
let github = serde_json::json!({"event_name": "push"});
326-
let msg = build_agent_job_message(&plans[0], &github, &BTreeMap::new(), &secrets, &BTreeMap::new())
327-
.unwrap();
341+
let msg = build_agent_job_message(
342+
&plans[0],
343+
&github,
344+
&BTreeMap::new(),
345+
&secrets,
346+
&BTreeMap::new(),
347+
)
348+
.unwrap();
328349

329350
assert!(!msg.mask_hints.is_empty());
330351
assert_eq!(msg.mask_hints[0].value, "s3cr3t");

‎crates/aksh-gha-parser/src/lib.rs‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::collections::BTreeMap;
44
use std::path::{Path, PathBuf};
55

6-
use indexmap::IndexMap;
76
use aksh_gha_protocol::{JobId, JobPlan, StepPlan};
7+
use indexmap::IndexMap;
88

99
/// Expression evaluation for workflow fields.
1010
pub mod eval;
@@ -140,7 +140,9 @@ impl Trigger {
140140
}
141141
// paths filter
142142
if let Some(path_filters) = obj.get("paths") {
143-
if !paths.is_empty() && !paths.iter().any(|p| matches_filter(path_filters, p)) {
143+
if !paths.is_empty()
144+
&& !paths.iter().any(|p| matches_filter(path_filters, p))
145+
{
144146
return false;
145147
}
146148
}
@@ -742,10 +744,7 @@ fn object_entry_indexed(
742744
field,
743745
});
744746
};
745-
Ok(map
746-
.iter()
747-
.map(|(k, v)| (k.clone(), v.clone()))
748-
.collect())
747+
Ok(map.iter().map(|(k, v)| (k.clone(), v.clone())).collect())
749748
}
750749

751750
fn can_merge_include_indexed(
@@ -757,7 +756,7 @@ fn can_merge_include_indexed(
757756
.all(|(key, value)| candidate.get(key).is_none_or(|existing| existing == value))
758757
}
759758

760-
fn object_entry(
759+
fn _object_entry(
761760
job_id: &str,
762761
field: &'static str,
763762
value: &Value,
@@ -782,7 +781,7 @@ fn matches_partial(candidate: &IndexMap<String, Value>, partial: &IndexMap<Strin
782781
})
783782
}
784783

785-
fn can_merge_include(
784+
fn _can_merge_include(
786785
candidate: &IndexMap<String, Value>,
787786
include: &IndexMap<String, Value>,
788787
) -> bool {

0 commit comments

Comments
 (0)