Skip to content

Commit 0bfa46b

Browse files
committed
update sshdconfig manifest
1 parent bf615e1 commit 0bfa46b

File tree

5 files changed

+103
-17
lines changed

5 files changed

+103
-17
lines changed

sshdconfig/Cargo.lock

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sshdconfig/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ lto = true
1616
[dependencies]
1717
atty = { version = "0.2" }
1818
chrono = { version = "0.4" }
19+
schemars = "0.9"
1920
serde = { version = "1.0", features = ["derive"] }
2021
serde_json = { version = "1.0", features = ["preserve_order"] }
2122
thiserror = { version = "2.0" }

sshdconfig/src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
use schemars::schema_for;
5+
use serde_json::to_string_pretty;
6+
use std::{env::args, process::exit};
7+
48
use crate::export::invoke_export;
9+
use crate::parser::SshdConfigParser;
510

611
mod error;
712
mod export;
@@ -10,6 +15,22 @@ mod parser;
1015
mod util;
1116

1217
fn main() {
18+
19+
// TODO: add support for other commands and use clap for argument parsing
20+
let args: Vec<String> = args().collect();
21+
22+
if args.len() != 2 || (args[1] != "export" && args[1] != "schema") {
23+
eprintln!("Usage: {} <export|schema>", args[0]);
24+
exit(1);
25+
}
26+
27+
if args[1] == "schema" {
28+
// for dsc tests on linux/mac
29+
let schema = schema_for!(SshdConfigParser);
30+
println!("{}", to_string_pretty(&schema).unwrap());
31+
return;
32+
}
33+
1334
// only supports export for sshdconfig for now
1435
match invoke_export() {
1536
Ok(result) => {

sshdconfig/src/parser.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
use schemars::JsonSchema;
45
use serde_json::{Map, Value};
56
use tree_sitter::Parser;
67

78
use crate::error::SshdConfigError;
89
use crate::metadata::{MULTI_ARG_KEYWORDS, REPEATABLE_KEYWORDS};
910

11+
#[derive(Debug, JsonSchema)]
1012
pub struct SshdConfigParser {
1113
map: Map<String, Value>
1214
}
@@ -236,11 +238,10 @@ mod tests {
236238
}
237239

238240
#[test]
239-
fn err() {
241+
fn empty_string_is_ok() {
240242
let code = r#"
241243
"#;
242244
let result = parse_text_to_map(code);
243-
println!("{result:?}");
244245
assert!(result.is_ok());
245246
}
246247
}
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"manifestVersion": "1.0",
3-
"configuration": {
4-
"get": {
2+
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
3+
"type": "Microsoft.Windows.OpenSSH.SSHD/sshd_config",
4+
"description": "Manage SSH Server Configuration",
5+
"version": "0.1.0",
6+
"export": {
7+
"executable": "sshdconfig",
8+
"args": [
9+
"export"
10+
]
11+
},
12+
"schema": {
13+
"command": {
514
"executable": "sshdconfig",
6-
"args": [ "get" ],
7-
"acceptStdin": true
8-
},
9-
"set": {
10-
"executable": "sshdconfig",
11-
"args": [ "set" ],
12-
"acceptStdin": true
13-
},
14-
"test": {
15-
"executable": "sshdconfig",
16-
"args": [ "test" ],
17-
"acceptStdin": true
15+
"args": [
16+
"schema"
17+
]
1818
}
1919
}
2020
}

0 commit comments

Comments
 (0)